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


Python CommentForm.as_p方法代码示例

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


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

示例1: update_note

# 需要导入模块: from django.contrib.comments.forms import CommentForm [as 别名]
# 或者: from django.contrib.comments.forms.CommentForm import as_p [as 别名]
def update_note(request, space_url):

    """
    Updated the current note with the POST data. UpdateNoteForm is an incomplete
    form that doesn't handle some properties, only the important for the note
    editing.
    """

    place = get_object_or_404(Space, url=space_url)

    if request.method == "GET" and request.is_ajax:
        note = get_object_or_404(Note, pk=request.GET['noteid'])
        ctype = ContentType.objects.get_for_model(Note)
        latest_comments = Comment.objects.filter(is_public=True,
            is_removed=False, content_type=ctype, object_pk=note.id) \
            .order_by('-submit_date')[:5]
        form = CommentForm(target_object=note)

        response_data = {}
        response_data['title'] = note.title
        response_data['message'] = note.message
        response_data['author'] = {'name': note.author.username}
        response_data['comments'] = [{'username': c.user.username,
            'comment': c.comment,
            'submit_date': c.submit_date} for c in latest_comments]
        response_data["form_html"] = form.as_p()

        return HttpResponse(json.dumps(response_data, cls=DjangoJSONEncoder),
                            mimetype="application/json")

    if request.method == "POST" and request.is_ajax:
        if has_operation_permission(request.user, place, 'note.change_note',
        allow=['admins', 'mods']) or request.user == note.author:
            note = get_object_or_404(Note, pk=request.POST['noteid'])
            note_form = UpdateNoteForm(request.POST or None, instance=note)
            if note_form.is_valid():
                note_form_uncommited = note_form.save(commit=False)
                note_form_uncommited.title = request.POST['title']
                note_form_uncommited.message = request.POST['message']
                note_form_uncommited.last_mod_author = request.user

                note_form_uncommited.save()
                msg = "The note has been updated."
            else:
                msg = "The form is not valid, check field(s): " + note_form.errors
            return HttpResponse(msg)
        else:
            msg = "There was some error in the petition."
    return HttpResponse(msg)
开发者ID:badescunicu,项目名称:e-cidadania,代码行数:51,代码来源:views.py

示例2: update_note

# 需要导入模块: from django.contrib.comments.forms import CommentForm [as 别名]
# 或者: from django.contrib.comments.forms.CommentForm import as_p [as 别名]
def update_note(request, space_url):

    """
    Updated the current note with the POST data. UpdateNoteForm is an incomplete
    form that doesn't handle some properties, only the important for the note editing.
    """

    if request.method == "GET" and request.is_ajax:
        note = get_object_or_404(Note, pk=request.GET["noteid"])
        ctype = ContentType.objects.get_for_model(Note)
        latest_comments = Comment.objects.filter(
            is_public=True, is_removed=False, content_type=ctype, object_pk=note.id
        ).order_by("-submit_date")[:5]
        form = CommentForm(target_object=note)

        response_data = {}
        response_data["title"] = note.title
        response_data["message"] = note.message
        response_data["comments"] = [
            {"username": c.user.username, "comment": c.comment, "submit_date": c.submit_date} for c in latest_comments
        ]
        response_data["form_html"] = form.as_p()

        return HttpResponse(json.dumps(response_data, cls=DjangoJSONEncoder), mimetype="application/json")

    if request.method == "POST" and request.is_ajax:
        note = get_object_or_404(Note, pk=request.POST["noteid"])
        note_form = UpdateNoteForm(request.POST or None, instance=note)
        if note_form.is_valid():
            note_form_uncommited = note_form.save(commit=False)
            note_form_uncommited.title = request.POST["title"]
            note_form_uncommited.message = request.POST["message"]
            note_form_uncommited.last_mod_author = request.user

            note_form_uncommited.save()
            msg = "The note has been updated."
        else:
            msg = "The form is not valid, check field(s): " + note_form.errors
    else:
        msg = "There was some error in the petition."

    return HttpResponse(msg)
开发者ID:bithinalangot,项目名称:e-cidadania,代码行数:44,代码来源:views.py

示例3: update_note

# 需要导入模块: from django.contrib.comments.forms import CommentForm [as 别名]
# 或者: from django.contrib.comments.forms.CommentForm import as_p [as 别名]
def update_note(request, space_url):

    """
    Updated the current note with the POST data. UpdateNoteForm is an incomplete
    form that doesn't handle some properties, only the important for the note
    editing.
    """

    # Shit double validation here due to the fact that we can't get the note ID
    # until the JS code sends us the GET or POST signals
    place = get_object_or_404(Space, url=space_url)

    if request.method == "GET" and request.is_ajax():
        note = get_object_or_404(Note, pk=request.GET['noteid'])
        debate = get_object_or_404(Debate, pk=note.debate.id)

        if (request.user.has_perm('admin_space', place) or
            request.user.has_perm('mod_space', place) or
            request.user.has_perm('admin_debate', debate) or
            request.user.has_perm('mod_debate', debate) or
            request.user == note.author):

            ctype = ContentType.objects.get_for_model(Note)
            latest_comments = Comment.objects.filter(is_public=True,
                is_removed=False, content_type=ctype, object_pk=note.id) \
                .order_by('-submit_date')[:5]
            form = CommentForm(target_object=note)

            response_data = {}
            response_data['title'] = note.title
            response_data['message'] = note.message
            response_data['author'] = {'name': note.author.username}
            response_data['comments'] = [{'username': c.user.username,
                'comment': c.comment,
                'submit_date': c.submit_date} for c in latest_comments]
            response_data["form_html"] = form.as_p()

            return HttpResponse(json.dumps(response_data, cls=DjangoJSONEncoder),
                            mimetype="application/json")
        else:
            raise PermissionDenied

    if request.method == "POST" and request.is_ajax:
        note = get_object_or_404(Note, pk=request.POST['noteid'])
        debate = get_object_or_404(Debate, pk=note.debate.id)

        if (request.user.has_perm('admin_space', place) or
            request.user.has_perm('mod_space', place) or
            request.user.has_perm('admin_debate', debate) or
            request.user.has_perm('mod_debate', debate) or
            request.user == note.author):

            note_form = UpdateNoteForm(request.POST or None, instance=note)
            if note_form.is_valid():
                note_form_uncommited = note_form.save(commit=False)
                note_form_uncommited.title = request.POST['title']
                note_form_uncommited.message = request.POST['message']
                note_form_uncommited.last_mod_author = request.user

                note_form_uncommited.save()
            else:
                return HttpResponseBadRequest(_("The form is not valid, check field(s): ") + note_form.errors)
        else:
            raise PermissionDenied
    return HttpResponseBadRequest(_("Bad request"))
开发者ID:rafacouto,项目名称:e-cidadania,代码行数:67,代码来源:views.py


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