本文整理汇总了Python中notifications.models.Notification.action方法的典型用法代码示例。如果您正苦于以下问题:Python Notification.action方法的具体用法?Python Notification.action怎么用?Python Notification.action使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类notifications.models.Notification
的用法示例。
在下文中一共展示了Notification.action方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_note
# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import action [as 别名]
def new_note(request, pk, format=None):
"""Create a new note for choice."""
choice = get_object_or_404(Choice, pk=pk)
if request.user not in [choice.tutee, choice.tutor]:
return HttpResponseRedirect(reverse('choices.views.requests'))
if request.method == 'POST' and request.POST.get('content'):
choice_note = ChoiceNote(choice=choice,
content=request.POST.get('content'), user=request.user)
choice_note.save()
try:
channel = Channel.objects.get(choice=choice)
# Create notification for this channel
notification = Notification()
notification.action = 'new'
notification.channel = channel
notification.choice_note = choice_note
notification.model = 'choice_note'
notification.user = request.user
notification.save()
except Channel.DoesNotExist:
pass
if format and format == '.json':
data = {
'choice_note': choice_note.to_json(),
}
elif request.is_ajax():
d = {
'choice': choice,
'choice_note': choice_note,
}
choice_note_template = loader.get_template(
'choices/choice_note.html')
choice_note_form = loader.get_template(
'choices/choice_note_form.html')
context = RequestContext(request, add_csrf(request, d))
data = {
'choice_note_template': choice_note_template.render(
context),
'choice_note_form': choice_note_form.render(context)
}
if (format and format == '.json') or request.is_ajax():
return HttpResponse(json.dumps(data),
mimetype='application/json')
return HttpResponseRedirect(reverse('choices.views.detail',
args=[choice.pk]))