From 56956baf49f157f7216a82762fe6bdc83ce2b6b4 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Tue, 14 Mar 2017 16:51:07 +0100 Subject: [PATCH] notifications about subjects with required contact date --- smash/web/tests/test_view_notifications.py | 39 ++++++++++++++++++++++ smash/web/views.py | 25 +++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/smash/web/tests/test_view_notifications.py b/smash/web/tests/test_view_notifications.py index 2447e4a2..9a2fb73a 100644 --- a/smash/web/tests/test_view_notifications.py +++ b/smash/web/tests/test_view_notifications.py @@ -253,3 +253,42 @@ class NotificationViewTests(TestCase): notification = get_approaching_visits_for_mail_contact_count(self.user) self.assertEquals(original_notification.count, notification.count) + + def test_get_subjects_with_reminder_count(self): + original_without_visit_notification = get_subject_with_no_visit_notifications_count(self.user) + original_notification = get_subjects_with_reminder_count(self.user) + subject = create_subject() + subject.datetime_contact_reminder = get_today_midnight_date()+datetime.timedelta(days=-1) + subject.save() + + notification = get_subjects_with_reminder_count(self.user) + self.assertEquals(original_notification.count + 1, notification.count) + + notification = get_subject_with_no_visit_notifications_count(self.user) + self.assertEquals(original_without_visit_notification.count, notification.count) + + def test_get_subjects_with_reminder_count_2(self): + original_without_visit_notification = get_subject_with_no_visit_notifications_count(self.user) + original_notification = get_subjects_with_reminder_count(self.user) + subject = create_subject() + subject.datetime_contact_reminder = get_today_midnight_date()+datetime.timedelta(hours=23) + subject.save() + + notification = get_subjects_with_reminder_count(self.user) + self.assertEquals(original_notification.count + 1, notification.count) + + notification = get_subject_with_no_visit_notifications_count(self.user) + self.assertEquals(original_without_visit_notification.count, notification.count) + + def test_get_subjects_with_reminder_count_3(self): + original_without_visit_notification = get_subject_with_no_visit_notifications_count(self.user) + original_notification = get_subjects_with_reminder_count(self.user) + subject = create_subject() + subject.datetime_contact_reminder = get_today_midnight_date()+datetime.timedelta(days=2) + subject.save() + + notification = get_subjects_with_reminder_count(self.user) + self.assertEquals(original_notification.count, notification.count) + + notification = get_subject_with_no_visit_notifications_count(self.user) + self.assertEquals(original_without_visit_notification.count, notification.count) diff --git a/smash/web/views.py b/smash/web/views.py index ba5eeae2..eb89a75b 100644 --- a/smash/web/views.py +++ b/smash/web/views.py @@ -120,10 +120,31 @@ def get_subjects_with_no_visit(user): dead=False, resigned=False, my_count=0, - default_location__in = get_filter_locations(user) + default_location__in = get_filter_locations(user), + postponed=False, + datetime_contact_reminder__isnull=True, ) return result +def get_subjects_with_reminder(user): + tomorrow = get_today_midnight_date() + datetime.timedelta(days=1) + + result = Subject.objects.filter( + dead=False, + resigned=False, + default_location__in = get_filter_locations(user), + datetime_contact_reminder__lt=tomorrow, + ) + return result + +def get_subjects_with_reminder_count(user): + notification = NotificationCount( + title = "subject required contact", + count = get_subjects_with_reminder(user).count(), + style = "fa fa-users text-aqua", + type = 'web.views.subject_no_visits') + return notification + def get_subject_with_no_visit_notifications_count(user): notification = NotificationCount( title = "subject without visit", @@ -251,6 +272,8 @@ def get_notifications(the_user): notifications.append(get_visits_with_missing_appointments_count(person)) notifications.append(get_subject_with_no_visit_notifications_count(person)) notifications.append(get_approaching_visits_for_mail_contact_count(person)) + notifications.append(get_subjects_with_reminder_count(person)) + for notification in notifications: count += notification.count -- GitLab