Exemplo n.º 1
0
def email_mentor_on_add_report(sender, instance, created, **kwargs):
    """Email a mentor when a user adds or edits a report."""
    subject = '[Report] Your mentee, %s %s a report for %s %s.'
    email_template = 'emails/mentor_notification_report_added_or_edited.txt'
    month = instance.month.strftime('%B')
    year = instance.month.strftime('%Y')
    rep_user = instance.user
    rep_profile = instance.user.userprofile
    mentor_profile = instance.mentor.userprofile
    ctx_data = {
        'rep_user': rep_user,
        'rep_profile': rep_profile,
        'new_report': created,
        'month': month,
        'year': year
    }
    if created:
        if mentor_profile.receive_email_on_add_report:
            subject = subject % (
                (rep_profile.display_name, 'added', month, year))
            send_remo_mail.delay([instance.mentor.id], subject, email_template,
                                 ctx_data)
    else:
        if mentor_profile.receive_email_on_edit_report:
            subject = subject % (rep_profile.display_name, 'edited', month,
                                 year)
            send_remo_mail.delay([instance.mentor.id], subject, email_template,
                                 ctx_data)
Exemplo n.º 2
0
def email_commenters_on_add_ng_report_comment(sender, instance, **kwargs):
    """Email a user when a comment is added to a continuous report instance."""
    subject = '[Report] User {0} commented on {1}'
    email_template = 'emails/user_notification_on_add_ng_report_comment.txt'
    report = instance.report

    # Send an email to all users commented so far on the report except fom
    # the user who made the comment. Dedup the list with unique IDs.
    commenters = set(NGReportComment.objects.filter(report=report)
                     .exclude(user=instance.user)
                     .values_list('user', flat=True))

    # Add the owner of the report in the list
    if report.user.id not in commenters:
        commenters.add(report.user.id)

    for user_id in commenters:
        user = User.objects.get(pk=user_id)
        if (user.userprofile.receive_email_on_add_comment and
                user != instance.user):
            ctx_data = {'report': report, 'user': user,
                        'commenter': instance.user,
                        'comment': instance.comment,
                        'created_on': instance.created_on}
            subject = subject.format(instance.user.get_full_name(), report)
            send_remo_mail.delay([user_id], subject,
                                 email_template, ctx_data)
Exemplo n.º 3
0
def poll_vote_reminder():
    """Send an email reminder every 8 hours to
    remind valid users to cast their vote.

    """
    now = datetime2pdt()
    polls = Poll.objects.filter(start__lte=now, end__gt=now)

    for poll in polls:
        last_notification = (poll.last_nofication
                             if poll.last_notification else poll.created_on)

        time_diff = (time.mktime(now.timetuple()) -
                     time.mktime(last_notification.timetuple()))
        if time_diff > NOTIFICATION_INTERVAL:
            valid_users = User.objects.filter(groups=poll.valid_groups)
            recipients = (valid_users.exclude(
                pk__in=poll.users_voted.all()).values_list('id', flat=True))
            subject = ('[Reminder][Voting] Please cast your vote '
                       'for "%s" now!' % poll.name)
            template_reminder = 'emails/voting_vote_reminder.txt'
            ctx_data = {'poll': poll}
            send_remo_mail.delay(recipients, subject, template_reminder,
                                 ctx_data)
            Poll.objects.filter(pk=poll.pk).update(last_notification=now)
