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 | 57 | <td>{{ notification.task.get_action_display }}</td> |
58 | 58 | <td>{{ notification.task.end_date|date:"SHORT_DATE_FORMAT"|default:_('Not Informed') }}</td> |
59 | 59 | <td>{{ notification.level|warning_msg }}</td> |
60 | - <td> | |
61 | - </td> | |
60 | + <td>{{ notification|observation }}</td> | |
62 | 61 | </tr> |
63 | 62 | {% endfor %} |
64 | 63 | {% else %} | ... | ... |
notifications/templates/notifications/_view.html
... | ... | @@ -62,14 +62,13 @@ |
62 | 62 | |
63 | 63 | <div class="popover"> |
64 | 64 | <div class="popover-content"> |
65 | - <form role="form" method="post"> | |
65 | + <form action="{% url 'notifications:set_goal' %}" role="form" method="post"> | |
66 | 66 | {% csrf_token %} |
67 | 67 | <div style="overflow:hidden;"> |
68 | 68 | <div class="form-group"> |
69 | 69 | <div class="row"> |
70 | 70 | <div class="col-md-12"> |
71 | 71 | <div class="datetimepicker"></div> |
72 | - <input type="hidden" class="meta" name="meta" /> | |
73 | 72 | <input type="hidden" name="id" value="{{ notification.id }}"> |
74 | 73 | </div> |
75 | 74 | </div> | ... | ... |
notifications/templates/notifications/subject.html
... | ... | @@ -76,6 +76,7 @@ |
76 | 76 | } |
77 | 77 | |
78 | 78 | datetime.datetimepicker({ |
79 | + format: "YYYY-MM-DD HH:mm", | |
79 | 80 | locale: locale, |
80 | 81 | inline: true, |
81 | 82 | sideBySide: false |
... | ... | @@ -86,9 +87,26 @@ |
86 | 87 | }); |
87 | 88 | |
88 | 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 | 112 | }).on('hide.bs.popover', function (e) { | ... | ... |
notifications/templatetags/notification_filters.py
1 | 1 | from django import template |
2 | 2 | from datetime import datetime |
3 | +from django.utils import timezone, formats | |
3 | 4 | from django.utils.translation import ugettext_lazy as _ |
4 | 5 | |
5 | 6 | from notifications.utils import get_resource_users |
... | ... | @@ -87,4 +88,20 @@ def order_href(request, column): |
87 | 88 | if len(getvars) > 0: |
88 | 89 | params = '&%s' % getvars.urlencode() |
89 | 90 | |
90 | - return "?order_by=" + order_href + params | |
91 | 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 | 109 | \ No newline at end of file | ... | ... |
notifications/urls.py
... | ... | @@ -2,6 +2,7 @@ from django.conf.urls import url |
2 | 2 | from . import views |
3 | 3 | |
4 | 4 | urlpatterns = [ |
5 | + url(r'^set_goal/$', views.set_goal, name='set_goal'), | |
5 | 6 | url(r'^(?P<slug>[\w_-]+)/$', views.SubjectNotifications.as_view(), name='view'), |
6 | 7 | url(r'^(?P<slug>[\w_-]+)/history/$', views.SubjectHistory.as_view(), name='history'), |
7 | 8 | ] |
8 | 9 | \ No newline at end of file | ... | ... |
notifications/views.py
... | ... | @@ -4,9 +4,13 @@ from django.contrib import messages |
4 | 4 | from django.core.urlresolvers import reverse, reverse_lazy |
5 | 5 | from django.utils.translation import ugettext_lazy as _ |
6 | 6 | from django.contrib.auth.mixins import LoginRequiredMixin |
7 | +from django.contrib.auth.decorators import login_required | |
8 | +from django.http import JsonResponse | |
7 | 9 | from django.db.models import Q |
8 | 10 | |
11 | +from dateutil import parser | |
9 | 12 | from datetime import datetime |
13 | +from django.utils import formats, timezone | |
10 | 14 | |
11 | 15 | from amadeus.permissions import has_subject_view_permissions |
12 | 16 | |
... | ... | @@ -104,4 +108,39 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView): |
104 | 108 | context['total'] = self.total |
105 | 109 | context['rows'] = self.num_rows |
106 | 110 | |
107 | - return context | |
108 | 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 | 148 | \ No newline at end of file | ... | ... |
requirements.txt