Commit a36b1fdc93f6ba4b5482f02b2df7901a1fb10ba5
1 parent
277a890b
Exists in
master
and in
3 other branches
Adjusts in notification search
Showing
3 changed files
with
28 additions
and
3 deletions
Show diff stats
notifications/templates/notifications/_history.html
@@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
10 | <div class="form-group"> | 10 | <div class="form-group"> |
11 | <label class="col-md-4 history-control-label control-label">{% trans 'Search' %}:</label> | 11 | <label class="col-md-4 history-control-label control-label">{% trans 'Search' %}:</label> |
12 | <div class="col-md-8"> | 12 | <div class="col-md-8"> |
13 | - <input type="text" class="form-control" name="search" placeholder="{% trans 'Search...' %}" /> | 13 | + <input type="text" class="form-control" name="search" value="{{ searched }}" placeholder="{% trans 'Search...' %}" /> |
14 | </div> | 14 | </div> |
15 | </div> | 15 | </div> |
16 | </form> | 16 | </form> |
notifications/utils.py
1 | from datetime import date | 1 | from datetime import date |
2 | from django.utils import timezone | 2 | from django.utils import timezone |
3 | from django.db.models import Q | 3 | from django.db.models import Q |
4 | +from dateutil.parser import parse | ||
4 | 5 | ||
5 | from log.models import Log | 6 | from log.models import Log |
6 | from pendencies.models import Pendencies | 7 | from pendencies.models import Pendencies |
@@ -96,3 +97,10 @@ def get_order_by(order): | @@ -96,3 +97,10 @@ def get_order_by(order): | ||
96 | return ["-meta"] | 97 | return ["-meta"] |
97 | else: | 98 | else: |
98 | return ["meta"] | 99 | return ["meta"] |
100 | + | ||
101 | +def is_date(string): | ||
102 | + try: | ||
103 | + parse(string) | ||
104 | + return True | ||
105 | + except ValueError: | ||
106 | + return False | ||
99 | \ No newline at end of file | 107 | \ No newline at end of file |
notifications/views.py
@@ -17,7 +17,7 @@ from amadeus.permissions import has_subject_view_permissions | @@ -17,7 +17,7 @@ from amadeus.permissions import has_subject_view_permissions | ||
17 | from subjects.models import Subject | 17 | from subjects.models import Subject |
18 | 18 | ||
19 | from .models import Notification | 19 | from .models import Notification |
20 | -from .utils import get_order_by | 20 | +from .utils import get_order_by, is_date |
21 | 21 | ||
22 | class SubjectNotifications(LoginRequiredMixin, generic.ListView): | 22 | class SubjectNotifications(LoginRequiredMixin, generic.ListView): |
23 | login_url = reverse_lazy("users:login") | 23 | login_url = reverse_lazy("users:login") |
@@ -90,7 +90,23 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView): | @@ -90,7 +90,23 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView): | ||
90 | self.total = notifications.filter(creation_date = datetime.now()).count() | 90 | self.total = notifications.filter(creation_date = datetime.now()).count() |
91 | 91 | ||
92 | if search: | 92 | if search: |
93 | - notifications = notifications.filter(Q(task__resource__name__icontains = search)).order_by(*order) | 93 | + queries = Q(task__resource__name__icontains = search) |
94 | + queries |= Q(task__action__icontains = search) | ||
95 | + | ||
96 | + if search.isdigit(): | ||
97 | + queries |= Q(level = search) | ||
98 | + | ||
99 | + if is_date(search): | ||
100 | + search_date = parser.parse(search) | ||
101 | + search_date = timezone.make_aware(search_date, timezone.get_current_timezone()) | ||
102 | + | ||
103 | + queries |= Q(creation_date = search_date) | ||
104 | + queries |= Q(task__limit_date = search_date) | ||
105 | + queries |= Q(task__end_date = search_date) | ||
106 | + queries |= Q(meta__date = search_date) | ||
107 | + | ||
108 | + | ||
109 | + notifications = notifications.filter(queries).order_by(*order) | ||
94 | 110 | ||
95 | self.num_rows = notifications.count() | 111 | self.num_rows = notifications.count() |
96 | 112 | ||
@@ -107,6 +123,7 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView): | @@ -107,6 +123,7 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView): | ||
107 | context['history'] = True | 123 | context['history'] = True |
108 | context['total'] = self.total | 124 | context['total'] = self.total |
109 | context['rows'] = self.num_rows | 125 | context['rows'] = self.num_rows |
126 | + context['searched'] = self.request.GET.get("search", "") | ||
110 | 127 | ||
111 | return context | 128 | return context |
112 | 129 |