Exemplo n.º 4
0
def poll_vote_reminder():
    """Send an email reminder every 8 hours to
    remind valid users to cast their vote.

    """
    now = datetime2pdt()
    polls = Poll.objects.filter(start__lte=now, end__gt=now)

    for poll in polls:
        last_notification = (poll.last_nofication if poll.last_notification
                             else poll.created_on)

        time_diff = (time.mktime(now.timetuple()) -
                     time.mktime(last_notification.timetuple()))
        if time_diff > NOTIFICATION_INTERVAL:
            valid_users = User.objects.filter(groups=poll.valid_groups)
            recipients = (valid_users.exclude(pk__in=poll.users_voted.all())
                                     .values_list('id', flat=True))
            subject = ('[Reminder][Voting] Please cast your vote '
                       'for "%s" now!' % poll.name)
            template_reminder = 'emails/voting_vote_reminder.txt'
            ctx_data = {'poll': poll}
            send_remo_mail.delay(recipients, subject,
                                 template_reminder, ctx_data)
            Poll.objects.filter(pk=poll.pk).update(last_notification=now)
Exemplo n.º 5
0
def email_mentor_notification(sender, instance, raw, **kwargs):
    """Notify mentor when his/her mentee changes mentor on his/her profile."""
    if UserProfile.objects.filter(user=instance.user).exists() and not raw:
        user_profile = UserProfile.objects.get(user=instance.user)
        if user_profile.mentor and user_profile.mentor != instance.mentor:
            subject = "[Reps] Change of mentor."
            email_template = "emails/mentor_change_notification.txt"
            recipients = [user_profile.mentor.id, user_profile.user.id, instance.mentor.id]
            ctx_data = {"rep_user": instance.user, "new_mentor": instance.mentor}
            send_remo_mail.delay(recipients, subject, email_template, ctx_data)
Exemplo n.º 6
0
def email_user_on_add_comment(sender, instance, **kwargs):
    """Email a user when a comment is added to a report."""
    subject = '[Report] User %s commented on your report of %s'
    email_template = 'emails/user_notification_on_add_comment.txt'
    report = instance.report
    owner = instance.report.user
    ctx_data = {'report': report, 'owner': owner, 'user': instance.user,
                'comment': instance.comment, 'created_on': instance.created_on}
    if owner.userprofile.receive_email_on_add_comment:
        subject = subject % (instance.user.get_full_name(),
                             report.month.strftime('%B %Y'))
        send_remo_mail.delay([owner], subject, email_template, ctx_data)
Exemplo n.º 7
0
def email_user_on_add_comment(sender, instance, **kwargs):
    """Email a user when a comment is added to a report."""
    subject = '[Report] User %s commented on your report of %s'
    email_template = 'emails/user_notification_on_add_comment.txt'
    report = instance.report
    owner = instance.report.user
    ctx_data = {'report': report, 'owner': owner, 'user': instance.user,
                'comment': instance.comment, 'created_on': instance.created_on}
    if owner.userprofile.receive_email_on_add_comment:
        subject = subject % (instance.user.get_full_name(),
                             report.month.strftime('%B %Y'))
        send_remo_mail.delay([owner.id], subject, email_template, ctx_data)
Exemplo n.º 8
0
def email_event_owner_on_add_comment(sender, instance, **kwargs):
    """Email event owner when a comment is added to event."""
    subject = '[Event] User %s commented on event "%s"'
    email_template = 'email/owner_notification_on_add_comment.txt'
    event = instance.event
    owner = instance.event.owner
    event_url = reverse('events_view_event', kwargs={'slug': event.slug})
    ctx_data = {'event': event, 'owner': owner, 'user': instance.user,
                'comment': instance.comment, 'event_url': event_url}
    if owner.userprofile.receive_email_on_add_event_comment:
        subject = subject % (instance.user.get_full_name(),
                             instance.event.name)
        send_remo_mail.delay([owner], subject, email_template, ctx_data)
Exemplo n.º 9
0
def email_event_owner_on_add_comment(sender, instance, **kwargs):
    """Email event owner when a comment is added to event."""
    subject = '[Event] User %s commented on event "%s"'
    email_template = 'email/owner_notification_on_add_comment.txt'
    event = instance.event
    owner = instance.event.owner
    event_url = reverse('events_view_event', kwargs={'slug': event.slug})
    ctx_data = {'event': event, 'owner': owner, 'user': instance.user,
                'comment': instance.comment, 'event_url': event_url}
    if owner.userprofile.receive_email_on_add_event_comment:
        subject = subject % (instance.user.get_full_name(),
                             instance.event.name)
        send_remo_mail.delay([owner.id], subject, email_template, ctx_data)
