本文整理汇总了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."))