当前位置: 首页>>代码示例>>Python>>正文


Python Notification.choice_note方法代码示例

本文整理汇总了Python中notifications.models.Notification.choice_note方法的典型用法代码示例。如果您正苦于以下问题:Python Notification.choice_note方法的具体用法?Python Notification.choice_note怎么用?Python Notification.choice_note使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在notifications.models.Notification的用法示例。


在下文中一共展示了Notification.choice_note方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: new_note

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import choice_note [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]))
开发者ID:tommydangerous,项目名称:spadetree,代码行数:47,代码来源:views.py


注:本文中的notifications.models.Notification.choice_note方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。