def send_first_report_notification(): """Send inactivity notification after 4 weeks.""" today = get_date() start = today - timedelta(weeks=4) end = today + timedelta(weeks=4) users = User.objects.filter( groups__name='Rep', userprofile__registration_complete=True, userprofile__first_report_notification__isnull=True) inactive_users = users.exclude(ng_reports__report_date__range=[start, end]) send_report_notification(inactive_users, weeks=4) for user in inactive_users: user.userprofile.first_report_notification = today user.userprofile.save()
def send_first_report_notification(): """Send inactivity notification after 4 weeks.""" today = get_date() start = today - timedelta(weeks=4) end = today + timedelta(weeks=4) users = User.objects.filter( groups__name='Rep', userprofile__registration_complete=True, userprofile__first_report_notification__isnull=True) # Exclude users with a report filed between start and end period # and users who joined the program less than one month inactive_users = users.exclude( ng_reports__report_date__range=[start, end], userprofile__date_joined_program__gt=start) send_report_notification(inactive_users, weeks=4) for user in inactive_users: user.userprofile.first_report_notification = today user.userprofile.save() statsd.incr('reports.send_first_report_notification')
def send_first_report_notification(): """Send inactivity notification after 4 weeks.""" today = get_date() start = today - timedelta(weeks=4) end = today + timedelta(weeks=4) users = User.objects.filter( groups__name='Rep', userprofile__registration_complete=True, userprofile__first_report_notification__isnull=True, userprofile__is_unavailable=False) # Exclude users with a report filed between start and end period # and users who joined the program less than one month inactive_users = (users .exclude(ng_reports__report_date__range=[start, end]) .exclude(userprofile__date_joined_program__gt=start)) send_report_notification(inactive_users, weeks=4) for user in inactive_users: user.userprofile.first_report_notification = today user.userprofile.save() statsd.incr('reports.send_first_report_notification')