當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。