本文整理汇总了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)
示例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)
示例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"))