Commit 8e93a82c33443a3441ccd755a56a33058365f082

Authored by Zambom
1 parent ae544a77

Adding notification history search and ordering

amadeus/templates/pagination.html
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 text-center"> 3 <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 text-center">
4 <ul class="pagination"> 4 <ul class="pagination">
5 {% if page_obj.has_previous %} 5 {% if page_obj.has_previous %}
6 - <li><a href="?page={{ page_obj.previous_page_number }}">&laquo;</a></li> 6 + <li><a href="?page={{ page_obj.previous_page_number }}{{ getvars }}">&laquo;</a></li>
7 {% else %} 7 {% else %}
8 <li class="disabled"><span>&laquo;</span></li> 8 <li class="disabled"><span>&laquo;</span></li>
9 {% endif %} 9 {% endif %}
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 {% endfor %} 15 {% endfor %}
16 16
17 {% if page_obj.has_next %} 17 {% if page_obj.has_next %}
18 - <li><a href="?page={{ page_obj.next_page_number }}">&raquo;</a></li> 18 + <li><a href="?page={{ page_obj.next_page_number }}{{ getvars }}">&raquo;</a></li>
19 {% else %} 19 {% else %}
20 <li class="disabled"><span>&raquo;</span></li> 20 <li class="disabled"><span>&raquo;</span></li>
21 {% endif %} 21 {% endif %}
notifications/templates/notifications/_history.html
@@ -17,12 +17,36 @@ @@ -17,12 +17,36 @@
17 </div> 17 </div>
18 <table class="table table-striped table-bordered"> 18 <table class="table table-striped table-bordered">
19 <thead> 19 <thead>
20 - <th>{% trans 'Date' %}</th>  
21 - <th>{% trans 'Resource' %}</th>  
22 - <th>{% trans 'Task' %}</th>  
23 - <th>{% trans 'Final Date' %}</th>  
24 - <th>{% trans 'Notification' %}</th>  
25 - <th>{% trans 'Observation' %}</th> 20 + <th>
  21 + <a href="{{ request|order_href:'creation_date' }}">
  22 + {% trans 'Date' %} <i class="fa fa-fw {{ request|order_icon_class:'creation_date' }} pull-right"></i>
  23 + </a>
  24 + </th>
  25 + <th>
  26 + <a href="{{ request|order_href:'resource' }}">
  27 + {% trans 'Resource' %} <i class="fa fa-fw {{ request|order_icon_class:'resource' }} pull-right"></i>
  28 + </a>
  29 + </th>
  30 + <th>
  31 + <a href="{{ request|order_href:'task' }}">
  32 + {% trans 'Task' %} <i class="fa fa-fw {{ request|order_icon_class:'task' }} pull-right"></i>
  33 + </a>
  34 + </th>
  35 + <th>
  36 + <a href="{{ request|order_href:'final_date' }}">
  37 + {% trans 'Final Date' %} <i class="fa fa-fw {{ request|order_icon_class:'final_date' }} pull-right"></i>
  38 + </a>
  39 + </th>
  40 + <th>
  41 + <a href="{{ request|order_href:'notification' }}">
  42 + {% trans 'Notification' %} <i class="fa fa-fw {{ request|order_icon_class:'notification' }} pull-right"></i>
  43 + </a>
  44 + </th>
  45 + <th>
  46 + <a href="{{ request|order_href:'obs' }}">
  47 + {% trans 'Observation' %} <i class="fa fa-fw {{ request|order_icon_class:'obs' }} pull-right"></i>
  48 + </a>
  49 + </th>
26 </thead> 50 </thead>
27 <tbody> 51 <tbody>
28 {% if rows > 0 %} 52 {% if rows > 0 %}
notifications/templatetags/notification_filters.py
@@ -42,4 +42,49 @@ def done_percent(notification): @@ -42,4 +42,49 @@ def done_percent(notification):
42 42
43 not_done = (notified * 100) / number_users 43 not_done = (notified * 100) / number_users
44 44
45 - return 100 - not_done  
46 \ No newline at end of file 45 \ No newline at end of file
  46 + return 100 - not_done
  47 +
  48 +@register.filter(name = 'order_icon_class')
  49 +def order_icon_class(request, column):
  50 + getvars = request.GET.copy()
  51 + order = None
  52 + class_name = "fa-sort"
  53 +
  54 + if 'order_by' in getvars:
  55 + order = getvars['order_by']
  56 +
  57 + if not order:
  58 + if column == "creation_date":
  59 + class_name = "fa-sort-desc"
  60 + else:
  61 + if column in order:
  62 + if "-" in order:
  63 + class_name = "fa-sort-desc"
  64 + else:
  65 + class_name = "fa-sort-asc"
  66 +
  67 + return class_name
  68 +
  69 +@register.filter(name = 'order_href')
  70 +def order_href(request, column):
  71 + getvars = request.GET.copy()
  72 + order_href = "-" + column
  73 + order = None
  74 + params = ""
  75 +
  76 + if 'order_by' in getvars:
  77 + order = getvars['order_by']
  78 + del getvars['order_by']
  79 +
  80 + if not order:
  81 + if column == "creation_date":
  82 + order_href = "creation_date"
  83 + else:
  84 + if column in order:
  85 + if "-" in order:
  86 + order_href = column
  87 +
  88 + if len(getvars) > 0:
  89 + params = '&%s' % getvars.urlencode()
  90 +
  91 + return "?order_by=" + order_href + params
