예제 #1
0
    def send(self):
        """
        Sends a reminder email to the user.
        """
        if not self.sent:
            challenge = challenge_mgr.get_challenge()
            subject = "[%s] Reminder for %s" % (challenge.name, self.action.title)
            message = render_to_string(
                "email/activity_reminder.txt",
                {
                    "action": self.action,
                    "user": self.user,
                    "COMPETITION_NAME": challenge.name,
                    "domain": challenge.domain,
                },
            )
            html_message = render_to_string(
                "email/activity_reminder.html",
                {
                    "action": self.action,
                    "user": self.user,
                    "COMPETITION_NAME": challenge.name,
                    "domain": challenge.domain,
                },
            )

            UserNotification.create_email_notification(self.email_address, subject, message, html_message)
            self.sent = True
            self.save()
예제 #2
0
    def send(self):
        """
        Sends a reminder email to the user.
        """
        if not self.sent:
            challenge = challenge_mgr.get_challenge()
            subject = "[%s] Reminder for %s" % (challenge.name,
                                                self.action.title)
            message = render_to_string(
                "email/activity_reminder.txt", {
                    "action": self.action,
                    "user": self.user,
                    "COMPETITION_NAME": challenge.name,
                    "domain": challenge.domain,
                })
            html_message = render_to_string(
                "email/activity_reminder.html", {
                    "action": self.action,
                    "user": self.user,
                    "COMPETITION_NAME": challenge.name,
                    "domain": challenge.domain,
                })

            UserNotification.create_email_notification(self.email_address,
                                                       subject, message,
                                                       html_message)
            self.sent = True
            self.save()
예제 #3
0
    def send(self):
        """
        Sends a reminder text to the user via an email.
        """
        number = self.text_number.replace("-", "")
        email = number + "@" + self.TEXT_EMAILS[self.text_carrier]
        if not self.sent:
            message = render_to_string("email/activity_text_reminder.txt", {"activity": self.action, "user": self.user})

            UserNotification.create_email_notification(email, "", message)
            self.sent = True
            self.save()
예제 #4
0
    def _send_winner_notification(self, prize, leader):
        """send notification."""
        if leader and not self._notification_exists(prize, leader):
            # Notify winner using the template.
            template = NoticeTemplate.objects.get(notice_type='prize-winner')
            message = template.render({'PRIZE': prize})
            UserNotification.create_info_notification(leader.user, message, True, prize)

            challenge = challenge_mgr.get_challenge()
            subject = "[%s] Congratulations, you won a prize!" % challenge.name
            UserNotification.create_email_notification(
                leader.user.email, subject, message, message)
예제 #5
0
    def _send_winner_notification(self, prize, leader):
        """send notification."""
        if leader and not self._notification_exists(prize, leader):
            # Notify winner using the template.
            template = NoticeTemplate.objects.get(notice_type='prize-winner')
            message = template.render({'PRIZE': prize})
            UserNotification.create_info_notification(leader.user, message,
                                                      True, prize)

            challenge = challenge_mgr.get_challenge()
            subject = "[%s] Congratulations, you won a prize!" % challenge.name
            UserNotification.create_email_notification(leader.user.email,
                                                       subject, message,
                                                       message)
예제 #6
0
    def send(self):
        """
        Sends a reminder text to the user via an email.
        """
        number = self.text_number.replace("-", "")
        email = number + "@" + self.TEXT_EMAILS[self.text_carrier]
        if not self.sent:
            message = render_to_string("email/activity_text_reminder.txt", {
                "activity": self.action,
                "user": self.user,
            })

            UserNotification.create_email_notification(email, "", message)
            self.sent = True
            self.save()
예제 #7
0
    def notify_winner(self, request, queryset):
        """pick winner."""
        _ = request
        for obj in queryset:
            if obj.winner and not self.notice_sent(obj):
                # Notify winner using the template.
                template = NoticeTemplate.objects.get(notice_type="raffle-winner")
                message = template.render({"PRIZE": obj})
                UserNotification.create_info_notification(obj.winner, message, True, obj)

                challenge = challenge_mgr.get_challenge()
                subject = "[%s] Congratulations, you won a prize!" % challenge.name
                UserNotification.create_email_notification(obj.winner.email, subject, message, message)

        self.message_user(request, "Winners notification sent.")
