diff --git a/amadeus/permissions.py b/amadeus/permissions.py
index 380405a..fbe7a81 100644
--- a/amadeus/permissions.py
+++ b/amadeus/permissions.py
@@ -1,5 +1,6 @@
# File used to store functions to handle permissions
+from subjects.models import Subject
from topics.models import Resource
"""
@@ -20,6 +21,10 @@ def has_subject_permissions(user, subject):
return False
+"""
+ Function to know if user has permission to:
+ - See subject
+"""
def has_subject_view_permissions(user, subject):
if has_subject_permissions(user, subject):
return True
@@ -30,6 +35,14 @@ def has_subject_view_permissions(user, subject):
return False
"""
+ Function to know if user is student of some subject in category
+"""
+def has_category_permission(user, cat_slug):
+ exist = Subject.objects.filter(students__id = user.id, category__slug = cat_slug).exists()
+
+ return exist
+
+"""
Function to know if user has permission to:
- Access Resource
"""
diff --git a/notifications/templates/notifications/index.html b/notifications/templates/notifications/index.html
index 209e805..a19712e 100644
--- a/notifications/templates/notifications/index.html
+++ b/notifications/templates/notifications/index.html
@@ -6,13 +6,18 @@
{% block breadcrumbs %}
{{ block.super }}
+ {% if category %}
+ {% breadcrumb category 'subjects:cat_view' category.slug %}
+ {% endif %}
+
{% breadcrumb 'Pendencies' 'notifications:manage' %}
+
{% endblock %}
{% block content %}
-
{% if notifications.count > 0 %}
+
{% trans 'You got pendencies in the following subjects' %}:
{% for notification in notifications %}
diff --git a/notifications/urls.py b/notifications/urls.py
index 2feb177..b26949f 100644
--- a/notifications/urls.py
+++ b/notifications/urls.py
@@ -3,6 +3,7 @@ from . import views
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='manage'),
+ url(r'^category/(?P
[\w_-]+)/$', views.IndexView.as_view(), name='manage_cat'),
url(r'^set_goal/$', views.set_goal, name='set_goal'),
url(r'^ajax/(?P[\w_-]+)/$', views.AjaxNotifications.as_view(), name='ajax_view'),
url(r'^ajax_history/(?P[\w_-]+)/$', views.AjaxHistory.as_view(), name='ajax_history'),
diff --git a/notifications/views.py b/notifications/views.py
index 9a39ce3..d8ba891 100644
--- a/notifications/views.py
+++ b/notifications/views.py
@@ -12,9 +12,10 @@ from dateutil import parser
from datetime import datetime
from django.utils import formats, timezone
-from amadeus.permissions import has_subject_view_permissions
+from amadeus.permissions import has_subject_view_permissions, has_category_permission
from subjects.models import Subject
+from categories.models import Category
from .models import Notification
from .utils import get_order_by, is_date
@@ -43,6 +44,8 @@ class SubjectNotifications(LoginRequiredMixin, generic.ListView):
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")
+ notifications.update(viewed = True)
+
self.total = notifications.count()
return notifications
@@ -134,8 +137,22 @@ class IndexView(LoginRequiredMixin, generic.ListView):
template_name = 'notifications/index.html'
paginate_by = 10
+ def dispatch(self, request, *args, **kwargs):
+ cat = self.kwargs.get('slug', None)
+
+ if cat:
+ if not has_category_permission(request.user, cat):
+ return redirect(reverse_lazy('subjects:home'))
+
+ return super(IndexView, self).dispatch(request, *args, **kwargs)
+
def get_queryset(self):
- 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'))
+ cat = self.kwargs.get('slug', None)
+
+ if cat:
+ 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'))
+ else:
+ 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'))
return notifications
@@ -143,7 +160,14 @@ class IndexView(LoginRequiredMixin, generic.ListView):
context = super(IndexView, self).get_context_data(**kwargs)
context['title'] = _('Pendencies')
- context['pendencies_menu_active'] = "subjects_menu_active"
+
+ cat = self.kwargs.get('slug', None)
+
+ if cat:
+ context['category'] = get_object_or_404(Category, slug = cat)
+ else:
+ context['pendencies_menu_active'] = "subjects_menu_active"
+
return context
@@ -159,6 +183,8 @@ class AjaxNotifications(LoginRequiredMixin, generic.ListView):
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")
+ notifications.update(viewed = True)
+
return notifications
class AjaxHistory(LoginRequiredMixin, generic.ListView):
diff --git a/subjects/templates/subjects/list.html b/subjects/templates/subjects/list.html
index cdf0135..9707fdd 100644
--- a/subjects/templates/subjects/list.html
+++ b/subjects/templates/subjects/list.html
@@ -81,7 +81,7 @@
{% endif %}
-
+
{% notifies_cat_number category request.user %}
--
libgit2 0.21.2