47 \ No newline at end of file 92 \ No newline at end of file
notifications/utils.py
@@ -60,4 +60,37 @@ def set_notifications(): @@ -60,4 +60,37 @@ def set_notifications():
60 60
61 notification.save() 61 notification.save()
62 62
63 - 63 +def get_order_by(order):
  64 + if not order:
  65 + return ["-creation_date"]
  66 +
  67 + if "creation_date" in order:
  68 + if "-" in order:
  69 + return ["-creation_date"]
  70 + else:
  71 + return ["creation_date"]
  72 + elif "resource" in order:
  73 + if "-" in order:
  74 + return ["-task__resource__name"]
  75 + else:
  76 + return ["task__resource__name"]
  77 + elif "task" in order:
  78 + if "-" in order:
  79 + return ["-task__action"]
  80 + else:
  81 + return ["task__action"]
  82 + elif "final_date" in order:
  83 + if "-" in order:
  84 + return ["-task__limit_date", "-task__end_date"]
  85 + else:
  86 + return ["task__limit_date", "task__end_date"]
  87 + elif "notification" in order:
  88 + if "-" in order:
  89 + return ["-level"]
  90 + else:
  91 + return ["level"]
  92 + elif "obs" in order:
  93 + if "-" in order:
  94 + return ["-meta"]
  95 + else:
  96 + return ["meta"]
notifications/views.py
@@ -4,6 +4,7 @@ from django.contrib import messages @@ -4,6 +4,7 @@ from django.contrib import messages
4 from django.core.urlresolvers import reverse, reverse_lazy 4 from django.core.urlresolvers import reverse, reverse_lazy
5 from django.utils.translation import ugettext_lazy as _ 5 from django.utils.translation import ugettext_lazy as _
6 from django.contrib.auth.mixins import LoginRequiredMixin 6 from django.contrib.auth.mixins import LoginRequiredMixin
  7 +from django.db.models import Q
7 8
8 from datetime import datetime 9 from datetime import datetime
9 10
@@ -12,6 +13,7 @@ from amadeus.permissions import has_subject_view_permissions @@ -12,6 +13,7 @@ from amadeus.permissions import has_subject_view_permissions
12 from subjects.models import Subject 13 from subjects.models import Subject
13 14
14 from .models import Notification 15 from .models import Notification
  16 +from .utils import get_order_by
15 17
16 class SubjectNotifications(LoginRequiredMixin, generic.ListView): 18 class SubjectNotifications(LoginRequiredMixin, generic.ListView):
17 login_url = reverse_lazy("users:login") 19 login_url = reverse_lazy("users:login")
@@ -35,7 +37,7 @@ class SubjectNotifications(LoginRequiredMixin, generic.ListView): @@ -35,7 +37,7 @@ class SubjectNotifications(LoginRequiredMixin, generic.ListView):
35 slug = self.kwargs.get('slug', '') 37 slug = self.kwargs.get('slug', '')
36 subject = get_object_or_404(Subject, slug = slug) 38 subject = get_object_or_404(Subject, slug = slug)
37 39
38 - notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject, creation_date = datetime.now()) 40 + 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")
39 41
40 self.total = notifications.count() 42 self.total = notifications.count()
41 43
@@ -76,9 +78,16 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView): @@ -76,9 +78,16 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView):
76 slug = self.kwargs.get('slug', '') 78 slug = self.kwargs.get('slug', '')
77 subject = get_object_or_404(Subject, slug = slug) 79 subject = get_object_or_404(Subject, slug = slug)
78 80
79 - notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject).order_by("-creation_date") 81 + order = get_order_by(self.request.GET.get("order_by", None))
  82 + search = self.request.GET.get("search", None)
  83 +
  84 + notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject).order_by(*order)
80 85
81 self.total = notifications.filter(creation_date = datetime.now()).count() 86 self.total = notifications.filter(creation_date = datetime.now()).count()
  87 +
  88 + if search:
  89 + notifications = notifications.filter(Q(task__resource__name__icontains = search)).order_by(*order)
  90 +
82 self.num_rows = notifications.count() 91 self.num_rows = notifications.count()
83 92
84 return notifications 93 return notifications