diff --git a/notifications/templates/notifications/_history.html b/notifications/templates/notifications/_history.html index 63fd604..a9bb6c3 100644 --- a/notifications/templates/notifications/_history.html +++ b/notifications/templates/notifications/_history.html @@ -57,8 +57,7 @@ {{ notification.task.get_action_display }} {{ notification.task.end_date|date:"SHORT_DATE_FORMAT"|default:_('Not Informed') }} {{ notification.level|warning_msg }} - - + {{ notification|observation }} {% endfor %} {% else %} diff --git a/notifications/templates/notifications/_view.html b/notifications/templates/notifications/_view.html index 1ae9501..5cad20f 100644 --- a/notifications/templates/notifications/_view.html +++ b/notifications/templates/notifications/_view.html @@ -62,14 +62,13 @@
-
+ {% csrf_token %}
-
diff --git a/notifications/templates/notifications/subject.html b/notifications/templates/notifications/subject.html index 30fa505..5480d43 100644 --- a/notifications/templates/notifications/subject.html +++ b/notifications/templates/notifications/subject.html @@ -76,6 +76,7 @@ } datetime.datetimepicker({ + format: "YYYY-MM-DD HH:mm", locale: locale, inline: true, sideBySide: false @@ -86,9 +87,26 @@ }); save.on("click", function () { - var field = form.find('.meta'); - field.val(datetime.data('date')); - console.log(form.serialize()); + var meta = datetime.data('date'), + url = form.attr('action'), + method = form.attr('method'), + token = form.find('input[name="csrfmiddlewaretoken"]').val(), + notification = form.find('input[name="id"]').val(); + + $.ajax({ + url: url, + method: method, + data: {'csrfmiddlewaretoken': token, 'meta': meta, 'id': notification}, + dataType: 'json', + success: function (response) { + if (response.error) { + alertify.error(response.message); + } else { + alertify.success(response.message); + popover.popover('hide'); + } + } + }); }); } }).on('hide.bs.popover', function (e) { diff --git a/notifications/templatetags/notification_filters.py b/notifications/templatetags/notification_filters.py index 0323a57..b972395 100644 --- a/notifications/templatetags/notification_filters.py +++ b/notifications/templatetags/notification_filters.py @@ -1,5 +1,6 @@ from django import template from datetime import datetime +from django.utils import timezone, formats from django.utils.translation import ugettext_lazy as _ from notifications.utils import get_resource_users @@ -87,4 +88,20 @@ def order_href(request, column): if len(getvars) > 0: params = '&%s' % getvars.urlencode() - return "?order_by=" + order_href + params \ No newline at end of file + return "?order_by=" + order_href + params + +@register.filter(name = 'observation') +def observation(notification): + msg = '' + + if notification.level == 1: + if notification.meta: + msg = _('Goal defined to task realization: %s')%(formats.date_format(notification.meta, "SHORT_DATETIME_FORMAT")) + elif notification.level == 2: + if notification.meta: + if notification.meta < timezone.now(): + msg = _('Goal defined to task realization: %s')%(formats.date_format(notification.meta, "SHORT_DATETIME_FORMAT")) + else: + msg = _('New goal defined to task realization: %s')%(formats.date_format(notification.meta, "SHORT_DATETIME_FORMAT")) + + return msg \ No newline at end of file diff --git a/notifications/urls.py b/notifications/urls.py index c021cb6..870e24e 100644 --- a/notifications/urls.py +++ b/notifications/urls.py @@ -2,6 +2,7 @@ from django.conf.urls import url from . import views urlpatterns = [ + url(r'^set_goal/$', views.set_goal, name='set_goal'), url(r'^(?P[\w_-]+)/$', views.SubjectNotifications.as_view(), name='view'), url(r'^(?P[\w_-]+)/history/$', views.SubjectHistory.as_view(), name='history'), ] \ No newline at end of file diff --git a/notifications/views.py b/notifications/views.py index 292fd3e..61435f1 100644 --- a/notifications/views.py +++ b/notifications/views.py @@ -4,9 +4,13 @@ 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.contrib.auth.decorators import login_required +from django.http import JsonResponse from django.db.models import Q +from dateutil import parser from datetime import datetime +from django.utils import formats, timezone from amadeus.permissions import has_subject_view_permissions @@ -104,4 +108,39 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView): context['total'] = self.total context['rows'] = self.num_rows - return context \ No newline at end of file + return context + +@login_required +def set_goal(request): + if request.method == "POST" and request.is_ajax(): + meta = request.POST.get('meta', None) + + if not meta: + return JsonResponse({'error': True, 'message': _('No goal date received')}) + + meta = parser.parse(meta) + + notify_id = request.POST.get('id', None) + + if not notify_id: + return JsonResponse({'error': True, 'message': _('Could not identify the notification')}) + + notification = get_object_or_404(Notification, id = notify_id) + + meta = timezone.make_aware(meta, timezone.get_current_timezone()) + + if meta < timezone.now(): + return JsonResponse({'error': True, 'message': _("The goal date should be equal or after today's date")}) + + if meta.date() > notification.task.resource.topic.subject.end_date: + return JsonResponse({'error': True, 'message': _("The goal date should be equal or before subject's date")}) + + notification.meta = meta + notification.save() + + if notification.level == 2: + message = _('Your new goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) + else: + message = _('Your goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) + + return JsonResponse({'error': False, 'message': message}) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index b351794..bf40d05 100644 --- a/requirements.txt +++ b/requirements.txt @@ -33,4 +33,5 @@ validators==0.11.0 Werkzeug==0.11.11 whitenoise==3.2.2 django-session-security==2.4.0 -django-cron==0.5.0 \ No newline at end of file +django-cron==0.5.0 +python-dateutil==2.6.0 \ No newline at end of file -- libgit2 0.21.2