diff --git a/amadeus/templates/pagination.html b/amadeus/templates/pagination.html index 1a76e6a..6dfa807 100644 --- a/amadeus/templates/pagination.html +++ b/amadeus/templates/pagination.html @@ -3,7 +3,7 @@
- - - - - - + + + + + + {% if rows > 0 %} diff --git a/notifications/templatetags/notification_filters.py b/notifications/templatetags/notification_filters.py index b552bd3..0323a57 100644 --- a/notifications/templatetags/notification_filters.py +++ b/notifications/templatetags/notification_filters.py @@ -42,4 +42,49 @@ def done_percent(notification): not_done = (notified * 100) / number_users - return 100 - not_done \ No newline at end of file + return 100 - not_done + +@register.filter(name = 'order_icon_class') +def order_icon_class(request, column): + getvars = request.GET.copy() + order = None + class_name = "fa-sort" + + if 'order_by' in getvars: + order = getvars['order_by'] + + if not order: + if column == "creation_date": + class_name = "fa-sort-desc" + else: + if column in order: + if "-" in order: + class_name = "fa-sort-desc" + else: + class_name = "fa-sort-asc" + + return class_name + +@register.filter(name = 'order_href') +def order_href(request, column): + getvars = request.GET.copy() + order_href = "-" + column + order = None + params = "" + + if 'order_by' in getvars: + order = getvars['order_by'] + del getvars['order_by'] + + if not order: + if column == "creation_date": + order_href = "creation_date" + else: + if column in order: + if "-" in order: + order_href = column + + if len(getvars) > 0: + params = '&%s' % getvars.urlencode() + + return "?order_by=" + order_href + params \ No newline at end of file diff --git a/notifications/utils.py b/notifications/utils.py index ee3ddb5..32ba0c6 100644 --- a/notifications/utils.py +++ b/notifications/utils.py @@ -60,4 +60,37 @@ def set_notifications(): notification.save() - +def get_order_by(order): + if not order: + return ["-creation_date"] + + if "creation_date" in order: + if "-" in order: + return ["-creation_date"] + else: + return ["creation_date"] + elif "resource" in order: + if "-" in order: + return ["-task__resource__name"] + else: + return ["task__resource__name"] + elif "task" in order: + if "-" in order: + return ["-task__action"] + else: + return ["task__action"] + elif "final_date" in order: + if "-" in order: + return ["-task__limit_date", "-task__end_date"] + else: + return ["task__limit_date", "task__end_date"] + elif "notification" in order: + if "-" in order: + return ["-level"] + else: + return ["level"] + elif "obs" in order: + if "-" in order: + return ["-meta"] + else: + return ["meta"] diff --git a/notifications/views.py b/notifications/views.py index 84fc594..292fd3e 100644 --- a/notifications/views.py +++ b/notifications/views.py @@ -4,6 +4,7 @@ from django.contrib import messages from django.core.urlresolvers import reverse, reverse_lazy from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.mixins import LoginRequiredMixin +from django.db.models import Q from datetime import datetime @@ -12,6 +13,7 @@ from amadeus.permissions import has_subject_view_permissions from subjects.models import Subject from .models import Notification +from .utils import get_order_by class SubjectNotifications(LoginRequiredMixin, generic.ListView): login_url = reverse_lazy("users:login") @@ -35,7 +37,7 @@ class SubjectNotifications(LoginRequiredMixin, generic.ListView): slug = self.kwargs.get('slug', '') subject = get_object_or_404(Subject, slug = slug) - notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject, creation_date = datetime.now()) + 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") self.total = notifications.count() @@ -76,9 +78,16 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView): slug = self.kwargs.get('slug', '') subject = get_object_or_404(Subject, slug = slug) - notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject).order_by("-creation_date") + order = get_order_by(self.request.GET.get("order_by", None)) + search = self.request.GET.get("search", None) + + notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject).order_by(*order) self.total = notifications.filter(creation_date = datetime.now()).count() + + if search: + notifications = notifications.filter(Q(task__resource__name__icontains = search)).order_by(*order) + self.num_rows = notifications.count() return notifications -- libgit2 0.21.2
{% trans 'Date' %}{% trans 'Resource' %}{% trans 'Task' %}{% trans 'Final Date' %}{% trans 'Notification' %}{% trans 'Observation' %} + + {% trans 'Date' %} + + + + {% trans 'Resource' %} + + + + {% trans 'Task' %} + + + + {% trans 'Final Date' %} + + + + {% trans 'Notification' %} + + + + {% trans 'Observation' %} + +