Commit 0f3dd7a8cb98770a791e0edd28f02a5b9c726a0d
1 parent
b737ff62
Exists in
master
and in
3 other branches
Adding category pendencies page
Showing
5 changed files
with
50 additions
and
5 deletions
Show diff stats
amadeus/permissions.py
1 | # File used to store functions to handle permissions | 1 | # File used to store functions to handle permissions |
2 | 2 | ||
3 | +from subjects.models import Subject | ||
3 | from topics.models import Resource | 4 | from topics.models import Resource |
4 | 5 | ||
5 | """ | 6 | """ |
@@ -20,6 +21,10 @@ def has_subject_permissions(user, subject): | @@ -20,6 +21,10 @@ def has_subject_permissions(user, subject): | ||
20 | 21 | ||
21 | return False | 22 | return False |
22 | 23 | ||
24 | +""" | ||
25 | + Function to know if user has permission to: | ||
26 | + - See subject | ||
27 | +""" | ||
23 | def has_subject_view_permissions(user, subject): | 28 | def has_subject_view_permissions(user, subject): |
24 | if has_subject_permissions(user, subject): | 29 | if has_subject_permissions(user, subject): |
25 | return True | 30 | return True |
@@ -30,6 +35,14 @@ def has_subject_view_permissions(user, subject): | @@ -30,6 +35,14 @@ def has_subject_view_permissions(user, subject): | ||
30 | return False | 35 | return False |
31 | 36 | ||
32 | """ | 37 | """ |
38 | + Function to know if user is student of some subject in category | ||
39 | +""" | ||
40 | +def has_category_permission(user, cat_slug): | ||
41 | + exist = Subject.objects.filter(students__id = user.id, category__slug = cat_slug).exists() | ||
42 | + | ||
43 | + return exist | ||
44 | + | ||
45 | +""" | ||
33 | Function to know if user has permission to: | 46 | Function to know if user has permission to: |
34 | - Access Resource | 47 | - Access Resource |
35 | """ | 48 | """ |
notifications/templates/notifications/index.html
@@ -6,13 +6,18 @@ | @@ -6,13 +6,18 @@ | ||
6 | {% block breadcrumbs %} | 6 | {% block breadcrumbs %} |
7 | {{ block.super }} | 7 | {{ block.super }} |
8 | 8 | ||
9 | + {% if category %} | ||
10 | + {% breadcrumb category 'subjects:cat_view' category.slug %} | ||
11 | + {% endif %} | ||
12 | + | ||
9 | {% breadcrumb 'Pendencies' 'notifications:manage' %} | 13 | {% breadcrumb 'Pendencies' 'notifications:manage' %} |
14 | + | ||
10 | {% endblock %} | 15 | {% endblock %} |
11 | 16 | ||
12 | {% block content %} | 17 | {% block content %} |
13 | <input type="hidden" id="pend_url" value="{% url 'notifications:manage' %}" /> | 18 | <input type="hidden" id="pend_url" value="{% url 'notifications:manage' %}" /> |
14 | - | ||
15 | {% if notifications.count > 0 %} | 19 | {% if notifications.count > 0 %} |
20 | + <p>{% trans 'You got pendencies in the following subjects' %}: </p> | ||
16 | <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true"> | 21 | <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true"> |
17 | {% for notification in notifications %} | 22 | {% for notification in notifications %} |
18 | <div class="panel panel-info subject-panel"> | 23 | <div class="panel panel-info subject-panel"> |
notifications/urls.py
@@ -3,6 +3,7 @@ from . import views | @@ -3,6 +3,7 @@ from . import views | ||
3 | 3 | ||
4 | urlpatterns = [ | 4 | urlpatterns = [ |
5 | url(r'^$', views.IndexView.as_view(), name='manage'), | 5 | url(r'^$', views.IndexView.as_view(), name='manage'), |
6 | + url(r'^category/(?P<slug>[\w_-]+)/$', views.IndexView.as_view(), name='manage_cat'), | ||
6 | url(r'^set_goal/$', views.set_goal, name='set_goal'), | 7 | url(r'^set_goal/$', views.set_goal, name='set_goal'), |
7 | url(r'^ajax/(?P<id>[\w_-]+)/$', views.AjaxNotifications.as_view(), name='ajax_view'), | 8 | url(r'^ajax/(?P<id>[\w_-]+)/$', views.AjaxNotifications.as_view(), name='ajax_view'), |
8 | url(r'^ajax_history/(?P<id>[\w_-]+)/$', views.AjaxHistory.as_view(), name='ajax_history'), | 9 | url(r'^ajax_history/(?P<id>[\w_-]+)/$', views.AjaxHistory.as_view(), name='ajax_history'), |
notifications/views.py
@@ -12,9 +12,10 @@ from dateutil import parser | @@ -12,9 +12,10 @@ from dateutil import parser | ||
12 | from datetime import datetime | 12 | from datetime import datetime |
13 | from django.utils import formats, timezone | 13 | from django.utils import formats, timezone |
14 | 14 | ||
15 | -from amadeus.permissions import has_subject_view_permissions | 15 | +from amadeus.permissions import has_subject_view_permissions, has_category_permission |
16 | 16 | ||
17 | from subjects.models import Subject | 17 | from subjects.models import Subject |
18 | +from categories.models import Category | ||
18 | 19 | ||
19 | from .models import Notification | 20 | from .models import Notification |
20 | from .utils import get_order_by, is_date | 21 | from .utils import get_order_by, is_date |
@@ -43,6 +44,8 @@ class SubjectNotifications(LoginRequiredMixin, generic.ListView): | @@ -43,6 +44,8 @@ class SubjectNotifications(LoginRequiredMixin, generic.ListView): | ||
43 | 44 | ||
44 | 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") | 45 | 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") |
45 | 46 | ||
47 | + notifications.update(viewed = True) | ||
48 | + | ||
46 | self.total = notifications.count() | 49 | self.total = notifications.count() |
47 | 50 | ||
48 | return notifications | 51 | return notifications |
@@ -134,8 +137,22 @@ class IndexView(LoginRequiredMixin, generic.ListView): | @@ -134,8 +137,22 @@ class IndexView(LoginRequiredMixin, generic.ListView): | ||
134 | template_name = 'notifications/index.html' | 137 | template_name = 'notifications/index.html' |
135 | paginate_by = 10 | 138 | paginate_by = 10 |
136 | 139 | ||
140 | + def dispatch(self, request, *args, **kwargs): | ||
141 | + cat = self.kwargs.get('slug', None) | ||
142 | + | ||
143 | + if cat: | ||
144 | + if not has_category_permission(request.user, cat): | ||
145 | + return redirect(reverse_lazy('subjects:home')) | ||
146 | + | ||
147 | + return super(IndexView, self).dispatch(request, *args, **kwargs) | ||
148 | + | ||
137 | def get_queryset(self): | 149 | def get_queryset(self): |
138 | - notifications = Notification.objects.filter(user = self.request.user, viewed = False, creation_date = datetime.now()).values('task__resource__topic__subject', 'task__resource__topic__subject__name').annotate(total = Count('task__resource__topic__subject')) | 150 | + cat = self.kwargs.get('slug', None) |
151 | + | ||
152 | + if cat: | ||
153 | + notifications = Notification.objects.filter(user = self.request.user, creation_date = datetime.now(), task__resource__topic__subject__category__slug = cat).values('task__resource__topic__subject', 'task__resource__topic__subject__name').annotate(total = Count('task__resource__topic__subject')) | ||
154 | + else: | ||
155 | + notifications = Notification.objects.filter(user = self.request.user, creation_date = datetime.now()).values('task__resource__topic__subject', 'task__resource__topic__subject__name').annotate(total = Count('task__resource__topic__subject')) | ||
139 | 156 | ||
140 | return notifications | 157 | return notifications |
141 | 158 | ||
@@ -143,7 +160,14 @@ class IndexView(LoginRequiredMixin, generic.ListView): | @@ -143,7 +160,14 @@ class IndexView(LoginRequiredMixin, generic.ListView): | ||
143 | context = super(IndexView, self).get_context_data(**kwargs) | 160 | context = super(IndexView, self).get_context_data(**kwargs) |
144 | 161 | ||
145 | context['title'] = _('Pendencies') | 162 | context['title'] = _('Pendencies') |
146 | - context['pendencies_menu_active'] = "subjects_menu_active" | 163 | + |
164 | + cat = self.kwargs.get('slug', None) | ||
165 | + | ||
166 | + if cat: | ||
167 | + context['category'] = get_object_or_404(Category, slug = cat) | ||
168 | + else: | ||
169 | + context['pendencies_menu_active'] = "subjects_menu_active" | ||
170 | + | ||
147 | 171 | ||
148 | return context | 172 | return context |
149 | 173 | ||
@@ -159,6 +183,8 @@ class AjaxNotifications(LoginRequiredMixin, generic.ListView): | @@ -159,6 +183,8 @@ class AjaxNotifications(LoginRequiredMixin, generic.ListView): | ||
159 | 183 | ||
160 | notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject__id = subject_id, creation_date = datetime.now()).order_by("task__limit_date", "task__end_date") | 184 | notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject__id = subject_id, creation_date = datetime.now()).order_by("task__limit_date", "task__end_date") |
161 | 185 | ||
186 | + notifications.update(viewed = True) | ||
187 | + | ||
162 | return notifications | 188 | return notifications |
163 | 189 | ||
164 | class AjaxHistory(LoginRequiredMixin, generic.ListView): | 190 | class AjaxHistory(LoginRequiredMixin, generic.ListView): |
subjects/templates/subjects/list.html
@@ -81,7 +81,7 @@ | @@ -81,7 +81,7 @@ | ||
81 | {% endif %} | 81 | {% endif %} |
82 | 82 | ||
83 | <a href="" class="pull-right action_icon"><i class="fa fa-bar-chart" aria-hidden="true"></i></a> | 83 | <a href="" class="pull-right action_icon"><i class="fa fa-bar-chart" aria-hidden="true"></i></a> |
84 | - <a href="" class="pull-right action_icon"> | 84 | + <a href="{% url 'notifications:manage_cat' category.slug %}" class="pull-right action_icon"> |
85 | <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> | 85 | <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> |
86 | {% notifies_cat_number category request.user %} | 86 | {% notifies_cat_number category request.user %} |
87 | </a> | 87 | </a> |