예제 #8
0
    def notify_winner(self, request, queryset):
        """pick winner."""
        _ = request
        for obj in queryset:
            if obj.winner and not self.notice_sent(obj):
                # Notify winner using the template.
                template = NoticeTemplate.objects.get(
                    notice_type='raffle-winner')
                message = template.render({'PRIZE': obj})
                UserNotification.create_info_notification(
                    obj.winner, message, True, obj)

                challenge = challenge_mgr.get_challenge()
                subject = "[%s] Congratulations, you won a prize!" % challenge.name
                UserNotification.create_email_notification(
                    obj.winner.email, subject, message, message)

        self.message_user(request, "Winners notification sent.")
예제 #9
0
    def notify_winner(self, request, queryset):
        """pick winner."""
        _ = request
        for obj in queryset:
            leader = obj.leader()
            if leader and obj.award_to in ('individual_overall', 'individual_team')\
                and not self.notice_sent(obj):
                # Notify winner using the template.
                template = NoticeTemplate.objects.get(notice_type='prize-winner')
                message = template.render({'PRIZE': obj})
                UserNotification.create_info_notification(leader.user, message, True, obj)

                challenge = challenge_mgr.get_challenge()
                subject = "[%s] Congratulations, you won a prize!" % challenge.competition_name
                UserNotification.create_email_notification(
                    leader.user.email, subject, message, message)

        self.message_user(request, "Winners notification sent.")
예제 #10
0
    def _handle_activity_notification(self, status):
        """Creates a notification for rejected or approved tasks.
        This also creates an email message if it is configured.
        """
        # don't create notification if the action is the SETUP_WIZARD_ACTIVITY
        # that is used in the setup wizard.
        if self.action.slug == SETUP_WIZARD_ACTIVITY:
            return

        # Construct the message to be sent.
        status_nicely = "not approved" if status != "approved" else status
        message = 'Your response to <a href="%s#action-details">"%s"</a> %s was %s.' % (
            reverse("activity_task", args=(self.action.type, self.action.slug)),
            self.action.title,
            # The below is to tell the javascript to convert into a pretty date.
            # See the prettyDate function in media/js/makahiki.js
            '<span class="rejection-date" title="%s"></span>' % self.submission_date.isoformat(),
            status_nicely,
        )

        if status != "approved":
            challenge = challenge_mgr.get_challenge()
            message += " You can still get points by clicking on the link and trying again."
            UserNotification.create_error_notification(self.user, message, display_alert=True, content_object=self)

            # only send out email notification for rejected action
            subject = "[%s] Your response to '%s' was %s" % (challenge.name, self.action.title, status_nicely)

            message = render_to_string(
                "email/rejected_activity.txt",
                {
                    "object": self,
                    "COMPETITION_NAME": challenge.name,
                    "domain": challenge.domain,
                    "status_nicely": status_nicely,
                },
            )
            html_message = render_to_string(
                "email/rejected_activity.html",
                {
                    "object": self,
                    "COMPETITION_NAME": challenge.name,
                    "domain": challenge.domain,
                    "status_nicely": status_nicely,
                },
            )

            UserNotification.create_email_notification(self.user.email, subject, message, html_message)
        else:
            points = self.points_awarded if self.points_awarded else self.action.point_value
            message += " You earned %d points!" % points

            UserNotification.create_success_notification(self.user, message, display_alert=True, content_object=self)

            # if admin approve an activity (action_type==activity),
            # check to the submission queue is empty,
            # if so, remove the admin reminder object.
            if self.action.type == "activity":
                submission_count = ActionMember.objects.filter(
                    action__type="activity", approval_status="pending"
                ).count()
                if not submission_count:
                    try:
                        admin = User.objects.get(username=settings.ADMIN_USER)
                        action = Action.objects.get(slug=SETUP_WIZARD_ACTIVITY)
                        EmailReminder.objects.filter(user=admin, action=action).delete()
                    except ObjectDoesNotExist:
                        pass
