Commit 277a890bc820851e8de200cfba9d28b368701207
1 parent
ba0047d1
Exists in
master
and in
3 other branches
Adding goal definition
Showing
7 changed files
with
84 additions
and
10 deletions
Show diff stats
notifications/templates/notifications/_history.html
@@ -57,8 +57,7 @@ | @@ -57,8 +57,7 @@ | ||
57 | <td>{{ notification.task.get_action_display }}</td> | 57 | <td>{{ notification.task.get_action_display }}</td> |
58 | <td>{{ notification.task.end_date|date:"SHORT_DATE_FORMAT"|default:_('Not Informed') }}</td> | 58 | <td>{{ notification.task.end_date|date:"SHORT_DATE_FORMAT"|default:_('Not Informed') }}</td> |
59 | <td>{{ notification.level|warning_msg }}</td> | 59 | <td>{{ notification.level|warning_msg }}</td> |
60 | - <td> | ||
61 | - </td> | 60 | + <td>{{ notification|observation }}</td> |
62 | </tr> | 61 | </tr> |
63 | {% endfor %} | 62 | {% endfor %} |
64 | {% else %} | 63 | {% else %} |
notifications/templates/notifications/_view.html
@@ -62,14 +62,13 @@ | @@ -62,14 +62,13 @@ | ||
62 | 62 | ||
63 | <div class="popover"> | 63 | <div class="popover"> |
64 | <div class="popover-content"> | 64 | <div class="popover-content"> |
65 | - <form role="form" method="post"> | 65 | + <form action="{% url 'notifications:set_goal' %}" role="form" method="post"> |
66 | {% csrf_token %} | 66 | {% csrf_token %} |
67 | <div style="overflow:hidden;"> | 67 | <div style="overflow:hidden;"> |
68 | <div class="form-group"> | 68 | <div class="form-group"> |
69 | <div class="row"> | 69 | <div class="row"> |
70 | <div class="col-md-12"> | 70 | <div class="col-md-12"> |
71 | <div class="datetimepicker"></div> | 71 | <div class="datetimepicker"></div> |
72 | - <input type="hidden" class="meta" name="meta" /> | ||
73 | <input type="hidden" name="id" value="{{ notification.id }}"> | 72 | <input type="hidden" name="id" value="{{ notification.id }}"> |
74 | </div> | 73 | </div> |
75 | </div> | 74 | </div> |
notifications/templates/notifications/subject.html
@@ -76,6 +76,7 @@ | @@ -76,6 +76,7 @@ | ||
76 | } | 76 | } |
77 | 77 | ||
78 | datetime.datetimepicker({ | 78 | datetime.datetimepicker({ |
79 | + format: "YYYY-MM-DD HH:mm", | ||
79 | locale: locale, | 80 | locale: locale, |
80 | inline: true, | 81 | inline: true, |
81 | sideBySide: false | 82 | sideBySide: false |
@@ -86,9 +87,26 @@ | @@ -86,9 +87,26 @@ | ||
86 | }); | 87 | }); |
87 | 88 | ||
88 | save.on("click", function () { | 89 | save.on("click", function () { |
89 | - var field = form.find('.meta'); | ||
90 | - field.val(datetime.data('date')); | ||
91 | - console.log(form.serialize()); | 90 | + var meta = datetime.data('date'), |
91 | + url = form.attr('action'), | ||
92 | + method = form.attr('method'), | ||
93 | + token = form.find('input[name="csrfmiddlewaretoken"]').val(), | ||
94 | + notification = form.find('input[name="id"]').val(); | ||
95 | + | ||
96 | + $.ajax({ | ||
97 | + url: url, | ||
98 | + method: method, | ||
99 | + data: {'csrfmiddlewaretoken': token, 'meta': meta, 'id': notification}, | ||
100 | + dataType: 'json', | ||
101 | + success: function (response) { | ||
102 | + if (response.error) { | ||
103 | + alertify.error(response.message); | ||
104 | + } else { | ||
105 | + alertify.success(response.message); | ||
106 | + popover.popover('hide'); | ||
107 | + } | ||
108 | + } | ||
109 | + }); | ||
92 | }); | 110 | }); |
93 | } | 111 | } |
94 | }).on('hide.bs.popover', function (e) { | 112 | }).on('hide.bs.popover', function (e) { |
notifications/templatetags/notification_filters.py
1 | from django import template | 1 | from django import template |
2 | from datetime import datetime | 2 | from datetime import datetime |
3 | +from django.utils import timezone, formats | ||
3 | from django.utils.translation import ugettext_lazy as _ | 4 | from django.utils.translation import ugettext_lazy as _ |
4 | 5 | ||
5 | from notifications.utils import get_resource_users | 6 | from notifications.utils import get_resource_users |
@@ -87,4 +88,20 @@ def order_href(request, column): | @@ -87,4 +88,20 @@ def order_href(request, column): | ||
87 | if len(getvars) > 0: | 88 | if len(getvars) > 0: |
88 | params = '&%s' % getvars.urlencode() | 89 | params = '&%s' % getvars.urlencode() |
89 | 90 | ||
90 | - return "?order_by=" + order_href + params | ||
91 | \ No newline at end of file | 91 | \ No newline at end of file |
92 | + return "?order_by=" + order_href + params | ||
93 | + | ||
94 | +@register.filter(name = 'observation') | ||
95 | +def observation(notification): | ||
96 | + msg = '' | ||
97 | + | ||
98 | + if notification.level == 1: | ||
99 | + if notification.meta: | ||
100 | + msg = _('Goal defined to task realization: %s')%(formats.date_format(notification.meta, "SHORT_DATETIME_FORMAT")) | ||
101 | + elif notification.level == 2: | ||
102 | + if notification.meta: | ||
103 | + if notification.meta < timezone.now(): | ||
104 | + msg = _('Goal defined to task realization: %s')%(formats.date_format(notification.meta, "SHORT_DATETIME_FORMAT")) | ||
105 | + else: | ||
106 | + msg = _('New goal defined to task realization: %s')%(formats.date_format(notification.meta, "SHORT_DATETIME_FORMAT")) | ||
107 | + | ||
108 | + return msg | ||
92 | \ No newline at end of file | 109 | \ No newline at end of file |
notifications/urls.py
@@ -2,6 +2,7 @@ from django.conf.urls import url | @@ -2,6 +2,7 @@ from django.conf.urls import url | ||
2 | from . import views | 2 | from . import views |
3 | 3 | ||
4 | urlpatterns = [ | 4 | urlpatterns = [ |
5 | + url(r'^set_goal/$', views.set_goal, name='set_goal'), | ||
5 | url(r'^(?P<slug>[\w_-]+)/$', views.SubjectNotifications.as_view(), name='view'), | 6 | url(r'^(?P<slug>[\w_-]+)/$', views.SubjectNotifications.as_view(), name='view'), |
6 | url(r'^(?P<slug>[\w_-]+)/history/$', views.SubjectHistory.as_view(), name='history'), | 7 | url(r'^(?P<slug>[\w_-]+)/history/$', views.SubjectHistory.as_view(), name='history'), |
7 | ] | 8 | ] |
8 | \ No newline at end of file | 9 | \ No newline at end of file |
notifications/views.py
@@ -4,9 +4,13 @@ from django.contrib import messages | @@ -4,9 +4,13 @@ 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.contrib.auth.decorators import login_required | ||
8 | +from django.http import JsonResponse | ||
7 | from django.db.models import Q | 9 | from django.db.models import Q |
8 | 10 | ||
11 | +from dateutil import parser | ||
9 | from datetime import datetime | 12 | from datetime import datetime |
13 | +from django.utils import formats, timezone | ||
10 | 14 | ||
11 | from amadeus.permissions import has_subject_view_permissions | 15 | from amadeus.permissions import has_subject_view_permissions |
12 | 16 | ||
@@ -104,4 +108,39 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView): | @@ -104,4 +108,39 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView): | ||
104 | context['total'] = self.total | 108 | context['total'] = self.total |
105 | context['rows'] = self.num_rows | 109 | context['rows'] = self.num_rows |
106 | 110 | ||
107 | - return context | ||
108 | \ No newline at end of file | 111 | \ No newline at end of file |
112 | + return context | ||
113 | + | ||
114 | +@login_required | ||
115 | +def set_goal(request): | ||
116 | + if request.method == "POST" and request.is_ajax(): | ||
117 | + meta = request.POST.get('meta', None) | ||
118 | + | ||
119 | + if not meta: | ||
120 | + return JsonResponse({'error': True, 'message': _('No goal date received')}) | ||
121 | + | ||
122 | + meta = parser.parse(meta) | ||
123 | + | ||
124 | + notify_id = request.POST.get('id', None) | ||
125 | + | ||
126 | + if not notify_id: | ||
127 | + return JsonResponse({'error': True, 'message': _('Could not identify the notification')}) | ||
128 | + | ||
129 | + notification = get_object_or_404(Notification, id = notify_id) | ||
130 | + | ||
131 | + meta = timezone.make_aware(meta, timezone.get_current_timezone()) | ||
132 | + | ||
133 | + if meta < timezone.now(): | ||
134 | + return JsonResponse({'error': True, 'message': _("The goal date should be equal or after today's date")}) | ||
135 | + | ||
136 | + if meta.date() > notification.task.resource.topic.subject.end_date: | ||
137 | + return JsonResponse({'error': True, 'message': _("The goal date should be equal or before subject's date")}) | ||
138 | + | ||
139 | + notification.meta = meta | ||
140 | + notification.save() | ||
141 | + | ||
142 | + if notification.level == 2: | ||
143 | + message = _('Your new goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) | ||
144 | + else: | ||
145 | + message = _('Your goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) | ||
146 | + | ||
147 | + return JsonResponse({'error': False, 'message': message}) | ||
109 | \ No newline at end of file | 148 | \ No newline at end of file |
requirements.txt
@@ -33,4 +33,5 @@ validators==0.11.0 | @@ -33,4 +33,5 @@ validators==0.11.0 | ||
33 | Werkzeug==0.11.11 | 33 | Werkzeug==0.11.11 |
34 | whitenoise==3.2.2 | 34 | whitenoise==3.2.2 |
35 | django-session-security==2.4.0 | 35 | django-session-security==2.4.0 |
36 | -django-cron==0.5.0 | ||
37 | \ No newline at end of file | 36 | \ No newline at end of file |
37 | +django-cron==0.5.0 | ||
38 | +python-dateutil==2.6.0 | ||
38 | \ No newline at end of file | 39 | \ No newline at end of file |