예제 #1
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':
            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)
        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)
예제 #2
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':
            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)
        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)
예제 #3
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
예제 #4
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