From 07193e64de2ee9ab1e2642c6ff8b01ebbc0c5d60 Mon Sep 17 00:00:00 2001 From: Zambom Date: Fri, 27 Jan 2017 21:31:20 -0200 Subject: [PATCH] Adding subject notifications view page --- amadeus/static/css/base/amadeus.css | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ amadeus/static/css/themes/green.css | 29 +++++++++++++++++++++++++++++ amadeus/templates/pagination.html | 2 +- amadeus/urls.py | 1 + notifications/models.py | 3 +++ notifications/templates/notifications/_view.html | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ notifications/templates/notifications/subject.html | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ notifications/templatetags/__init__.py | 0 notifications/templatetags/notification_filters.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ notifications/urls.py | 6 ++++++ notifications/views.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- subjects/templates/subjects/subject_card.html | 2 +- subjects/templates/subjects/view.html | 2 +- subjects/views.py | 2 +- topics/templates/topics/list.html | 2 +- 15 files changed, 307 insertions(+), 7 deletions(-) create mode 100644 notifications/templates/notifications/_view.html create mode 100644 notifications/templates/notifications/subject.html create mode 100644 notifications/templatetags/__init__.py create mode 100644 notifications/templatetags/notification_filters.py create mode 100644 notifications/urls.py diff --git a/amadeus/static/css/base/amadeus.css b/amadeus/static/css/base/amadeus.css index 7b3b322..06c0ff9 100755 --- a/amadeus/static/css/base/amadeus.css +++ b/amadeus/static/css/base/amadeus.css @@ -142,6 +142,10 @@ a:focus { font-size: 15px; } +.pendencies-content { + padding: 10px; +} + .category-panel-content { padding:10px; } @@ -834,4 +838,54 @@ li.item .notify_badge { font-size: 0.9rem; border-radius: 50%; padding: 0px; +} + +.pendency { + border: 1px solid; + padding-left: 10px; + padding-top: 7px; + margin-bottom: 15px; +} + +.pendency .breadcrumb { + padding-left: 0px; + margin-bottom: 0px; +} + +.pendency h4 { + margin: 0px; + font-size: 22px; + font-weight: 700; +} + +.pendency p { + margin-bottom: 3px; +} + +.pendency .alert { + padding-top: 5px; + padding-bottom: 5px; + font-weight: 700; +} + +.pendency .alert span { + position: relative; + top: -7px; + padding-left: 10px; +} + +.pendency .alert i { + font-size: 35px; +} + +.alert-low { + opacity: 0.5; +} + +.no_button { + cursor: initial; +} + +.no_button:focus, .no_button:active:focus, .no_button.active:focus, .no_button.focus, .no_button:active.focus, .no_button.active.focus { + outline: none; } \ No newline at end of file diff --git a/amadeus/static/css/themes/green.css b/amadeus/static/css/themes/green.css index 18fa676..5c522a3 100644 --- a/amadeus/static/css/themes/green.css +++ b/amadeus/static/css/themes/green.css @@ -85,6 +85,14 @@ a, a:focus, a:hover { color: #F5F5F5; } +.pendencies-content { + background: #FFFFFF; +} + +.pendencies-content .core-subjects-options li { + background: #F5F5F5; +} + .category-header i { color: white; } @@ -426,6 +434,27 @@ a.add-row { color: #F5F5F5 !important; } +.pendency { + border-color: #CCCCCC; +} + +.pendency .breadcrumb { + background-color: #FFFFFF; +} + +.pendency .meta { + color: #FF0000; +} + +.alert-low, .alert-medium { + background-color: #FFA500; + color: #FFFFFF; +} + +.no_button:hover, .no_button:focus, .no_button:active { + background-color: initial !important; +} + @media(max-width: 768px) { .navbar .navbar-nav .dropdown .dropdown-menu li > a { color: #333333 !important; diff --git a/amadeus/templates/pagination.html b/amadeus/templates/pagination.html index f18d0b5..1a76e6a 100644 --- a/amadeus/templates/pagination.html +++ b/amadeus/templates/pagination.html @@ -1,5 +1,5 @@ {% if paginator.count > 0 %} -
+
    {% if page_obj.has_previous %} diff --git a/amadeus/urls.py b/amadeus/urls.py index 6583efb..0e91d7d 100644 --- a/amadeus/urls.py +++ b/amadeus/urls.py @@ -34,6 +34,7 @@ urlpatterns = [ url(r'^mailsender/', include('mailsender.urls', namespace = 'mailsender')), url(r'^security/', include('security.urls', namespace = 'security')), url(r'^themes/', include('themes.urls', namespace = 'themes')), + url(r'^notifications/', include('notifications.urls', namespace = 'notifications')), #API url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), #S3Direct diff --git a/notifications/models.py b/notifications/models.py index 1b034ec..8494e04 100644 --- a/notifications/models.py +++ b/notifications/models.py @@ -11,3 +11,6 @@ class Notification(models.Model): level = models.IntegerField(_('Type'), choices = ((1, _('Type 1-A')), (2, _('Type 1-B')), (3, _('Type 2')), (4, _('Type 3')))) viewed = models.BooleanField(_('Visualized'), default = False) creation_date = models.DateField(_('Creation Date'), auto_now_add = True) + + def __str__(self): + return self.task.get_action_display() + " " + str(self.task.resource) diff --git a/notifications/templates/notifications/_view.html b/notifications/templates/notifications/_view.html new file mode 100644 index 0000000..965312b --- /dev/null +++ b/notifications/templates/notifications/_view.html @@ -0,0 +1,65 @@ +{% load i18n notification_filters %} + +
    +
    +
    + +
    +
    +

    {{ notification }}

    +

    {% trans 'Final Date/Time' %}: {{ notification.task.end_date|default:_('Not Informed') }}

    + + {% if notification.level == 2 %} +

    {% trans 'Your goal was to realize this in' %}: {{ notification.meta }}

    + {% elif notification.level == 4 %} +

    {% trans 'Task finished in' %}: {{ notification.task.limit_date }}

    + {% endif %} + + {{ notification|done_percent }}% {% trans 'of the participants already realized this task.' %} +
    +
    +
    + + {{ notification.level|warning_msg }} +
    +
    +
    + +
    +
    +
    \ No newline at end of file diff --git a/notifications/templates/notifications/subject.html b/notifications/templates/notifications/subject.html new file mode 100644 index 0000000..d081a19 --- /dev/null +++ b/notifications/templates/notifications/subject.html @@ -0,0 +1,50 @@ +{% extends 'subjects/view.html' %} + +{% load static i18n pagination permissions_tags subject_counter %} +{% load django_bootstrap_breadcrumbs %} + +{% block breadcrumbs %} + {{ block.super }} + + {% breadcrumb 'Pendencies' 'notifications:view' subject.slug %} +{% endblock %} + +{% block content %} + {% if subject.visible %} +
    +
    + {% else %} +
    +
    + {% endif %} +
    +
    +

    + {% trans 'Pendencies' %} +

    +
    +
    +
    +
    + + + {% if notifications.count > 0 %} + {% for notification in notifications %} + {% include 'notifications/_view.html' %} + {% endfor %} + + {% pagination request paginator page_obj %} + {% else %} +
    + +

    {% trans 'You do not posses any pendency in this subject' %}

    +
    + {% endif %} +
    +
    +{% endblock %} \ No newline at end of file diff --git a/notifications/templatetags/__init__.py b/notifications/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/notifications/templatetags/__init__.py diff --git a/notifications/templatetags/notification_filters.py b/notifications/templatetags/notification_filters.py new file mode 100644 index 0000000..b552bd3 --- /dev/null +++ b/notifications/templatetags/notification_filters.py @@ -0,0 +1,45 @@ +from django import template +from datetime import datetime +from django.utils.translation import ugettext_lazy as _ + +from notifications.utils import get_resource_users +from notifications.models import Notification + +register = template.Library() + +@register.filter(name = 'warning_class') +def warning_class(level): + if level == 1: + class_name = "alert-low" + elif level == 2: + class_name = "alert-low" + elif level == 3: + class_name = "alert-medium" + else: + class_name = "alert-danger" + + return class_name + +@register.filter(name = 'warning_msg') +def warning_msg(level): + if level == 1: + msg = _('You still did not realize this task') + elif level == 2: + msg = _('You still did not realize this task') + elif level == 3: + msg = _('This task is late') + else: + msg = _('You miss this task') + + return msg + +@register.filter(name = 'done_percent') +def done_percent(notification): + users = get_resource_users(notification.task.resource) + notified = Notification.objects.filter(user__in = users.values_list('id', flat = True), creation_date = datetime.now(), task = notification.task).count() + + number_users = users.count() + + not_done = (notified * 100) / number_users + + return 100 - not_done \ No newline at end of file diff --git a/notifications/urls.py b/notifications/urls.py new file mode 100644 index 0000000..953f6b3 --- /dev/null +++ b/notifications/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls import url +from . import views + +urlpatterns = [ + url(r'^(?P[\w_-]+)/$', views.SubjectNotifications.as_view(), name='view'), +] \ No newline at end of file diff --git a/notifications/views.py b/notifications/views.py index 91ea44a..2ca992d 100644 --- a/notifications/views.py +++ b/notifications/views.py @@ -1,3 +1,50 @@ -from django.shortcuts import render +from django.shortcuts import get_object_or_404, redirect, render +from django.views import generic +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 -# Create your views here. +from datetime import datetime + +from amadeus.permissions import has_subject_view_permissions + +from subjects.models import Subject + +from .models import Notification + +class SubjectNotifications(LoginRequiredMixin, generic.ListView): + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + context_object_name = 'notifications' + template_name = 'notifications/subject.html' + paginate_by = 10 + + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('slug', '') + subject = get_object_or_404(Subject, slug = slug) + + if not has_subject_view_permissions(request.user, subject): + return redirect(reverse_lazy('subjects:home')) + + return super(SubjectNotifications, self).dispatch(request, *args, **kwargs) + + def get_queryset(self): + slug = self.kwargs.get('slug', '') + subject = get_object_or_404(Subject, slug = slug) + + notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject, creation_date = datetime.now()) + + return notifications + + def get_context_data(self, **kwargs): + context = super(SubjectNotifications, self).get_context_data(**kwargs) + + slug = self.kwargs.get('slug', '') + subject = get_object_or_404(Subject, slug = slug) + + context['title'] = _('%s - Pendencies')%(subject.name) + context['subject'] = subject + + return context diff --git a/subjects/templates/subjects/subject_card.html b/subjects/templates/subjects/subject_card.html index b1a2964..7ff6b37 100644 --- a/subjects/templates/subjects/subject_card.html +++ b/subjects/templates/subjects/subject_card.html @@ -37,7 +37,7 @@ - + {% notifies_number subject request.user %} diff --git a/subjects/templates/subjects/view.html b/subjects/templates/subjects/view.html index f9d077f..fcd7e31 100644 --- a/subjects/templates/subjects/view.html +++ b/subjects/templates/subjects/view.html @@ -56,7 +56,7 @@
{% endif %} - + {% notifies_number subject request.user %} diff --git a/subjects/views.py b/subjects/views.py index d4714b7..67207d0 100644 --- a/subjects/views.py +++ b/subjects/views.py @@ -46,7 +46,7 @@ class HomeView(LoginRequiredMixin, ListView): subjects = Subject.objects.filter(Q(students__pk=pk) | Q(professor__pk=pk) | Q(category__coordinators__pk=pk)).distinct() - self.total = len(subjects) + self.total = subjects.count() return subjects diff --git a/topics/templates/topics/list.html b/topics/templates/topics/list.html index 69a7390..600c661 100644 --- a/topics/templates/topics/list.html +++ b/topics/templates/topics/list.html @@ -34,7 +34,7 @@
-
+
-- libgit2 0.21.2