Commit ae544a779ec2fe9b0c057d0ccfd3251d26b10b81
Exists in
master
and in
3 other branches
Merge branch 'refactoring' of https://github.com/amadeusproject/amadeuslms into refactoring
Showing
6 changed files
with
125 additions
and
15 deletions
Show diff stats
amadeus/static/css/base/amadeus.css
@@ -914,4 +914,14 @@ li.item .notify_badge { | @@ -914,4 +914,14 @@ li.item .notify_badge { | ||
914 | 914 | ||
915 | .no_button:focus, .no_button:active:focus, .no_button.active:focus, .no_button.focus, .no_button:active.focus, .no_button.active.focus { | 915 | .no_button:focus, .no_button:active:focus, .no_button.active:focus, .no_button.focus, .no_button:active.focus, .no_button.active.focus { |
916 | outline: none; | 916 | outline: none; |
917 | +} | ||
918 | + | ||
919 | +.history-header { | ||
920 | + line-height: 1.8; | ||
921 | +} | ||
922 | + | ||
923 | +.history-control-label { | ||
924 | + padding-right: 0px; | ||
925 | + font-size: 16px !important; | ||
926 | + margin: 7px 0 0 0 !important; | ||
917 | } | 927 | } |
918 | \ No newline at end of file | 928 | \ No newline at end of file |
@@ -0,0 +1,47 @@ | @@ -0,0 +1,47 @@ | ||
1 | +{% load i18n notification_filters pagination %} | ||
2 | + | ||
3 | +<div class="row"> | ||
4 | + <div class="col-md-12"> | ||
5 | + <div class="col-md-offset-3 col-md-5"> | ||
6 | + <h4 class="text-center history-header">{{ rows }} {% trans 'rows' %}</h4> | ||
7 | + </div> | ||
8 | + <div class="col-md-4"> | ||
9 | + <form action="" method="GET" class="form-horizontal"> | ||
10 | + <div class="form-group"> | ||
11 | + <label class="col-md-4 history-control-label control-label">{% trans 'Search' %}:</label> | ||
12 | + <div class="col-md-8"> | ||
13 | + <input type="text" class="form-control" name="search" placeholder="{% trans 'Search...' %}" /> | ||
14 | + </div> | ||
15 | + </div> | ||
16 | + </form> | ||
17 | + </div> | ||
18 | + <table class="table table-striped table-bordered"> | ||
19 | + <thead> | ||
20 | + <th>{% trans 'Date' %}</th> | ||
21 | + <th>{% trans 'Resource' %}</th> | ||
22 | + <th>{% trans 'Task' %}</th> | ||
23 | + <th>{% trans 'Final Date' %}</th> | ||
24 | + <th>{% trans 'Notification' %}</th> | ||
25 | + <th>{% trans 'Observation' %}</th> | ||
26 | + </thead> | ||
27 | + <tbody> | ||
28 | + {% if rows > 0 %} | ||
29 | + {% for notification in notifications %} | ||
30 | + <tr> | ||
31 | + <td>{{ notification.creation_date|date:"SHORT_DATE_FORMAT" }}</td> | ||
32 | + <td>{{ notification.task.resource }}</td> | ||
33 | + <td>{{ notification.task.get_action_display }}</td> | ||
34 | + <td>{{ notification.task.end_date|date:"SHORT_DATE_FORMAT"|default:_('Not Informed') }}</td> | ||
35 | + <td>{{ notification.level|warning_msg }}</td> | ||
36 | + <td> | ||
37 | + </td> | ||
38 | + </tr> | ||
39 | + {% endfor %} | ||
40 | + {% else %} | ||
41 | + {% endif %} | ||
42 | + </tbody> | ||
43 | + </table> | ||
44 | + | ||
45 | + {% pagination request paginator page_obj %} | ||
46 | + </div> | ||
47 | +</div> | ||
0 | \ No newline at end of file | 48 | \ No newline at end of file |
notifications/templates/notifications/subject.html
@@ -28,23 +28,27 @@ | @@ -28,23 +28,27 @@ | ||
28 | <div id="{{subject.slug}}" class="panel-collapse in collapse pendencies-content"> | 28 | <div id="{{subject.slug}}" class="panel-collapse in collapse pendencies-content"> |
29 | <div id="core-subjects-options-div"> | 29 | <div id="core-subjects-options-div"> |
30 | <ul class="core-subjects-options"> | 30 | <ul class="core-subjects-options"> |
31 | - <a href="{% url 'notifications:view' subject.slug %}"><li class="active">{% trans "Actual Pendencies" %} ({{ notifications.count }})</li></a> | ||
32 | - <a href="" ><li>{% trans "Notifications History" %}</li></a> | 31 | + <a href="{% url 'notifications:view' subject.slug %}"><li {% if not history %} class="active" {% endif %}>{% trans "Actual Pendencies" %} ({{ total }})</li></a> |
32 | + <a href="{% url 'notifications:history' subject.slug %}" ><li {% if history %} class="active" {% endif %}>{% trans "Notifications History" %}</li></a> | ||
33 | </ul> | 33 | </ul> |
34 | </div> | 34 | </div> |
35 | 35 | ||
36 | - {% if notifications.count > 0 %} | ||
37 | - {% for notification in notifications %} | ||
38 | - {% include 'notifications/_view.html' %} | ||
39 | - {% endfor %} | 36 | + {% if not history %} |
37 | + {% if notifications.count > 0 %} | ||
38 | + {% for notification in notifications %} | ||
39 | + {% include 'notifications/_view.html' %} | ||
40 | + {% endfor %} | ||
40 | 41 | ||
41 | - {% pagination request paginator page_obj %} | ||
42 | - {% else %} | ||
43 | - <div class="text-center no-subjects"> | ||
44 | - <i class="fa fa-exclamation-triangle"></i> | ||
45 | - <h4>{% trans 'You do not posses any pendency in this subject' %}</h4> | ||
46 | - </div> | ||
47 | - {% endif %} | 42 | + {% pagination request paginator page_obj %} |
43 | + {% else %} | ||
44 | + <div class="text-center no-subjects"> | ||
45 | + <i class="fa fa-exclamation-triangle"></i> | ||
46 | + <h4>{% trans 'You do not posses any pendency in this subject' %}</h4> | ||
47 | + </div> | ||
48 | + {% endif %} | ||
49 | + {% else %} | ||
50 | + {% include 'notifications/_history.html' %} | ||
51 | + {% endif %} | ||
48 | </div> | 52 | </div> |
49 | </div> | 53 | </div> |
50 | {% endblock %} | 54 | {% endblock %} |
51 | \ No newline at end of file | 55 | \ No newline at end of file |
notifications/urls.py
@@ -3,4 +3,5 @@ from . import views | @@ -3,4 +3,5 @@ from . import views | ||
3 | 3 | ||
4 | urlpatterns = [ | 4 | urlpatterns = [ |
5 | url(r'^(?P<slug>[\w_-]+)/$', views.SubjectNotifications.as_view(), name='view'), | 5 | url(r'^(?P<slug>[\w_-]+)/$', views.SubjectNotifications.as_view(), name='view'), |
6 | + url(r'^(?P<slug>[\w_-]+)/history/$', views.SubjectHistory.as_view(), name='history'), | ||
6 | ] | 7 | ] |
7 | \ No newline at end of file | 8 | \ No newline at end of file |
notifications/views.py
@@ -20,6 +20,7 @@ class SubjectNotifications(LoginRequiredMixin, generic.ListView): | @@ -20,6 +20,7 @@ class SubjectNotifications(LoginRequiredMixin, generic.ListView): | ||
20 | context_object_name = 'notifications' | 20 | context_object_name = 'notifications' |
21 | template_name = 'notifications/subject.html' | 21 | template_name = 'notifications/subject.html' |
22 | paginate_by = 10 | 22 | paginate_by = 10 |
23 | + total = 0 | ||
23 | 24 | ||
24 | def dispatch(self, request, *args, **kwargs): | 25 | def dispatch(self, request, *args, **kwargs): |
25 | slug = self.kwargs.get('slug', '') | 26 | slug = self.kwargs.get('slug', '') |
@@ -36,6 +37,8 @@ class SubjectNotifications(LoginRequiredMixin, generic.ListView): | @@ -36,6 +37,8 @@ class SubjectNotifications(LoginRequiredMixin, generic.ListView): | ||
36 | 37 | ||
37 | notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject, creation_date = datetime.now()) | 38 | notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject, creation_date = datetime.now()) |
38 | 39 | ||
40 | + self.total = notifications.count() | ||
41 | + | ||
39 | return notifications | 42 | return notifications |
40 | 43 | ||
41 | def get_context_data(self, **kwargs): | 44 | def get_context_data(self, **kwargs): |
@@ -46,5 +49,50 @@ class SubjectNotifications(LoginRequiredMixin, generic.ListView): | @@ -46,5 +49,50 @@ class SubjectNotifications(LoginRequiredMixin, generic.ListView): | ||
46 | 49 | ||
47 | context['title'] = _('%s - Pendencies')%(subject.name) | 50 | context['title'] = _('%s - Pendencies')%(subject.name) |
48 | context['subject'] = subject | 51 | context['subject'] = subject |
52 | + context['total'] = self.total | ||
49 | 53 | ||
50 | return context | 54 | return context |
55 | + | ||
56 | +class SubjectHistory(LoginRequiredMixin, generic.ListView): | ||
57 | + login_url = reverse_lazy("users:login") | ||
58 | + redirect_field_name = 'next' | ||
59 | + | ||
60 | + context_object_name = 'notifications' | ||
61 | + template_name = 'notifications/subject.html' | ||
62 | + paginate_by = 10 | ||
63 | + total = 0 | ||
64 | + num_rows = 0 | ||
65 | + | ||
66 | + def dispatch(self, request, *args, **kwargs): | ||
67 | + slug = self.kwargs.get('slug', '') | ||
68 | + subject = get_object_or_404(Subject, slug = slug) | ||
69 | + | ||
70 | + if not has_subject_view_permissions(request.user, subject): | ||
71 | + return redirect(reverse_lazy('subjects:home')) | ||
72 | + | ||
73 | + return super(SubjectHistory, self).dispatch(request, *args, **kwargs) | ||
74 | + | ||
75 | + def get_queryset(self): | ||
76 | + slug = self.kwargs.get('slug', '') | ||
77 | + subject = get_object_or_404(Subject, slug = slug) | ||
78 | + | ||
79 | + notifications = Notification.objects.filter(user = self.request.user, task__resource__topic__subject = subject).order_by("-creation_date") | ||
80 | + | ||
81 | + self.total = notifications.filter(creation_date = datetime.now()).count() | ||
82 | + self.num_rows = notifications.count() | ||
83 | + | ||
84 | + return notifications | ||
85 | + | ||
86 | + def get_context_data(self, **kwargs): | ||
87 | + context = super(SubjectHistory, self).get_context_data(**kwargs) | ||
88 | + | ||
89 | + slug = self.kwargs.get('slug', '') | ||
90 | + subject = get_object_or_404(Subject, slug = slug) | ||
91 | + | ||
92 | + context['title'] = _('%s - Pendencies')%(subject.name) | ||
93 | + context['subject'] = subject | ||
94 | + context['history'] = True | ||
95 | + context['total'] = self.total | ||
96 | + context['rows'] = self.num_rows | ||
97 | + | ||
98 | + return context | ||
51 | \ No newline at end of file | 99 | \ No newline at end of file |
pendencies/forms.py
@@ -56,7 +56,7 @@ class PendenciesForm(forms.ModelForm): | @@ -56,7 +56,7 @@ class PendenciesForm(forms.ModelForm): | ||
56 | subject = Subject.objects.get(id = subject_id) | 56 | subject = Subject.objects.get(id = subject_id) |
57 | 57 | ||
58 | if not begin_date == ValueError and begin_date: | 58 | if not begin_date == ValueError and begin_date: |
59 | - if not pend_id and begin_date.date() < datetime.datetime.today().date(): | 59 | + if not self.instance.id and begin_date.date() < datetime.datetime.today().date(): |
60 | self.add_error('begin_date', _("This input should be filled with a date equal or after today's date.")) | 60 | self.add_error('begin_date', _("This input should be filled with a date equal or after today's date.")) |
61 | 61 | ||
62 | if begin_date.date() < subject.init_date: | 62 | if begin_date.date() < subject.init_date: |
@@ -66,7 +66,7 @@ class PendenciesForm(forms.ModelForm): | @@ -66,7 +66,7 @@ class PendenciesForm(forms.ModelForm): | ||
66 | self.add_error('begin_date', _('This input should be filled with a date equal or after the subject end date.')) | 66 | self.add_error('begin_date', _('This input should be filled with a date equal or after the subject end date.')) |
67 | 67 | ||
68 | if not end_date == ValueError and end_date: | 68 | if not end_date == ValueError and end_date: |
69 | - if not pend_id and end_date.date() < datetime.datetime.today().date(): | 69 | + if not self.instance.id and end_date.date() < datetime.datetime.today().date(): |
70 | self.add_error('end_date', _("This input should be filled with a date equal or after today's date.")) | 70 | self.add_error('end_date', _("This input should be filled with a date equal or after today's date.")) |
71 | 71 | ||
72 | if end_date.date() < subject.init_date: | 72 | if end_date.date() < subject.init_date: |