Commit fbd91084d487aad00ac6c9a04863404e9a1edb1f
1 parent
f8c76568
Exists in
master
and in
2 other branches
Adding non-student view for subject goals
Showing
3 changed files
with
70 additions
and
13 deletions
Show diff stats
amadeus/templates/base.html
goals/templates/goals/view.html
... | ... | @@ -33,6 +33,7 @@ |
33 | 33 | {% endif %} |
34 | 34 | |
35 | 35 | {% resource_permissions request.user goal as has_resource_permissions %} |
36 | + {% subject_permissions request.user goal as has_subject_permissions %} | |
36 | 37 | |
37 | 38 | {% if goal.visible %} |
38 | 39 | <div class="panel panel-info topic-panel"> |
... | ... | @@ -57,6 +58,18 @@ |
57 | 58 | </div> |
58 | 59 | </div> |
59 | 60 | <div id="{{subject.slug}}" class="panel-collapse in collapse category-panel-content"> |
61 | + {% if has_subject_permissions %} | |
62 | + <form id="student_goals" action="" method="POST"> | |
63 | + {% csrf_token %} | |
64 | + <select name="selected_student" onchange="$('#student_goals').submit();"> | |
65 | + {% for stu in sub_students %} | |
66 | + <option value="{{ stu.email }}" {% if stu.email == student %}selected{% endif %}>{{ stu }}</option> | |
67 | + {% endfor %} | |
68 | + </select> | |
69 | + </form> | |
70 | + <br clear="all" /> | |
71 | + {% endif %} | |
72 | + | |
60 | 73 | {% autoescape off %} |
61 | 74 | {{ goal.presentation }} |
62 | 75 | {% endautoescape %} |
... | ... | @@ -77,13 +90,22 @@ |
77 | 90 | </div> |
78 | 91 | {% endfor %} |
79 | 92 | |
80 | - {% if not goal|is_close %} | |
81 | - <hr /> | |
93 | + {% if not has_subject_permissions %} | |
94 | + {% if not goal|is_close %} | |
95 | + <hr /> | |
82 | 96 | |
83 | - <div class="text-center"> | |
84 | - <a href="{% url 'goals:update_submit' goal.slug %}" class="btn btn-success btn-raised">{% trans 'Update Goals' %}</a> | |
85 | - </div> | |
97 | + <div class="text-center"> | |
98 | + <a href="{% url 'goals:update_submit' goal.slug %}" class="btn btn-success btn-raised">{% trans 'Update Goals' %}</a> | |
99 | + </div> | |
100 | + {% endif %} | |
86 | 101 | {% endif %} |
87 | 102 | </div> |
88 | 103 | </div> |
89 | 104 | {% endblock %} |
105 | + | |
106 | + | |
107 | +{% block addtional_scripts %} | |
108 | + <script type="text/javascript"> | |
109 | + sessionSecurity.confirmFormDiscard = undefined; | |
110 | + </script> | |
111 | +{% endblock %} | |
90 | 112 | \ No newline at end of file | ... | ... |
goals/views.py
... | ... | @@ -207,16 +207,41 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.ListView): |
207 | 207 | |
208 | 208 | template_name = 'goals/view.html' |
209 | 209 | model = Goals |
210 | - context_object_name = 'itens' | |
210 | + context_object_name = 'itens' | |
211 | + | |
212 | + students = None | |
211 | 213 | |
212 | 214 | def get_queryset(self): |
213 | 215 | slug = self.kwargs.get('slug', '') |
214 | 216 | goal = get_object_or_404(Goals, slug = slug) |
215 | 217 | |
216 | - goals = MyGoals.objects.filter(user = self.request.user, item__goal = goal) | |
218 | + if has_subject_permissions(self.request.user, goal): | |
219 | + self.students = User.objects.filter(subject_student = goal.topic.subject).order_by('social_name', 'username') | |
220 | + | |
221 | + goals = MyGoals.objects.filter(user = self.students.first(), item__goal = goal) | |
222 | + else: | |
223 | + goals = MyGoals.objects.filter(user = self.request.user, item__goal = goal) | |
217 | 224 | |
218 | 225 | return goals |
219 | 226 | |
227 | + def post(self, request, *args, **kwargs): | |
228 | + slug = self.kwargs.get('slug', '') | |
229 | + goal = get_object_or_404(Goals, slug = slug) | |
230 | + | |
231 | + user = request.POST.get('selected_student', None) | |
232 | + | |
233 | + if has_subject_permissions(request.user, goal): | |
234 | + self.students = User.objects.filter(subject_student = goal.topic.subject).order_by('social_name', 'username') | |
235 | + | |
236 | + if not user is None: | |
237 | + self.object_list = MyGoals.objects.filter(user__email = user, item__goal = goal) | |
238 | + else: | |
239 | + self.object_list = MyGoals.objects.filter(user = self.request.user, item__goal = goal) | |
240 | + else: | |
241 | + self.object_list = MyGoals.objects.filter(user = self.request.user, item__goal = goal) | |
242 | + | |
243 | + return self.render_to_response(self.get_context_data()) | |
244 | + | |
220 | 245 | def dispatch(self, request, *args, **kwargs): |
221 | 246 | slug = self.kwargs.get('slug', '') |
222 | 247 | goals = get_object_or_404(Goals, slug = slug) |
... | ... | @@ -238,6 +263,10 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.ListView): |
238 | 263 | context['topic'] = goals.topic |
239 | 264 | context['subject'] = goals.topic.subject |
240 | 265 | |
266 | + if not self.students is None: | |
267 | + context['sub_students'] = self.students | |
268 | + context['student'] = self.request.POST.get('selected_student', self.students.first().email) | |
269 | + | |
241 | 270 | self.log_context['category_id'] = goals.topic.subject.category.id |
242 | 271 | self.log_context['category_name'] = goals.topic.subject.category.name |
243 | 272 | self.log_context['category_slug'] = goals.topic.subject.category.slug |
... | ... | @@ -799,14 +828,17 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
799 | 828 | def get_success_url(self): |
800 | 829 | messages.success(self.request, _('The Goals specification for the topic %s was realized successfully!')%(self.object.topic.name)) |
801 | 830 | |
802 | - success_url = reverse_lazy('goals:submit', kwargs = {'slug': self.object.slug}) | |
831 | + if has_subject_permissions(self.request.user, self.object): | |
832 | + success_url = reverse_lazy('goals:view', kwargs = {'slug': self.object.slug}) | |
833 | + else: | |
834 | + success_url = reverse_lazy('goals:submit', kwargs = {'slug': self.object.slug}) | |
803 | 835 | |
804 | - if self.object.show_window: | |
805 | - self.request.session['resources'] = {} | |
806 | - self.request.session['resources']['new_page'] = True | |
807 | - self.request.session['resources']['new_page_url'] = reverse('goals:window_submit', kwargs = {'slug': self.object.slug}) | |
836 | + if self.object.show_window: | |
837 | + self.request.session['resources'] = {} | |
838 | + self.request.session['resources']['new_page'] = True | |
839 | + self.request.session['resources']['new_page_url'] = reverse('goals:window_submit', kwargs = {'slug': self.object.slug}) | |
808 | 840 | |
809 | - success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | |
841 | + success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | |
810 | 842 | |
811 | 843 | return success_url |
812 | 844 | ... | ... |