diff --git a/smash/web/tests/test_view_notifications.py b/smash/web/tests/test_view_notifications.py index 2447e4a2d68173f768729b78785357ae330b9b14..9a2fb73aad6adf009be43399f0640e2fb77e9131 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 ba5eeae2301ec2f1224f824ae58c1f4189d4ab9e..eb89a75bb46b6b017a2da724b9f7f8690d3e863e 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