当前位置: 首页>>代码示例>>Python>>正文


Python UserNotification.create_error_notification方法代码示例

本文整理汇总了Python中apps.widgets.notifications.models.UserNotification.create_error_notification方法的典型用法代码示例。如果您正苦于以下问题:Python UserNotification.create_error_notification方法的具体用法?Python UserNotification.create_error_notification怎么用?Python UserNotification.create_error_notification使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在apps.widgets.notifications.models.UserNotification的用法示例。


在下文中一共展示了UserNotification.create_error_notification方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _handle_activity_notification

# 需要导入模块: from apps.widgets.notifications.models import UserNotification [as 别名]
# 或者: from apps.widgets.notifications.models.UserNotification import create_error_notification [as 别名]
    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)
开发者ID:jtakayama,项目名称:makahiki-draft,代码行数:32,代码来源:models.py

示例2: _handle_activity_notification

# 需要导入模块: from apps.widgets.notifications.models import UserNotification [as 别名]
# 或者: from apps.widgets.notifications.models.UserNotification import create_error_notification [as 别名]
    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
开发者ID:jtakayama,项目名称:ics691-setupbooster,代码行数:70,代码来源:models.py


注:本文中的apps.widgets.notifications.models.UserNotification.create_error_notification方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。