# Path: api/processors.py
# def events_pending_for_report():
#     return Event.objects.filter(
#             reported_at=None,
#             status='APPROVED',
#             start_date__lte=datetime.datetime.now(),
#             start_date__gte=datetime.datetime(2015, 1, 1, 0, 0 ,0))
# 
# Path: api/processors.py
# def events_pending_for_report_for(creator):
#     return events_pending_for_report().filter(creator=creator)
# 
# Path: api/models/users.py
# class UserProfile(models.Model):
#     class Meta:
# class SocialAccountList(models.Model):
#     class Meta:
#     def __unicode__(self):
#     def is_ambassador(self):
# def get_user_profile(self):
# def email_with_name(self):
# def full_name(self):
#     def __unicode__(self):
# 
# Path: mailer/event_report_mailer.py
# def send_reminder_for_event_report_and_certificate(
#         user,
#         unreported_events_count,
#         previous_emails_count=0,
#         max_emails_count=None,
#         test_mode=False
#     ):
#     template = loader.get_template("mailer/reminder_for_event_report_and_certificate.txt")
#     context = Context({
#         'name': user.full_name(),
#         'email': user.email,
#         'previous_emails_count': previous_emails_count,
#         'total_emails_count': previous_emails_count + 1,
#         'max_emails_count': max_emails_count,
#         'unreported_events_count': unreported_events_count,
#     })
# 
#     content   = template.render(context)
#     subject   = '[CodeWeekEU] your feedback and your certificate of recognition'
#     sender    = settings.EVENT_REPORT_REMINDERS_FROM_EMAIL
#     recipient = user.email_with_name()
# 
#     if test_mode:
#         print("------------------------------------------------------------")
#         print(u"To: " + recipient)
#         print(u"From: " + sender)
#         print(u"Subject: " + subject)
#         print(u"\n" + content)
#         print("------------------------------------------------------------")
#     else:
#         send_mail(subject, content, sender, [recipient])


from datetime import datetime, timedelta
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from django.db.models import Q
from api.processors import events_pending_for_report
from api.processors import events_pending_for_report_for
from api.models.users import User
from mailer.event_report_mailer import send_reminder_for_event_report_and_certificate
            action='store',
            dest='emails_per_run',
            help='Required. The number of emails to send per run.'
        ),
        make_option('--notifications-limit',
            type='int',
            action='store',
            dest='notifications_limit',
            default=3,
            help='Send at most X notification emails for event reporting.'
        ),
        make_option('--notifications-interval-in-days',
            type='int',
            action='store',
            dest='notifications_interval_in_days',
            default=21,
            help="If we're allowed to send more than one reminder email, notifications will be sent each X days."
        ),
    )

    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)


# Path: api/processors.py
# def events_pending_for_report():
#     return Event.objects.filter(
#             reported_at=None,
#             status='APPROVED',
#             start_date__lte=datetime.datetime.now(),
#             start_date__gte=datetime.datetime(2015, 1, 1, 0, 0 ,0))
# 
# Path: api/processors.py
# def events_pending_for_report_for(creator):
#     return events_pending_for_report().filter(creator=creator)
# 
# Path: api/models/users.py
# class UserProfile(models.Model):
#     class Meta:
# class SocialAccountList(models.Model):
#     class Meta:
#     def __unicode__(self):
#     def is_ambassador(self):
# def get_user_profile(self):
# def email_with_name(self):
# def full_name(self):
#     def __unicode__(self):
# 
# Path: mailer/event_report_mailer.py
# def send_reminder_for_event_report_and_certificate(
#         user,
#         unreported_events_count,
#         previous_emails_count=0,
#         max_emails_count=None,
#         test_mode=False
#     ):
#     template = loader.get_template("mailer/reminder_for_event_report_and_certificate.txt")
#     context = Context({
#         'name': user.full_name(),
#         'email': user.email,
#         'previous_emails_count': previous_emails_count,
#         'total_emails_count': previous_emails_count + 1,
#         'max_emails_count': max_emails_count,
#         'unreported_events_count': unreported_events_count,
#     })
# 
#     content   = template.render(context)
#     subject   = '[CodeWeekEU] your feedback and your certificate of recognition'
#     sender    = settings.EVENT_REPORT_REMINDERS_FROM_EMAIL
#     recipient = user.email_with_name()
# 
#     if test_mode:
#         print("------------------------------------------------------------")
#         print(u"To: " + recipient)
#         print(u"From: " + sender)
#         print(u"Subject: " + subject)
#         print(u"\n" + content)
#         print("------------------------------------------------------------")
#     else:
#         send_mail(subject, content, sender, [recipient])


# Path: api/management/commands/remind_organizers_to_report_events.py
from datetime import datetime, timedelta
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from django.db.models import Q
from api.processors import events_pending_for_report
from api.processors import events_pending_for_report_for
from api.models.users import User
from mailer.event_report_mailer import send_reminder_for_event_report_and_certificate

            action='store',
            dest='emails_per_run',
            help='Required. The number of emails to send per run.'
        ),
        make_option('--notifications-limit',
            type='int',
            action='store',
            dest='notifications_limit',
            default=3,
            help='Send at most X notification emails for event reporting.'
        ),
        make_option('--notifications-interval-in-days',
            type='int',
            action='store',
            dest='notifications_interval_in_days',
            default=21,
            help="If we're allowed to send more than one reminder email, notifications will be sent each X days."
        ),
    )

    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(