Commit e6636f13c0adc604f0cdce3a6fe661ca915fa872
1 parent
fbd91084
Exists in
master
and in
2 other branches
Adding non-student view in pendencies (subject template)
Showing
6 changed files
with
146 additions
and
21 deletions
Show diff stats
goals/templates/goals/view.html
... | ... | @@ -33,7 +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 | + {% subject_permissions request.user goal.topic.subject as has_subject_permissions %} | |
37 | 37 | |
38 | 38 | {% if goal.visible %} |
39 | 39 | <div class="panel panel-info topic-panel"> | ... | ... |
goals/views.py
... | ... | @@ -215,7 +215,7 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.ListView): |
215 | 215 | slug = self.kwargs.get('slug', '') |
216 | 216 | goal = get_object_or_404(Goals, slug = slug) |
217 | 217 | |
218 | - if has_subject_permissions(self.request.user, goal): | |
218 | + if has_subject_permissions(self.request.user, goal.topic.subject): | |
219 | 219 | self.students = User.objects.filter(subject_student = goal.topic.subject).order_by('social_name', 'username') |
220 | 220 | |
221 | 221 | goals = MyGoals.objects.filter(user = self.students.first(), item__goal = goal) |
... | ... | @@ -230,7 +230,7 @@ class InsideView(LoginRequiredMixin, LogMixin, generic.ListView): |
230 | 230 | |
231 | 231 | user = request.POST.get('selected_student', None) |
232 | 232 | |
233 | - if has_subject_permissions(request.user, goal): | |
233 | + if has_subject_permissions(request.user, goal.topic.subject): | |
234 | 234 | self.students = User.objects.filter(subject_student = goal.topic.subject).order_by('social_name', 'username') |
235 | 235 | |
236 | 236 | if not user is None: | ... | ... |
notifications/templates/notifications/_history.html
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | </div> |
8 | 8 | <div class="col-md-4"> |
9 | 9 | <form action="" method="GET" class="form-horizontal"> |
10 | + <input type="hidden" value="{{ student }}" name="selected_student" /> | |
10 | 11 | <div class="form-group"> |
11 | 12 | <label class="col-md-4 history-control-label control-label">{% trans 'Search' %}:</label> |
12 | 13 | <div class="col-md-8"> |
... | ... | @@ -18,37 +19,37 @@ |
18 | 19 | <table class="table table-striped table-bordered"> |
19 | 20 | <thead> |
20 | 21 | <th> |
21 | - <a href="{{ request|order_href:'creation_date' }}"> | |
22 | + <a href="{{ request|add_student:student|order_href:'creation_date' }}"> | |
22 | 23 | {% trans 'Date' %} <i class="fa fa-fw {{ request|order_icon_class:'creation_date' }} pull-right"></i> |
23 | 24 | </a> |
24 | 25 | </th> |
25 | 26 | <th> |
26 | - <a href="{{ request|order_href:'resource' }}"> | |
27 | + <a href="{{ request|add_student:student|order_href:'resource' }}"> | |
27 | 28 | {% trans 'Resource' %} <i class="fa fa-fw {{ request|order_icon_class:'resource' }} pull-right"></i> |
28 | 29 | </a> |
29 | 30 | </th> |
30 | 31 | <th> |
31 | - <a href="{{ request|order_href:'task' }}"> | |
32 | + <a href="{{ request|add_student:student|order_href:'task' }}"> | |
32 | 33 | {% trans 'Task' %} <i class="fa fa-fw {{ request|order_icon_class:'task' }} pull-right"></i> |
33 | 34 | </a> |
34 | 35 | </th> |
35 | 36 | <th> |
36 | - <a href="{{ request|order_href:'final_date' }}"> | |
37 | + <a href="{{ request|add_student:student|order_href:'final_date' }}"> | |
37 | 38 | {% trans 'Final Date' %} <i class="fa fa-fw {{ request|order_icon_class:'final_date' }} pull-right"></i> |
38 | 39 | </a> |
39 | 40 | </th> |
40 | 41 | <th> |
41 | - <a href="{{ request|order_href:'notification' }}"> | |
42 | + <a href="{{ request|add_student:student|order_href:'notification' }}"> | |
42 | 43 | {% trans 'Notification' %} <i class="fa fa-fw {{ request|order_icon_class:'notification' }} pull-right"></i> |
43 | 44 | </a> |
44 | 45 | </th> |
45 | 46 | <th> |
46 | - <a href="{{ request|order_href:'aware' }}"> | |
47 | + <a href="{{ request|add_student:student|order_href:'aware' }}"> | |
47 | 48 | {% trans 'Aware' %} <i class="fa fa-fw {{ request|order_icon_class:'aware' }} pull-right"></i> |
48 | 49 | </a> |
49 | 50 | </th> |
50 | 51 | <th> |
51 | - <a href="{{ request|order_href:'obs' }}"> | |
52 | + <a href="{{ request|add_student:student|order_href:'obs' }}"> | |
52 | 53 | {% trans 'Observation' %} <i class="fa fa-fw {{ request|order_icon_class:'obs' }} pull-right"></i> |
53 | 54 | </a> |
54 | 55 | </th> | ... | ... |
notifications/templates/notifications/subject.html
... | ... | @@ -10,6 +10,8 @@ |
10 | 10 | {% endblock %} |
11 | 11 | |
12 | 12 | {% block content %} |
13 | + {% subject_permissions request.user subject as has_subject_permissions %} | |
14 | + | |
13 | 15 | {% if subject.visible %} |
14 | 16 | <div class="panel panel-info subject-panel"> |
15 | 17 | <div class="panel-heading"> |
... | ... | @@ -26,11 +28,36 @@ |
26 | 28 | </div> |
27 | 29 | </div> |
28 | 30 | <div id="{{subject.slug}}" class="panel-collapse in collapse pendencies-content subject-related-panel"> |
31 | + {% if has_subject_permissions %} | |
32 | + <form id="student_goals" action="" method="POST"> | |
33 | + {% csrf_token %} | |
34 | + <select name="selected_student" onchange="$('#student_goals').submit();"> | |
35 | + {% for stu in sub_students %} | |
36 | + <option value="{{ stu.email }}" {% if stu.email == student %}selected{% endif %}>{{ stu }}</option> | |
37 | + {% endfor %} | |
38 | + </select> | |
39 | + </form> | |
40 | + <br clear="all" /> | |
41 | + {% endif %} | |
42 | + | |
29 | 43 | <h5>{% trans 'This pendencies list is updated every 24 hours. Last update was in:' %} {{ last_update|default:_('Not determined') }}</h5> |
30 | 44 | <div id="core-subjects-options-div"> |
31 | 45 | <ul class="core-subjects-options"> |
32 | - <a href="{% url 'notifications:view' subject.slug %}"><li {% if not history %} class="active" {% endif %}>{% trans "Actual Pendencies" %} ({{ total }})</li></a> | |
33 | - <a href="{% url 'notifications:history' subject.slug %}"><li {% if history %} class="active" {% endif %}>{% trans "Notifications History" %}</li></a> | |
46 | + {% if has_subject_permissions %} | |
47 | + <form id="student_pend" action="{% url 'notifications:view' subject.slug %}" method="POST"> | |
48 | + {% csrf_token %} | |
49 | + <input type="hidden" value="{{ student }}" name="selected_student" /> | |
50 | + <a onclick="$('#student_pend').submit();" style="cursor:pointer"><li {% if not history %} class="active" {% endif %}>{% trans "Actual Pendencies" %} ({{ total }})</li></a> | |
51 | + </form> | |
52 | + <form id="student_history" action="{% url 'notifications:history' subject.slug %}" method="POST"> | |
53 | + {% csrf_token %} | |
54 | + <input type="hidden" value="{{ student }}" name="selected_student" /> | |
55 | + <a onclick="$('#student_history').submit();" style="cursor:pointer"><li {% if history %} class="active" {% endif %}>{% trans "Notifications History" %}</li></a> | |
56 | + </form> | |
57 | + {% else %} | |
58 | + <a href="{% url 'notifications:view' subject.slug %}"><li {% if not history %} class="active" {% endif %}>{% trans "Actual Pendencies" %} ({{ total }})</li></a> | |
59 | + <a href="{% url 'notifications:history' subject.slug %}"><li {% if history %} class="active" {% endif %}>{% trans "Notifications History" %}</li></a> | |
60 | + {% endif %} | |
34 | 61 | </ul> |
35 | 62 | </div> |
36 | 63 | |
... | ... | @@ -58,4 +85,10 @@ |
58 | 85 | metaFunctions(); |
59 | 86 | }); |
60 | 87 | </script> |
88 | +{% endblock %} | |
89 | + | |
90 | +{% block addtional_scripts %} | |
91 | + <script type="text/javascript"> | |
92 | + sessionSecurity.confirmFormDiscard = undefined; | |
93 | + </script> | |
61 | 94 | {% endblock %} |
62 | 95 | \ No newline at end of file | ... | ... |
notifications/templatetags/notification_filters.py
... | ... | @@ -85,7 +85,7 @@ def order_href(request, column): |
85 | 85 | if 'order_by' in getvars: |
86 | 86 | order = getvars['order_by'] |
87 | 87 | del getvars['order_by'] |
88 | - | |
88 | + | |
89 | 89 | if not order: |
90 | 90 | if column == "creation_date": |
91 | 91 | order_href = "creation_date" |
... | ... | @@ -93,12 +93,28 @@ def order_href(request, column): |
93 | 93 | if column in order: |
94 | 94 | if "-" in order: |
95 | 95 | order_href = column |
96 | - | |
96 | + | |
97 | 97 | if len(getvars) > 0: |
98 | 98 | params = '&%s' % getvars.urlencode() |
99 | 99 | |
100 | 100 | return "?order_by=" + order_href + params |
101 | 101 | |
102 | +@register.filter(name = 'add_student') | |
103 | +def add_student(request, student): | |
104 | + getvars = request.GET.copy() | |
105 | + params = "" | |
106 | + | |
107 | + if not student is None: | |
108 | + if not student == "": | |
109 | + if 'selected_student' in getvars: | |
110 | + del getvars['selected_student'] | |
111 | + | |
112 | + getvars['selected_student'] = student | |
113 | + | |
114 | + request.GET = getvars | |
115 | + | |
116 | + return request | |
117 | + | |
102 | 118 | @register.filter(name = 'order_ajax') |
103 | 119 | def order_ajax(request, column): |
104 | 120 | getvars = request.GET.copy() |
... | ... | @@ -109,7 +125,7 @@ def order_ajax(request, column): |
109 | 125 | if 'order_by' in getvars: |
110 | 126 | order = getvars['order_by'] |
111 | 127 | del getvars['order_by'] |
112 | - | |
128 | + | |
113 | 129 | if not order: |
114 | 130 | if column == "creation_date": |
115 | 131 | order_href = "creation_date" |
... | ... | @@ -117,7 +133,7 @@ def order_ajax(request, column): |
117 | 133 | if column in order: |
118 | 134 | if "-" in order: |
119 | 135 | order_href = column |
120 | - | |
136 | + | |
121 | 137 | return order_href |
122 | 138 | |
123 | 139 | @register.filter(name = 'observation') | ... | ... |
notifications/views.py
... | ... | @@ -12,10 +12,11 @@ from dateutil import parser |
12 | 12 | from datetime import datetime |
13 | 13 | from django.utils import formats, timezone |
14 | 14 | |
15 | -from amadeus.permissions import has_subject_view_permissions, has_category_permission | |
15 | +from amadeus.permissions import has_subject_view_permissions, has_category_permission, has_subject_permissions | |
16 | 16 | |
17 | 17 | from subjects.models import Subject |
18 | 18 | from categories.models import Category |
19 | +from users.models import User | |
19 | 20 | |
20 | 21 | from log.models import Log |
21 | 22 | from log.mixins import LogMixin |
... | ... | @@ -39,6 +40,8 @@ class SubjectNotifications(LoginRequiredMixin, LogMixin, generic.ListView): |
39 | 40 | paginate_by = 10 |
40 | 41 | total = 0 |
41 | 42 | |
43 | + students = None | |
44 | + | |
42 | 45 | def dispatch(self, request, *args, **kwargs): |
43 | 46 | slug = self.kwargs.get('slug', '') |
44 | 47 | subject = get_object_or_404(Subject, slug = slug) |
... | ... | @@ -52,14 +55,38 @@ class SubjectNotifications(LoginRequiredMixin, LogMixin, generic.ListView): |
52 | 55 | slug = self.kwargs.get('slug', '') |
53 | 56 | subject = get_object_or_404(Subject, slug = slug) |
54 | 57 | |
55 | - notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject, creation_date = datetime.now()).order_by("task__limit_date", "task__end_date") | |
56 | - | |
57 | - notifications.update(viewed = True) | |
58 | + if has_subject_permissions(self.request.user, subject): | |
59 | + self.students = User.objects.filter(subject_student = subject).order_by('social_name', 'username') | |
58 | 60 | |
61 | + notifications = Notification.objects.filter(user = self.students.first(), task__resource__topic__subject = subject, creation_date = datetime.now()).order_by("task__limit_date", "task__end_date") | |
62 | + else: | |
63 | + notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject, creation_date = datetime.now()).order_by("task__limit_date", "task__end_date") | |
64 | + notifications.update(viewed = True) | |
65 | + | |
59 | 66 | self.total = notifications.count() |
60 | 67 | |
61 | 68 | return notifications |
62 | 69 | |
70 | + def post(self, request, *args, **kwargs): | |
71 | + slug = self.kwargs.get('slug', '') | |
72 | + subject = get_object_or_404(Subject, slug = slug) | |
73 | + | |
74 | + user = request.POST.get('selected_student', None) | |
75 | + | |
76 | + if has_subject_permissions(request.user, subject): | |
77 | + self.students = User.objects.filter(subject_student = subject).order_by('social_name', 'username') | |
78 | + | |
79 | + if not user is None: | |
80 | + self.object_list = Notification.objects.filter(user__email = user, task__resource__topic__subject = subject, creation_date = datetime.now()).order_by("task__limit_date", "task__end_date") | |
81 | + else: | |
82 | + self.object_list = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject, creation_date = datetime.now()).order_by("task__limit_date", "task__end_date") | |
83 | + else: | |
84 | + self.object_list = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject, creation_date = datetime.now()).order_by("task__limit_date", "task__end_date") | |
85 | + | |
86 | + self.total = self.object_list.count() | |
87 | + | |
88 | + return self.render_to_response(self.get_context_data()) | |
89 | + | |
63 | 90 | def get_context_data(self, **kwargs): |
64 | 91 | context = super(SubjectNotifications, self).get_context_data(**kwargs) |
65 | 92 | |
... | ... | @@ -70,6 +97,12 @@ class SubjectNotifications(LoginRequiredMixin, LogMixin, generic.ListView): |
70 | 97 | context['subject'] = subject |
71 | 98 | context['total'] = self.total |
72 | 99 | |
100 | + if not self.students is None: | |
101 | + context['sub_students'] = self.students | |
102 | + context['student'] = self.request.POST.get('selected_student', self.students.first().email) | |
103 | + else: | |
104 | + context['student'] = None | |
105 | + | |
73 | 106 | update_pendencies = Log.objects.filter(action = "cron", component = "notifications").order_by('-datetime') |
74 | 107 | |
75 | 108 | if update_pendencies.count() > 0: |
... | ... | @@ -104,6 +137,8 @@ class SubjectHistory(LoginRequiredMixin, LogMixin, generic.ListView): |
104 | 137 | total = 0 |
105 | 138 | num_rows = 0 |
106 | 139 | |
140 | + students = None | |
141 | + | |
107 | 142 | def dispatch(self, request, *args, **kwargs): |
108 | 143 | slug = self.kwargs.get('slug', '') |
109 | 144 | subject = get_object_or_404(Subject, slug = slug) |
... | ... | @@ -120,7 +155,17 @@ class SubjectHistory(LoginRequiredMixin, LogMixin, generic.ListView): |
120 | 155 | order = get_order_by(self.request.GET.get("order_by", None)) |
121 | 156 | search = self.request.GET.get("search", None) |
122 | 157 | |
123 | - notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject).order_by(*order) | |
158 | + if has_subject_permissions(self.request.user, subject): | |
159 | + user = self.request.GET.get("selected_student", None) | |
160 | + | |
161 | + self.students = User.objects.filter(subject_student = subject).order_by('social_name', 'username') | |
162 | + | |
163 | + if not user is None: | |
164 | + notifications = Notification.objects.filter(user__email = user, task__resource__topic__subject = subject).order_by(*order) | |
165 | + else: | |
166 | + notifications = Notification.objects.filter(user = self.students.first(), task__resource__topic__subject = subject).order_by(*order) | |
167 | + else: | |
168 | + notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject).order_by(*order) | |
124 | 169 | |
125 | 170 | self.total = notifications.filter(creation_date = datetime.now()).count() |
126 | 171 | |
... | ... | @@ -145,6 +190,30 @@ class SubjectHistory(LoginRequiredMixin, LogMixin, generic.ListView): |
145 | 190 | |
146 | 191 | return notifications |
147 | 192 | |
193 | + def post(self, request, *args, **kwargs): | |
194 | + slug = self.kwargs.get('slug', '') | |
195 | + subject = get_object_or_404(Subject, slug = slug) | |
196 | + | |
197 | + order = get_order_by(self.request.POST.get("order_by", None)) | |
198 | + | |
199 | + user = request.POST.get('selected_student', None) | |
200 | + | |
201 | + if has_subject_permissions(request.user, subject): | |
202 | + self.students = User.objects.filter(subject_student = subject).order_by('social_name', 'username') | |
203 | + | |
204 | + if not user is None: | |
205 | + self.object_list = Notification.objects.filter(user__email = user, task__resource__topic__subject = subject).order_by(*order) | |
206 | + else: | |
207 | + self.object_list = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject).order_by(*order) | |
208 | + else: | |
209 | + self.object_list = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject).order_by(*order) | |
210 | + | |
211 | + self.total = self.object_list.filter(creation_date = datetime.now()).count() | |
212 | + | |
213 | + self.num_rows = self.object_list.count() | |
214 | + | |
215 | + return self.render_to_response(self.get_context_data()) | |
216 | + | |
148 | 217 | def get_context_data(self, **kwargs): |
149 | 218 | context = super(SubjectHistory, self).get_context_data(**kwargs) |
150 | 219 | |
... | ... | @@ -158,6 +227,12 @@ class SubjectHistory(LoginRequiredMixin, LogMixin, generic.ListView): |
158 | 227 | context['rows'] = self.num_rows |
159 | 228 | context['searched'] = self.request.GET.get("search", "") |
160 | 229 | |
230 | + if not self.students is None: | |
231 | + context['sub_students'] = self.students | |
232 | + context['student'] = self.request.POST.get('selected_student', self.request.GET.get('selected_student', self.students.first().email)) | |
233 | + else: | |
234 | + context['student'] = None | |
235 | + | |
161 | 236 | self.log_context['subject_id'] = subject.id |
162 | 237 | self.log_context['subject_name'] = subject.name |
163 | 238 | self.log_context['subject_slug'] = subject.slug | ... | ... |