本文整理汇总了Python中django.contrib.comments.forms.CommentForm类的典型用法代码示例。如果您正苦于以下问题:Python CommentForm类的具体用法?Python CommentForm怎么用?Python CommentForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommentForm类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tamperWithForm
def tamperWithForm(self, **kwargs):
a = Article.objects.get(pk=1)
d = self.getValidData(a)
d.update(kwargs)
f = CommentForm(Article.objects.get(pk=1), data=d)
self.assertFalse(f.is_valid())
return f
示例2: ajax_comment_post
def ajax_comment_post(request):
print request.POST
try:
form = CommentForm(request.POST)
except Exception as e:
print e
print "HERE"
if form.is_valid():
form.save()
return HttpResponse("IT WORKED!")
return HttpResponse("FAIL!")
示例3: post_comment
def post_comment(request):
if request.method == 'POST':
prod_id = request.POST['object_pk']
prod = Product.objects.get(pk=prod_id)
form = CommentForm(target_object=prod, data=request.POST)
if form.is_valid():
form.save()
return redirect('store_home')
else:
form = CommentForm()
return render(request, "register.html", {'form': form})
示例4: testProfanities
def testProfanities(self):
"""Test COMMENTS_ALLOW_PROFANITIES and PROFANITIES_LIST settings"""
a = Article.objects.get(pk=1)
d = self.getValidData(a)
# Try with COMMENTS_ALLOW_PROFANITIES off
with self.settings(COMMENTS_ALLOW_PROFANITIES=False):
f = CommentForm(a, data=dict(d, comment="What a rooster!"))
self.assertFalse(f.is_valid())
# Now with COMMENTS_ALLOW_PROFANITIES on
with self.settings(COMMENTS_ALLOW_PROFANITIES=True):
f = CommentForm(a, data=dict(d, comment="What a rooster!"))
self.assertTrue(f.is_valid())
示例5: update_note
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)
示例6: testDjango12Hash
def testDjango12Hash(self):
# Ensure we can use the hashes generated by Django 1.2
a = Article.objects.get(pk=1)
d = self.getValidData(a)
content_type = d['content_type']
object_pk = d['object_pk']
timestamp = d['timestamp']
# The Django 1.2 method hard-coded here:
info = (content_type, object_pk, timestamp, settings.SECRET_KEY)
security_hash = sha_constructor("".join(info)).hexdigest()
d['security_hash'] = security_hash
f = CommentForm(a, data=d)
self.assertTrue(f.is_valid(), f.errors)
示例7: update_note
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)
示例8: testProfanities
def testProfanities(self):
"""Test COMMENTS_ALLOW_PROFANITIES and PROFANITIES_LIST settings"""
a = Article.objects.get(pk=1)
d = self.getValidData(a)
# Save settings in case other tests need 'em
saved = settings.PROFANITIES_LIST, settings.COMMENTS_ALLOW_PROFANITIES
# Don't wanna swear in the unit tests if we don't have to...
settings.PROFANITIES_LIST = ["rooster"]
# Try with COMMENTS_ALLOW_PROFANITIES off
settings.COMMENTS_ALLOW_PROFANITIES = False
f = CommentForm(a, data=dict(d, comment="What a rooster!"))
self.assertFalse(f.is_valid())
# Now with COMMENTS_ALLOW_PROFANITIES on
settings.COMMENTS_ALLOW_PROFANITIES = True
f = CommentForm(a, data=dict(d, comment="What a rooster!"))
self.assertTrue(f.is_valid())
# Restore settings
settings.PROFANITIES_LIST, settings.COMMENTS_ALLOW_PROFANITIES = saved
示例9: testValidPost
def testValidPost(self):
a = Article.objects.get(pk=1)
f = CommentForm(a, data=self.getValidData(a))
self.assertTrue(f.is_valid(), f.errors)
return f
示例10: __init__
def __init__(self, *a, **kw):
_CommentForm.__init__(self, *a, **kw)
del self.fields['name']
del self.fields['email']
del self.fields['url']
示例11: update_note
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"))
示例12: get_comment_create_data
def get_comment_create_data(self):
data = CommentForm.get_comment_create_data(self)
data.update(AuthOslCommentForm.get_comment_create_data(self))
return data
示例13: clean_honeypot
def clean_honeypot(self):
return CommentForm.clean_honeypot(self)