本文整理汇总了Python中blog.models.Comment.author方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.author方法的具体用法?Python Comment.author怎么用?Python Comment.author使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Comment
的用法示例。
在下文中一共展示了Comment.author方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: view_entry
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def view_entry(request, e_id):
""" View Entry """
entry = Entry.objects.get(id=e_id)
entry.parsed_content = mark_safe(entry.content) #bbcode.render_html(entry.content)
msg = ''
if(request.method == 'POST'):
user_data= {'author': request.POST['author'] , 'email': request.POST['email'], 'message': request.POST['message'],'captcha': request.POST['captcha'] }
#check captcha
code = request.session['captcha_code']
if(request.user.is_authenticated()):
#user auth witrh external account
user_data['author'] = '%s %s '%(request.user.first_name, request.user.last_name )
if(request.session['backend'] == 'twitter'):
user_data['author'] += '(@%s)'%(request.user.username)
else:
user_data['author'] +='(%s)'%(request.session['backend'])
if(request.user.email == ''):
user_data['email'] = '[email protected]'#request.user.email
else:
user_data['email'] = request.user.email
logout(request)
cf = CommentForm(user_data)
if(cf.is_valid()):
#Check Captcha
if(''.join(code) == str.strip(str(request.POST['captcha'].upper()))):
#save comment
com = Comment()
com.author = cf.cleaned_data['author']
com.content = cf.cleaned_data['message']
com.email = cf.cleaned_data['email']
com.entry = entry
try:
com.save()
msg = 'Comment posted succesfully. Thanks.!'
except:
msg = 'Error saving your comment. Please try again.'
else:
msg = 'Wrong Captcha code. Please Try Again'
else:
msg = 'Error processing your comment. Please Try Again.'
request.session['comment_posted_msg'] = msg
return redirect('/blog/article/%s'%(e_id))#TODO put marker here to go to specific part of the html
if('comment_posted_msg' in request.session):
msg= request.session['comment_posted_msg']
del request.session['comment_posted_msg']
comments = entry.comment_set.filter(status=True)
cf = CommentForm()
t = get_template("entry.htm")
c = RequestContext(request, {'entry': entry,'comments': comments, 'cform': cf, 'rn': random.randint(1,999999), 'msg': msg})
return HttpResponse(t.render(c))
示例2: handle
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def handle(self, *args, **options):
print 'start'
Comment.objects.all().delete()
Post.objects.all().delete()
Topic.objects.all().delete()
t = Topic()
t.name = 'Angular'
t.save()
for i in range(0,10):
p = Post()
p.topic = t
p.title = 'First post %s' % i
p.content = 'Content of the first post'
p.save()
t = Topic()
t.name = 'Python'
t.save()
for i in range(0,20):
p = Post()
p.topic = t
p.title = 'Second post %s ' % i
p.content = 'Content of the second post'
p.save()
for i in range(0,20):
c = Comment()
c.author = 'Jim Morrison'
c.content = ' #%s Very nice article. Thank you very much!!!' % i
c.post = p
c.save()
print 'done'
示例3: add_comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def add_comment(request, slug):
"""Add a new comment."""
p = request.POST
post = Post.objects.get(slug=slug)
author_ip = get_ip(request)
if p.has_key("body") and p["body"]:
author = "Anonymous"
if p["author"]:
author = p["author"]
comment = Comment(post=post)
cf = CommentForm(p, instance=comment)
cf.fields["author"].required = False
comment = cf.save(commit=False)
comment.author = author
comment.author_ip = author_ip
comment.save()
messages.success(
request, "Thank you for submitting a comment. It will appear once reviewed by an administrator."
)
else:
messages.error(request, "Something went wrong. Please try again later.")
return HttpResponseRedirect(post.get_absolute_url())
示例4: post
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def post(self, request, *args, **kwargs):
comment_form = CommentForm(data=request.POST)
if comment_form.is_valid():
comment = Comment()
comment.author = request.user
comment.comment = comment_form.cleaned_data['comment']
comment.post = self.get_post(**kwargs)
comment.save()
return self.get(request, *args, **kwargs)
else:
return self.get(request, *args, **kwargs)
示例5: add_comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def add_comment(request, postslug):
p = request.POST
if p["body"]:
author = request.user
comment = Comment(post=Post.objects.get(slug=postslug))
cf = CommentForm(p, instance=comment)
cf.fields["author"].required = False
comment = cf.save(commit=False)
comment.author = author
comment.save()
return HttpResponseRedirect('/blog/')
示例6: comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def comment(request, article_id):
if not request.POST['author'] or not request.POST['text']:
request.message = "vous avez oubliez une partie du commentaire non?"
return detail(request, article_id)
else:
request.message = "commentaire enregistre!"
comment = Comment()
comment.author=request.POST['author']
comment.text = request.POST['text']
comment.date = timezone.now()
comment.article = Article.objects.get(id = article_id)
comment.save()
return detail(request, article_id)
示例7: _upsert_comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def _upsert_comment(comment):
"""
操作类型:
create:创建评论
approve:通过评论
spam:标记垃圾评论
delete:删除评论
delete-forever:彻底删除评论
"""
action = comment.get('action', '')
meta = comment.get('meta', None)
if meta and isinstance(meta, dict):
from blog.models import Article, Comment
a_id = meta.get('thread_key')
try:
if action == 'create':
try:
article = Article.objects.get(id=int(a_id))
except (Article.DoesNotExist, TypeError, ValueError) as e:
print 'Article does not exist, ID: %s, error: %s' % (a_id, e)
return
c = Comment()
c.article = article
parent_id = meta.get('parent_id', '0')
parent_c = Comment.objects.filter(duoshuo_id=parent_id)
c.parent = None if parent_id == '0' or parent_c.count() == 0 else parent_c[0]
c.duoshuo_id = meta.get('post_id', '')
c.duoshuo_user_id = comment.get('user_id', '')
c.author = meta.get('author_name', '')
c.author_email = meta.get('author_email', '')
c.author_website = meta.get('author_url', '')
c.author_ip = meta.get('ip', '')
c.comment_date = timestamp2datetime(comment.get('date', None), convert_to_local=True) or datetime.datetime.now()
c.content = _clean_content(meta.get('message', ''))
c.author_agent = ''
status = meta.get('status', '')
c.status = COMMENT_STATUS.APPROVED if status == 'approved' else (COMMENT_STATUS.NOT_REVIEWED if status == 'pending' else COMMENT_STATUS.REJECTED)
c.sync_status = 0
c.save()
print 'Create comment, article ID: %s, comment ID: %s' % (a_id, c.id)
elif action == 'approve':
Comment.objects.filter(duoshuo_id__in=meta).update(status=COMMENT_STATUS.APPROVED)
elif action == 'spam':
Comment.objects.filter(duoshuo_id__in=meta).update(status=COMMENT_STATUS.REJECTED)
elif action in ('delete', 'delete-forever'):
Comment.objects.filter(duoshuo_id__in=meta).update(hided=True, status=COMMENT_STATUS.REJECTED)
except Exception, e:
print 'update article comment failed, exception: %s, comment: %s' % (e, comment)
示例8: add_comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def add_comment(request, pk):
"""Add a new comment to a given post"""
p = request.POST
if p.has_key("body") and p["body"]:
author = p.get("author", "Anonymous")
comment = Comment(post=get_object_or_404(Post, pk=pk))
cf = CommentForm(p, instance=comment)
cf.fields["author"].required = False
comment = cf.save(commit=False)
comment.author = author
comment.save()
return HttpResponseRedirect(reverse(post, args=(pk,)))
示例9: add_comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def add_comment(request, pk):
"""Add a new comment."""
p = request.POST
if p.has_key("body") and p["body"]:
author = "Anonymous"
if p["author"]: author = p["author"]
comment = Comment(post=Post.objects.get(pk=pk))
cf = CommentForm(p, instance=comment)
cf.fields["author"].required = False
comment = cf.save(commit=False)
comment.author = author
comment.save()
return HttpResponseRedirect('/blog/%s' %pk)
示例10: add_comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def add_comment(request, pk):
"""Add a new comment."""
p = request.POST
# p.has_key("body") is deprecated ?
if p["body"]:
author = "Anonymous"
if p["author"]: author = p["author"]
comment = Comment(post=Post.objects.get(pk=pk))
cf = CommentForm(p, instance=comment)
cf.fields["author"].required = False
comment = cf.save(commit=False)
comment.author = author
comment.save()
return HttpResponseRedirect(reverse("blog.views.post", args=[pk]))
示例11: add_comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def add_comment(request, slug):
"""Add a new comment."""
#print("looool")
p = request.POST
if p["content"]:
author = "Anonymous"
if p["author"]: author = p["author"]
comment = Comment(post=Post.objects.get(slug=slug))
cf = CommentForm(p, instance=comment)
cf.fields["author"].required = False
comment = cf.save(commit=False)
comment.author = author
comment.save()
return HttpResponseRedirect(reverse("blog.views.post", args=[slug]))
示例12: add_comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def add_comment(request, pk):
p = request.POST
if p.has_key("body") and p["body"]:
author = "Anonymous"
if p["author"]: author = p["author"]
comment = Comment(post=Post.objects.get(pk=pk))
cf = CommentForm(p, instance=comment)
cf.fields["author"].required = False
comment = cf.save(commit=False)
comment.author = author
notify = True
if request.user.username == "nasa":
notify = False
comment.save(notify=notify)
return HttpResponseRedirect(reverse('post:post', args=(pk, )))
示例13: add_comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def add_comment(request, pk):
"""
Add a new comment. Code adapted from http://lightbird.net/dbe/blog.html
"""
p = request.POST
if p.has_key("body") and p["body"]:
author = "Anonymous"
if p["author"]: author = p["author"]
comment = Comment(post=Post.objects.get(pk=pk))
# save comment form
cf = CommentForm(p, instance=comment)
cf.fields["author"].required = False
comment = cf.save(commit=False)
# save comment instance
comment.author = author
notify = True
if request.user.username == "ak": notify = False
comment.save(notify=notify)
return HttpResponseRedirect(reverse("blog.views.post", args=[pk]))
示例14: add_comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def add_comment(request, pk):
p = request.POST
#print p
"""output: <QueryDict: {u'body': [u'good eats'], u'csrfmiddlewaretoken': [u'F4ioZcjG9UQQlYzBVQWKAnhOdRavY2Wa'], u'author': [u'salin']}>"""
if p.has_key("body") and p["body"]:
author = "Anonymous"
if p["author"]:
author = p["author"]
""" Create a form to edit an existing Comment """
comment = Comment(title=Post.objects.get(pk=pk))
""" Create a form to edit an existing Comment, but use POST data to populate the form. """
form_comment = CommentForm(p, instance=comment)
form_comment.fields["author"].required = False
""" Create, but don't save the new author instance. """
comment = form_comment.save(commit=False)
""" Modify the author in some way."""
comment.author = author
""" Comment Notification. """
notify = True
if comment.author == "salin":
notify = False
""" Save the new instance."""
comment.save(notify=notify)
return HttpResponseRedirect(reverse("post", args=[pk]))
#d = {'test': comment}
#return render_to_response("blog/test.html", d)
else:
html ="<html><body>Invalid Form!</body></html>"
return HttpResponse(html)
示例15: entry
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author [as 别名]
def entry(request, blog_slug):
"""
Defines the page of a single blog entry.
Finds the entry based on its slugified title, passed in by blog_slug.
"""
the_entry = get_object_or_404(Entry, slug=blog_slug)
tags = Tag.objects_by_entry_count.all()
comment_form = CommentForm()
if request.method == "POST":
new_comment = Comment()
new_comment.content = request.POST["content"]
new_comment.author = request.user
new_comment.published = datetime.now()
new_comment.associated_with = the_entry
new_comment.save()
return render(request, "individual_blog.html", {
"entry": the_entry,
"comment_form": comment_form,
"tags": tags
})