本文整理汇总了Python中blog.models.Comment.author_ip方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.author_ip方法的具体用法?Python Comment.author_ip怎么用?Python Comment.author_ip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Comment
的用法示例。
在下文中一共展示了Comment.author_ip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author_ip [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())
示例2: _upsert_comment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import author_ip [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)