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


Python Notification.send方法代码示例

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


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

示例1: NotificationTests

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import send [as 别名]
class NotificationTests(TestCase):
    def setUp(self):
        settings.NOTIFICATION_OPTIONS = dict(
                TEST_NOTIFICATION=dict(
                        caller='notification',
                        template='notification_test_template.html',
                        subject='Notification test template'
                )
        )

        self.package = dict(
                caller='notifications',
                notification_type='TEST_NOTIFICATION',
                recipients=['[email protected]_host.com', ],
                context=dict(
                        dummy_data='dummy_data'
                )
        )

    # noinspection PyUnresolvedReferences
    def tearDown(self):
        del settings.NOTIFICATION_OPTIONS

    # noinspection PyUnresolvedReferences
    def test_notification_options(self):
        self.notification = Notification(**self.package)
        self.notification.send()
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject, 'Notification test template')
        self.assertTrue('dummy_data' in mail.outbox[0].body)
开发者ID:vladblindu,项目名称:restserver,代码行数:32,代码来源:tests.py

示例2: post

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import send [as 别名]
    def post(self, request, token=None):
        user = check_token(token)
        password = request.data.get('new_password', '')
        if not password:
            return Response(
                    dict(status="error", error_code="new_password_required",
                         message="You haven't provided a new password."))

        # if we have a valid user
        if user:
            # check if the submitted password complies with the password_enforce_format
            pass_check = password_enforce_format(password)
            if pass_check:
                user.set_password(password)
                user.save()
                return Response(
                        dict(status="error", error_code="invalid_password_format",
                             message=pass_check))
            else:
                package = dict(
                        caller='jwt_auth',
                        notification_type='RESET_PASSWORD_CONFIRMATION',
                        recipients=[user.email, ],
                        context=dict(
                                username=user.username,
                                password=password
                        )
                )
                notify = Notification(**package)
                notify.send()
                return Response(dict(status="success", message="Password has been successfully reset"))
        else:
            return Response(
                    dict(status="error", error_code="invalid_token",
                         message="The token you provided is invalid or has expired."))
开发者ID:vladblindu,项目名称:restserver,代码行数:37,代码来源:views.py


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