本文整理汇总了Python中models.Comment.author方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.author方法的具体用法?Python Comment.author怎么用?Python Comment.author使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.author方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author [as 别名]
def parse_comment(self, content, wall_owner=None):
from models import Comment
remote_id = content['id'][4:]
try:
instance = Comment.objects.get(remote_id=remote_id)
except Comment.DoesNotExist:
instance = Comment(remote_id=remote_id)
comment_text = content.find('div', {'class': 'fw_reply_text'})
if comment_text:
instance.text = comment_text.text
# date
instance.date = self.parse_container_date(content)
# likes
instance.likes = self.parse_container_likes(content, 'like_count fl_l')
# author
users = content.findAll('a', {'class': 'fw_reply_author'})
slug = users[0]['href'][1:]
if wall_owner and wall_owner.screen_name == slug:
instance.author = wall_owner
else:
avatar = content.find('a', {'class': 'fw_reply_thumb'}).find('img')['src']
name_parts = users[0].text.split(' ')
user = get_object_by_slug(slug)
if user:
user.first_name = name_parts[0]
if len(name_parts) > 1:
user.last_name = name_parts[1]
user.photo = avatar
user.save()
instance.author = user
if len(users) == 2:
# this comment is answer
slug = users[1]['href'][1:]
if wall_owner and wall_owner.screen_name == slug:
instance.reply_for = wall_owner
else:
instance.reply_for = get_object_by_slug(slug)
# имя в падеже, аватара нет
# чтобы получть текст и ID родительского коммента нужно отправить:
#http://vk.com/al_wall.php
#act:post_tt
#al:1
#post:-16297716_126263
#reply:1
instance.fetched = datetime.now()
comment_parsed.send(sender=Comment, instance=instance, raw_html=str(content))
return instance
示例2: execute
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author [as 别名]
def execute(self):
invite_attendee = None
if self.invite_attendee_id:
invite_attendee = InviteAttendee.get_by_unique_id(
self.invite_attendee_id
)
invite = Invite.get_by_unique_id(self.invite_unique_id)
if invite is None:
raise InviteNotFoundException()
author = None
if invite_attendee is not None:
author = invite_attendee.name or invite_attendee.email or invite_attendee.phone
if invite.comments is None:
invite.comments = []
comment = Comment()
comment.author = author
comment.comment = self.comment
comment.commented_on = datetime.datetime.now()
invite.comments.append(comment)
invite.put()
return comment
示例3: article
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author [as 别名]
def article(request, post_id, post_name):
post = Post.posts.get_visible_post(post_id)
if not post:
raise Http404
if request.method == "POST":
comment_form = CommentForm(request.POST)
if comment_form.is_valid():
comment = Comment()
comment.author = comment_form.cleaned_data['author']
comment.post = post
comment.email = comment_form.cleaned_data['email']
comment.text = comment_form.cleaned_data['text']
comment.save()
return HttpResponseRedirect("/")
else:
# TODO SHOW ERRORS
pass
spotlighted = Project.objects.filter(related_posts=post)
comments = Comment.objects.filter(post=post)
related = TaggedItem.objects.get_related(post, Post)[:6]
comment_form = CommentForm()
return render_to_response('article.html',
{
"post": post,
"comments": comments,
"related": related,
"spotlighted": spotlighted,
"comment_form": comment_form
},
context_instance=RequestContext(request))
示例4: view_post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author [as 别名]
def view_post(request, post_id):
post = Post.get_by_id(int(post_id))
if not post:
raise Http404
if not is_admin() and not post.is_published:
raise Http404
if request.method == "POST":
comment = Comment()
comment.content = request.POST["comment"]
comment.author = users.get_current_user()
comment.post = post
if request.POST["parent_comment"] != "":
parent_comment = Comment.get_by_id(int(request.POST["parent_comment"]))
comment.parent_comment = parent_comment
comment.put()
post.comment_count = post.comment_count + 1
post.put()
mail.send_mail(
sender="[email protected]",
to=post.author.email(),
subject=(u"牛逼 - 你的文章%s有了新评论" % post.title).encode("utf8"),
body=(
u"""%s在你的文章%s上留了评论:
%s
点击这个链接回复: http://www.niubi.de/post/%s/"""
% (comment.author.nickname(), post.title, comment.content, post.key().id())
).encode("utf8"),
)
comments = Comment.all().filter("post", post)
sent_users = []
for c in comments:
if not contains_user(sent_users, c.author):
mail.send_mail(
sender="[email protected]",
to=c.author.email(),
subject=(u"牛逼 - 你参与评论的文章%s有了新评论" % post.title).encode("utf8"),
body=(
u"""%s在文章%s上留了评论:
%s
点击这个链接回复: http://www.niubi.de/post/%s/"""
% (comment.author.nickname(), post.title, comment.content, post.key().id())
).encode("utf8"),
)
sent_users.append(c.author)
return HttpResponseRedirect("/post/%s" % post.key().id())
post.read_count = post.read_count + 1
post.put()
post.getComments()
return render_to_response(
"view_post.html",
{"post": post, "is_post_author": is_post_author(post_id)},
context_instance=RequestContext(request),
)
示例5: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author [as 别名]
def post(self):
if not (session and session.get('uid')):
return jsonify({'error': 'Not logged in'})
comment = Comment(text=request.form['text'])
comment.author = User.objects(id=ObjectId(session.get('uid')))
comment.save()
node = Node.objects(id=ObjectId(request.form['nid']))[0]
nodes.comments.append(comment)
node.save(cascade=True)
return jsonify({'success':1})
示例6: post_detail
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author [as 别名]
def post_detail(request, id, showComments=False):
posts=Post.objects.get(pk=id)
comments=posts.comments.all()
if request.method =='POST':
comment=Comment(post=posts)
comment.author=request.user
form=CommentForm(request.POST,instance=comment)
if form.is_valid():
form.save()
return HttpResponseRedirect(request.path)
else:
form=CommentForm()
return render_to_response('blog/post_detail.html',{'posts':posts,'comments':comments,'form':form,'user':request.user})
示例7: view_post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author [as 别名]
def view_post(request, post_id):
post = Post.get_by_id(int(post_id))
if not post:
raise Http404
if not is_admin() and not post.is_published:
raise Http404
if request.method == 'POST':
comment = Comment()
comment.content = request.POST['comment']
comment.author = users.get_current_user()
comment.post = post
if request.POST['parent_comment'] != "":
parent_comment = Comment.get_by_id(int(request.POST['parent_comment']))
comment.parent_comment = parent_comment
comment.put()
post.comment_count = post.comment_count + 1
post.put()
mail.send_mail(sender="[email protected]",
to=post.author.email(),
subject=(u'牛逼 - 你的文章%s有了新评论'%post.title).encode('utf8'),
body=(u'''%s在你的文章%s上留了评论:
%s
点击这个链接回复: http://www.niubi.de/post/%s/''' %(comment.author.nickname(), post.title, comment.content, post.key().id())).encode('utf8')
)
comments = Comment.all().filter('post', post)
sent_users = []
for c in comments:
if not contains_user(sent_users, c.author):
mail.send_mail(sender="[email protected]",
to=c.author.email(),
subject=(u'牛逼 - 你参与评论的文章%s有了新评论'%post.title).encode('utf8'),
body=(u'''%s在文章%s上留了评论:
%s
点击这个链接回复: http://www.niubi.de/post/%s/''' %(comment.author.nickname(), post.title, comment.content, post.key().id())).encode('utf8')
)
sent_users.append(c.author)
return HttpResponseRedirect('/post/%s' % post.key().id())
post.read_count = post.read_count + 1
post.put()
post.getComments()
return render_to_response('view_post.html',
{'post':post,'is_post_author':is_post_author(post_id)}, context_instance=RequestContext(request))
示例8: add_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from 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=BlogPost.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("main_site.views.blogComments", args=[pk]))
示例9: addComment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author [as 别名]
def addComment(request):
result=urlparse.urlparse(request.POST['comment_url'])
params=urlparse.parse_qs(result.query,True)
nid=params['id']
comment = Comment()
comment.content =""
if request.POST.has_key("content"):
content = request.POST['content']
comment.content = content
if request.FILES.has_key("voice"):
voice =open(request.FILES['voice'].temporary_file_path(), "rb") # change to data from request
comment.voice = voice
comment.author = request.user
news = News.objects(pk=nid[0]).first()
news.comments = news.comments + [comment]
news.save()
return HttpResponse("success")
示例10: post_detail
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author [as 别名]
def post_detail(request, id, showComments=False):
post = Post.objects.get(pk=id)
if (request.method == 'POST'):
comment = Comment(post = post)
comment.author = request.user
form = CommentForm(request.POST, instance=comment)
if request.user.is_active:
if form.is_valid():
form.save()
return HttpResponseRedirect(request.path)
else:
return HttpResponseRedirect('reg/login.html')
else:
form = CommentForm()
comments = Comment.objects.filter(post = id).order_by('-pk')
t = loader.get_template('blog/post_detail.html')
c = Context ({ 'post' : post, 'comments' : comments, 'form' : form, 'user' : request.user })
return HttpResponse(t.render(c))
示例11: createComment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author [as 别名]
def createComment(request, blog_key):
if not current_user():
return HttpResponseRedirect(users.create_login_url('/blogs'))
form = CommentForm(request.POST)
if form.is_valid():
comment = Comment()
comment.blog = Blog.get(blog_key)
comment.author = current_user()
comment.content = form.cleaned_data['content']
comment.put()
context = Context({
'blog':comment.blog,
'comment':comment,
'admin':admin(),
})
template = loader.get_template('blogs/_comment.html')
return HttpResponse(template.render(context))
else:
return HttpResponse('')
示例12: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author [as 别名]
def post(self, album_id):
user = get_user()
if user:
album = Album.get_by_id(
int(album_id),
parent=DEFAULT_DOMAIN_KEY
)
comment = Comment(parent=album.key)
comment.text = self.request.get('comment_text')
comment.author = user.key
comment.parent = album.key
comment.put()
self.redirect('/album/%s/view' % album.key.integer_id())
else:
self.redirect_to_login()
示例13: add_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from 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))
# 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('post_detail.html', args=[pk]))
示例14: post_detail
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author [as 别名]
def post_detail(request, id, showComments = False):
post_value = Post.objects.get(pk = id)
if request.method == 'POST':
comment = Comment(post=post_value)
form = CommentForm(request.POST, instance = comment)
if form.is_valid():
comment.author = str(request.user)
form.save()
return HttpResponseRedirect(request.path)
else:
form = CommentForm()
if showComments != False:
comment = Comment.objects.filter(post_id=id)
tt = loader.get_template('blog/post_detail.html')
cc = Context({'comments': comment})
else:
pass
return render_to_response('blog/post_detail.html',{'post': post_value, 'comments':comment, 'form' : form, 'user' : str(request.user)})
示例15: post_detail
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author [as 别名]
def post_detail(request, id, showComments=False):
post=Post.objects.get(pk=id)
if request.method == 'POST':
comment = Comment(post=post)
comment.author=request.session['username']
form = CommentForm(request.POST,instance=comment)
if form.is_valid():
form.save()
return HttpResponseRedirect(request.path)
else:
form = CommentForm()
me=post.comment_set.all()
t=loader.get_template('blog/post_detail.html')
if showComments is None:
c=Context({'post':post,})
return HttpResponse(t.render(c))
else:
c=Context({'post':post,'comments':me,'form' : form, 'user':request})
return HttpResponse(t.render(c))