예제 #11
0
    def _handle_activity_notification(self, status):
        """Creates a notification for rejected or approved tasks.
        This also creates an email message if it is configured.
        """
        # don't create notification if the action is the SETUP_WIZARD_ACTIVITY
        # that is used in the setup wizard.
        if self.action.slug == SETUP_WIZARD_ACTIVITY:
            return

        # Construct the message to be sent.
        status_nicely = 'not approved' if status != 'approved' else status
        message = 'Your response to <a href="%s#action-details">"%s"</a> %s was %s.' % (
            reverse("activity_task",
                    args=(
                        self.action.type,
                        self.action.slug,
                    )),
            self.action.title,
            # The below is to tell the javascript to convert into a pretty date.
            # See the prettyDate function in media/js/makahiki.js
            '<span class="rejection-date" title="%s"></span>' %
            self.submission_date.isoformat(),
            status_nicely,
        )

        if status != 'approved':
            challenge = challenge_mgr.get_challenge()
            message += " You can still get points by clicking on the link and trying again."
            UserNotification.create_error_notification(self.user,
                                                       message,
                                                       display_alert=True,
                                                       content_object=self)

            # only send out email notification for rejected action
            subject = "[%s] Your response to '%s' was %s" % (
                challenge.name, self.action.title, status_nicely)

            message = render_to_string(
                "email/rejected_activity.txt", {
                    "object": self,
                    "COMPETITION_NAME": challenge.name,
                    "domain": challenge.domain,
                    "status_nicely": status_nicely,
                })
            html_message = render_to_string(
                "email/rejected_activity.html", {
                    "object": self,
                    "COMPETITION_NAME": challenge.name,
                    "domain": challenge.domain,
                    "status_nicely": status_nicely,
                })

            UserNotification.create_email_notification(self.user.email,
                                                       subject, message,
                                                       html_message)
        else:
            points = self.points_awarded if self.points_awarded else self.action.point_value
            message += " You earned %d points!" % points

            UserNotification.create_success_notification(self.user,
                                                         message,
                                                         display_alert=True,
                                                         content_object=self)

            # if admin approve an activity (action_type==activity),
            # check to the submission queue is empty,
            # if so, remove the admin reminder object.
            if self.action.type == "activity":
                submission_count = ActionMember.objects.filter(
                    action__type="activity",
                    approval_status="pending").count()
                if not submission_count:
                    try:
                        admin = User.objects.get(username=settings.ADMIN_USER)
                        action = Action.objects.get(slug=SETUP_WIZARD_ACTIVITY)
                        EmailReminder.objects.filter(user=admin,
                                                     action=action).delete()
                    except ObjectDoesNotExist:
                        pass
예제 #12
0
def process_rsvp():
    """Process RSVP notification and penalty"""
    noshow_penalty_points = score_mgr.noshow_penalty_points()
    signup_points = score_mgr.signup_points()

    members = ActionMember.objects.filter(
        Q(action__type="event") | Q(action__type="excursion"),
        approval_status="pending")

    # try and load the notification template.
    template_noshow = None
    try:
        template_noshow = NoticeTemplate.objects.get(
            notice_type="event-noshow-penalty")
    except NoticeTemplate.DoesNotExist:
        pass

    template_reminder = None
    try:
        template_reminder = NoticeTemplate.objects.get(
            notice_type="event-post-reminder")
    except NoticeTemplate.DoesNotExist:
        pass

    for member in members:
        action = member.action
        user = member.user
        profile = user.get_profile()

        diff = datetime.date.today() - action.event.event_date.date()
        if diff.days == NOSHOW_PENALTY_DAYS:
            # send out notification to remind the penalty
            if template_reminder:
                message = template_reminder.render({"ACTIVITY": action})
            else:
                message = "Hi %s, <p/> We just wanted to remind you that the "\
                          "%s <a href='http://%s%s'>%s</a> had ended. Please "\
                          "click on the link to claim your points." % (
                    profile.name,
                    action.type.capitalize(),
                    challenge_mgr.get_challenge().domain,
                    reverse("activity_task", args=(action.type, action.slug,)),
                    action.title)
                message += "<p/>Because you signed up for the "\
                           "event, if you do not enter the "\
                           "confirmation code within %d days after the "\
                           "event, a total of %d points (%d point "\
                           "signup bonus plus %d point no-show penalty) will "\
                           "be deducted from your total points. So please "\
                           "enter your confirmation code early to avoid the "\
                           "penalty." % (
                    NOSHOW_PENALTY_DAYS,
                    noshow_penalty_points + signup_points,
                    noshow_penalty_points,
                    signup_points,
                )
                message += "<p/><p/>Kukui Cup Administrators"
            subject = "[Kukui Cup] Reminder to enter your event confirmation code"
            UserNotification.create_email_notification(user.email, subject,
                                                       message, message)
            print "sent post event email reminder to %s for %s" % (
                profile.name, action.title)
        elif diff.days == (NOSHOW_PENALTY_DAYS + 1):
            # the day after the penalty day, process the penalty reduction
            message = "%s: %s (No Show)" % (action.type.capitalize(), action.title)
            profile.remove_points(noshow_penalty_points + signup_points,
                                  datetime.datetime.today() - datetime.timedelta(minutes=1),
                                  message,
                                  member)
            print "removed noshow penalty points from %s for '%s'" % (profile.name, message)

            if template_noshow:
                message = template_noshow.render({"ACTIVITY": action})
            else:
                message = "%d points had been deducted from you, "\
                          "because you signed up but did not enter the "\
                          "confirmation code %d days after the %s <a "\
                          "href='%s'>%s</a>, " % (
                    noshow_penalty_points + signup_points,
                    NOSHOW_PENALTY_DAYS,
                    action.type.capitalize(),
                    reverse("activity_task", args=(action.type, action.slug,)),
                    action.title)
                message += " If you did attend, please click on the link to "\
                           "claim your points and reverse the deduction."

            UserNotification.create_info_notification(user, message,
                                                      display_alert=True,
                                                      content_object=member)
            print "created no-show penalty notification for %s for %s" % (
                profile.name, action.title)