Exemplo n.º 10
0
def email_mentor_notification(sender, instance, raw, **kwargs):
    """Notify mentor when his/her mentee changes mentor on his/her profile."""
    if UserProfile.objects.filter(user=instance.user).exists() and not raw:
        user_profile = UserProfile.objects.get(user=instance.user)
        if user_profile.mentor and user_profile.mentor != instance.mentor:
            subject = '[Reps] Change of mentor.'
            email_template = 'emails/mentor_change_notification.txt'
            recipients = [
                user_profile.mentor.id, user_profile.user.id,
                instance.mentor.id
            ]
            ctx_data = {
                'rep_user': instance.user,
                'new_mentor': instance.mentor
            }
            send_remo_mail.delay(recipients, subject, email_template, ctx_data)
Exemplo n.º 11
0
def email_user_on_add_comment(sender, instance, **kwargs):
    """Email a user when a comment is added to a report."""
    subject = "[Report] User %s commented on your report of %s"
    email_template = "emails/user_notification_on_add_comment.txt"
    report = instance.report
    owner = instance.report.user
    ctx_data = {
        "report": report,
        "owner": owner,
        "user": instance.user,
        "comment": instance.comment,
        "created_on": instance.created_on,
    }
    if owner.userprofile.receive_email_on_add_comment:
        subject = subject % (instance.user.get_full_name(), report.month.strftime("%B %Y"))
        send_remo_mail.delay([owner.id], subject, email_template, ctx_data)
Exemplo n.º 12
0
def email_mentor_on_add_report(sender, instance, created, **kwargs):
    """Email a mentor when a user adds or edits a report."""
    subject = "[Report] Your mentee, %s %s a report for %s %s."
    email_template = "emails/mentor_notification_report_added_or_edited.txt"
    month = instance.month.strftime("%B")
    year = instance.month.strftime("%Y")
    rep_user = instance.user
    rep_profile = instance.user.userprofile
    mentor_profile = instance.mentor.userprofile
    ctx_data = {"rep_user": rep_user, "rep_profile": rep_profile, "new_report": created, "month": month, "year": year}
    if created:
        if mentor_profile.receive_email_on_add_report:
            subject = subject % ((rep_profile.display_name, "added", month, year))
            send_remo_mail.delay([instance.mentor.id], subject, email_template, ctx_data)
    else:
        if mentor_profile.receive_email_on_edit_report:
            subject = subject % (rep_profile.display_name, "edited", month, year)
            send_remo_mail.delay([instance.mentor.id], subject, email_template, ctx_data)
Exemplo n.º 13
0
def email_mentor_on_add_report(sender, instance, created, **kwargs):
    """Email a mentor when a user adds or edits a report."""
    subject = '[Report] Your mentee, %s %s a report for %s %s.'
    email_template = 'emails/mentor_notification_report_added_or_edited.txt'
    month = instance.month.strftime('%B')
    year = instance.month.strftime('%Y')
    rep_user = instance.user
    rep_profile = instance.user.userprofile
    mentor = rep_profile.mentor.userprofile
    ctx_data = {'rep_user': rep_user, 'rep_profile': rep_profile,
                'new_report': created, 'month': month, 'year': year}
    if created:
        if mentor.receive_email_on_add_report:
            subject = subject % (rep_profile.display_name, 'added', month, year)
            send_remo_mail.delay([instance.mentor], subject, email_template,
                                 ctx_data)
    else:
        if mentor.receive_email_on_edit_report:
            subject = subject % (rep_profile.display_name, 'edited',
                                 month, year)
            send_remo_mail.delay([instance.mentor], subject, email_template,
                                 ctx_data)