def handle(self, *args, **options): last_reminder_sent_before = datetime.now() - timedelta(days=options['notifications_interval_in_days']) if options['emails_per_run'] == None: self.stderr.write( "Please specify the emails to send per run as a positional argument. E.g.:\n\n" + "manage.py remind_organizers_to_report_events --emails-per-run 100" ) exit(1) events_to_report = events_pending_for_report().filter( Q(last_report_notification_sent_at=None) | Q(last_report_notification_sent_at__lte=last_reminder_sent_before) ).filter( report_notifications_count__lt=options['notifications_limit'] ).order_by( 'report_notifications_count', 'start_date' ) organizer_ids = events_to_report.distinct().values_list('creator_id', flat=True) # The values above may not be unique as we're using ordering. See here for more info: # https://docs.djangoproject.com/en/1.6/ref/models/querysets/#django.db.models.query.QuerySet.distinct organizer_ids = list(set(organizer_ids)) organizers = User.objects.filter(id__in=organizer_ids) self.stdout.write( u'We have to notify {organizers_count} organizer(s) in a total of {events_count} event(s). Will send at most {emails_per_run} email(s) now.'.format( events_count=events_to_report.count(), organizers_count=organizers.count(), emails_per_run=options['emails_per_run'] ) ) for organizer in organizers[:options['emails_per_run']]: unreported_organizer_events = events_pending_for_report_for(organizer) unrepored_events_count = unreported_organizer_events.count() self.stdout.write( u'Emailing {contact} for {events_count} unreported event(s)'.format( contact=organizer.email_with_name(), events_count=unrepored_events_count ) ) send_reminder_for_event_report_and_certificate( organizer, unrepored_events_count, previous_emails_count=unreported_organizer_events[0].report_notifications_count, max_emails_count=options['notifications_limit'], test_mode=options['simulate_emails'] ) if not options['simulate_db']: for event in unreported_organizer_events: event.last_report_notification_sent_at = datetime.now() event.report_notifications_count += 1 event.save()
def handle(self, *args, **options): last_reminder_sent_before = datetime.now() - timedelta( days=options['notifications_interval_in_days']) if options['emails_per_run'] == None: self.stderr.write( "Please specify the emails to send per run as a positional argument. E.g.:\n\n" + "manage.py remind_organizers_to_report_events --emails-per-run 100" ) exit(1) events_to_report = events_pending_for_report().filter( Q(last_report_notification_sent_at=None) | Q( last_report_notification_sent_at__lte=last_reminder_sent_before )).filter( report_notifications_count__lt=options['notifications_limit'] ).order_by('report_notifications_count', 'start_date') organizer_ids = events_to_report.distinct().values_list('creator_id', flat=True) # The values above may not be unique as we're using ordering. See here for more info: # https://docs.djangoproject.com/en/1.6/ref/models/querysets/#django.db.models.query.QuerySet.distinct organizer_ids = list(set(organizer_ids)) organizers = User.objects.filter(id__in=organizer_ids) self.stdout.write( u'We have to notify {organizers_count} organizer(s) in a total of {events_count} event(s). Will send at most {emails_per_run} email(s) now.' .format(events_count=events_to_report.count(), organizers_count=organizers.count(), emails_per_run=options['emails_per_run'])) for organizer in organizers[:options['emails_per_run']]: unreported_organizer_events = events_pending_for_report_for( organizer) unrepored_events_count = unreported_organizer_events.count() self.stdout.write( u'Emailing {contact} for {events_count} unreported event(s)'. format(contact=organizer.email_with_name(), events_count=unrepored_events_count)) send_reminder_for_event_report_and_certificate( organizer, unrepored_events_count, previous_emails_count=unreported_organizer_events[0]. report_notifications_count, max_emails_count=options['notifications_limit'], test_mode=options['simulate_emails']) if not options['simulate_db']: for event in unreported_organizer_events: event.last_report_notification_sent_at = datetime.now() event.report_notifications_count += 1 event.save()
def events_to_report(request): """ Display a list of events which should be reported but have not been reported yet. """ creator = request.user event_list = events_pending_for_report_for(creator=creator) return render_to_response( 'pages/list_events_pending_for_report.html', { 'event_list': event_list, }, context_instance=RequestContext(request))
def events_to_report(request): """ Display a list of events which should be reported but have not been reported yet. """ creator = request.user unreported_events_list = events_pending_for_report_for(creator=creator) reported_events_list = reporeted_events_for(creator=creator) return render_to_response('pages/list_events_pending_for_report.html', { 'unreported_events_list': unreported_events_list, 'reported_events_list': reported_events_list, }, context_instance=RequestContext(request))