예제 #13
0
def process_rsvp():
    """Process RSVP notification and penalty"""
    noshow_penalty_points = score_mgr.noshow_penalty_points()
    signup_points = score_mgr.signup_points()

    members = ActionMember.objects.filter(Q(action__type="event")
                                          | Q(action__type="excursion"),
                                          approval_status="pending")

    # try and load the notification template.
    template_noshow = None
    try:
        template_noshow = NoticeTemplate.objects.get(
            notice_type="event-noshow-penalty")
    except NoticeTemplate.DoesNotExist:
        pass

    template_reminder = None
    try:
        template_reminder = NoticeTemplate.objects.get(
            notice_type="event-post-reminder")
    except NoticeTemplate.DoesNotExist:
        pass

    for member in members:
        action = member.action
        user = member.user
        profile = user.profile

        diff = datetime.date.today() - action.event.event_date.date()
        if diff.days == NOSHOW_PENALTY_DAYS:
            # send out notification to remind the penalty
            if template_reminder:
                message = template_reminder.render({"ACTIVITY": action})
            else:
                message = "Hi %s, <p/> We just wanted to remind you that the "\
                          "%s <a href='http://%s%s'>%s</a> had ended. Please "\
                          "click on the link to claim your points." % (
                    profile.name,
                    action.type.capitalize(),
                    challenge_mgr.get_challenge().domain,
                    reverse("activity_task", args=(action.type, action.slug,)),
                    action.title)
                message += "<p/>Because you signed up for the "\
                           "event, if you do not enter the "\
                           "confirmation code within %d days after the "\
                           "event, a total of %d points (%d point "\
                           "signup bonus plus %d point no-show penalty) will "\
                           "be deducted from your total points. So please "\
                           "enter your confirmation code early to avoid the "\
                           "penalty." % (
                    NOSHOW_PENALTY_DAYS,
                    noshow_penalty_points + signup_points,
                    noshow_penalty_points,
                    signup_points,
                )
                message += "<p/><p/>Kukui Cup Administrators"
            subject = "[Kukui Cup] Reminder to enter your event confirmation code"
            UserNotification.create_email_notification(user.email, subject,
                                                       message, message)
            print "sent post event email reminder to %s for %s" % (
                profile.name, action.title)
        elif diff.days == (NOSHOW_PENALTY_DAYS + 1):
            # the day after the penalty day, process the penalty reduction
            message = "%s: %s (No Show)" % (action.type.capitalize(),
                                            action.title)
            profile.remove_points(
                noshow_penalty_points + signup_points,
                datetime.datetime.today() - datetime.timedelta(minutes=1),
                message, member)
            print "removed noshow penalty points from %s for '%s'" % (
                profile.name, message)

            if template_noshow:
                message = template_noshow.render({"ACTIVITY": action})
            else:
                message = "%d points had been deducted from you, "\
                          "because you signed up but did not enter the "\
                          "confirmation code %d days after the %s <a "\
                          "href='%s'>%s</a>, " % (
                    noshow_penalty_points + signup_points,
                    NOSHOW_PENALTY_DAYS,
                    action.type.capitalize(),
                    reverse("activity_task", args=(action.type, action.slug,)),
                    action.title)
                message += " If you did attend, please click on the link to "\
                           "claim your points and reverse the deduction."

            UserNotification.create_info_notification(user,
                                                      message,
                                                      display_alert=True,
                                                      content_object=member)
            print "created no-show penalty notification for %s for %s" % (
                profile.name, action.title)