本文整理汇总了Python中notifications.models.Notification.data方法的典型用法代码示例。如果您正苦于以下问题:Python Notification.data方法的具体用法?Python Notification.data怎么用?Python Notification.data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类notifications.models.Notification
的用法示例。
在下文中一共展示了Notification.data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: notify_handler
# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import data [as 别名]
def notify_handler(verb, **kwargs):
"""
Handler function to create Notification instance upon action signal call.
"""
kwargs.pop('signal', None)
recipient = kwargs.pop('recipient')
actor = kwargs.pop('sender')
newnotify = Notification(
recipient = recipient,
actor_content_type=ContentType.objects.get_for_model(actor),
actor_object_id=actor.pk,
verb=unicode(verb),
public=bool(kwargs.pop('public', True)),
description=kwargs.pop('description', None),
timestamp=kwargs.pop('timestamp', now())
)
for opt in ('target', 'action_object'):
obj = kwargs.pop(opt, None)
if not obj is None:
setattr(newnotify, '%s_object_id' % opt, obj.pk)
setattr(newnotify, '%s_content_type' % opt,
ContentType.objects.get_for_model(obj))
if len(kwargs) and EXTRA_DATA:
newnotify.data = kwargs
newnotify.save()
示例2: notify_user
# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import data [as 别名]
def notify_user(recipient, actor, verb, **kwargs):
"""
Handler function to create Notification instance upon action signal call.
"""
new_notification = Notification(
recipient = recipient,
actor_content_type=ContentType.objects.get_for_model(actor),
actor_object_id=actor.pk,
verb=text_type(verb),
public=bool(kwargs.pop('public', False)),
description=kwargs.pop('description', None),
timestamp=kwargs.pop('timestamp', utc_now()),
level=kwargs.pop('level', Notification.LEVELS.info),
)
for opt in ('target', 'action_object'):
obj = kwargs.pop(opt, None)
if not obj is None:
setattr(new_notification, '%s_object_id' % opt, obj.pk)
setattr(new_notification, '%s_content_type' % opt,
ContentType.objects.get_for_model(obj))
if len(kwargs) and EXTRA_DATA:
new_notification.data = kwargs
new_notification.save()
return new_notification