本文整理匯總了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)
示例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."))