當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。