本文整理汇总了Python中models.Comment.content方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.content方法的具体用法?Python Comment.content怎么用?Python Comment.content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.content方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: teamProfile
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [as 别名]
def teamProfile(teamId):
if current_user.team:
if int(teamId) == int(current_user.team_id):
return redirect(url_for('team_page'))
form = CommentForm()
team = db.session.query(Team).filter(Team.id == teamId).first()
comments = db.session.query(Comment).filter(Comment.idea_id == team.idea.id).all()
if not team:
flash('Team '+teamId+' not found.', 'error')
return redirect(url_for('home'))
else:
if form.validate_on_submit():
comment = Comment()
comment.content = form.comment.data
team.idea.comment.append(comment)
current_user.comment.append(comment)
db.session.add(comment)
for member in comment.idea.team.members:
notif = PersonalNotification()
notif.content = current_user.username + " commented on your team's idea."
member.notification.append(notif)
db.session.commit()
return render_template('team_view.html', form=form, team=team, comments=comments)
return render_template('team_view.html', form=form, team=team, comments=comments)
示例2: save_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [as 别名]
def save_comment(request):
"""保存评论"""
article_id = request.POST.get("article_id", "").strip()
try:
_int_article_id = int(article_id)
except Exception:
return HttpResponseRedirect("/")
username = request.POST.get("username", "").strip()
content = request.POST.get("content", "").strip()
if len(username) < 4 or len(content) < 4:
return HttpResponseRedirect("/")
comment = Comment()
comment.blog = Blog.objects.get(id=_int_article_id)
comment.blog.comment_times += 1
comment.blog.save()
comment.submit_name = username
comment.content = content
comment.ip = gcommon.get_remote_addr(request) # request.META['REMOTE_ADDR']
comment.save()
return HttpResponseRedirect("/blog/%d.html" % _int_article_id)
示例3: view_post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [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),
)
示例4: addComment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [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")
示例5: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [as 别名]
def post(self):
yeller_id = str(self.request.params.get('yeller_id'))
User_email = self.request.params.get("User_email")
comment = self.request.params.get("comment")
yeller = Yeller.query(Yeller.key_id==yeller_id).fetch(1)[0]
new_comment = Comment(author = User_email)
new_comment.content = comment
new_comment_key = new_comment.put()
yeller.comment.append(new_comment)
yeller.put()
示例6: view_post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [as 别名]
def view_post(id):
form = request.forms
if form.update_comment :
post = Post.get(id=id)
comment = Comment()
comment.post = post # current post
comment.user = User.get(username=form.username)
comment.content = form.content
comment.pub_date = datetime.now()
comment.save()
redirect('/view/post/%d' %(id,))
else :
post = Post.get(id=id)
comments = Comment.filter(post__id = id)
return template('templates/post.html.tpl',post=post,comments=comments)
示例7: view_post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [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: postComment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [as 别名]
def postComment(article_id):
article = Article.get_by_id(article_id)
if not article:
return "", 404, {"Content-Type": "application/json"}
data = request.get_json()
if not data:
return "Missing data", 400
comment = Comment()
comment.article = article.key
comment.author_name = escape(data.get("author_name"))
comment.author_email = escape(data.get("author_email"))
comment.content = escape(data.get("content"))
comment.put()
comments = Comment.query().order(Comment.date).fetch(keys_only=True)
if len(comments) >= 10:
comments[0].delete()
return serialize(comment)
示例9: createComment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [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('')
示例10: blog
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [as 别名]
def blog(request, blogid):
try:
article = Blog.objects.get(id=blogid)
article.visit_times += 1
article.save()
except Blog.DoesNotExist:
return HttpResponseRedirect('/')
page = request.GET.get('page', '1')
try:
page_num = int(page)
except:
page_num = 1
qs = article.comment_set.all().order_by('id')
html_dict = {'article': article,}
db_tools.get_category_latelyblogs(html_dict)
#分页
PAGE_MSG_NUM = 10
split_dict = gcommon.split_page(request, page_num, PAGE_MSG_NUM, qs)
html_dict.update(split_dict)
username = request.POST.get('username', '').strip()
content = request.POST.get('content', '').strip()
if not username and not content:
return render_to_response('blog/article.html', html_dict, context_instance=RequestContext(request))
if len(username) < 4 or len(content) < 4:
html_dict['remind_msg'] = u'名称和内容不能少于4个字符'
return render_to_response('blog/article.html', html_dict, context_instance=RequestContext(request))
comment = Comment()
comment.blog = Blog.objects.get(id=blogid)
comment.blog.comment_times += 1
comment.blog.save()
comment.submit_name = username
comment.content = content
comment.ip = gcommon.get_remote_addr(request) #request.META['REMOTE_ADDR']
comment.save()
return render_to_response('blog/article.html', html_dict, context_instance=RequestContext(request))
示例11: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [as 别名]
def post(id):
post = Post.query.get_or_404(id)
form = forms.CommentForm()
if request.method=='POST':
comment = Comment()
comment.content = form.content.html
comment.user_id = current_user.id
comment.post_id = id
comment.time_stamp = datetime.now()
db.session.add(comment)
db.session.commit()
return redirect(url_for('.post',id=id,page=-1))
page = request.args.get('page',1,type=int)
if page==-1:
page = (post.comments.count() - 1) / COMMENTS_PER_PAGE + 1
comments = post.comments.order_by(Comment.time_stamp.asc()).paginate(page,COMMENTS_PER_PAGE,False)
Post.query.filter(Post.id==id).update({Post.view_times:Post.view_times+1})
return render_template('post.html',post=post,comments=comments,form=form)
示例12: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [as 别名]
def post(self, title):
post = yield Post.asyncQuery(title=title).first()
if not post:
raise tornado.web.HTTPError(404)
if self.form.validate():
comment = Comment()
comment.create_time = datetime.datetime.utcnow()
comment.author_name = self.form.author_name.data
comment.author_email = self.form.author_email.data
comment.author_url = self.form.author_url.data
# Direct use user post data is unsafe,
# so we convert `org_markdown_text` in the back-end
comment.content = markdown2.markdown(self.form.content.data)
post.comments.append(comment)
yield post.save()
self.flash("评论提交成功~")
return self.redirect("{path}{id}".format(
path=self.request.path, id="#comment"))
self.render("post.html", post=post, form=self.form)
示例13: addcomment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [as 别名]
def addcomment(request):
error_msg = u"No POST data sent."
print 'addcomment called'
if request.method == "POST":
post = request.POST.copy()
if post.has_key('content') and post.has_key('id'):
try:
iid = post['id']
ideas = Idea.objects(id=iid)
if(len(ideas) >0):
idea = ideas[0]
comment = Comment()
comment.content = post['content']
if not comment.content or comment.content.strip()=="":
return HttpResponseRedirect('/')
comment.author = str(request.user)
idea.comments.append(comment)
incrementStat('comments',1)
person = getPerson(request)
if person:
person.lastActive = datetime.datetime.now()
person.timesCommented = person.timesCommented + 1
rating = Score.objects(type='comment')[0].value
person.currentRating = person.currentRating + rating
person.save()
idea.save()
try:
t = ThreadClass(comment.author+" has commented on your idea: '"+idea.title+"'", comment.author+" commented: '"+comment.content+"'",[idea.email])
t.start()
except Exception as inst:
print 'exception sending email '+str(inst)
return HttpResponseRedirect('/')
except Exception as inst:
return HttpResponseServerError('wowza! an error occurred, sorry!</br>'+str(inst))
else:
print 'didnt comment, no data'
return HttpResponseRedirect('/')
# error_msg = u"Insufficient POST data (need 'slug' and 'title'!)"
return HttpResponseServerError(error_msg)
示例14: save_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [as 别名]
def save_comment():
msg = "Comment not saved."
try:
nome = request.form['name']
email = request.form['email']
texto = request.form['content']
post_id = request.form['post_id']
comentario = Comment()
comentario.name = nome
comentario.email = email
comentario.content = texto
comentario.display = False
comentario.date_created = datetime.today()
comentario.post_id = post_id
db.session.add(comentario)
db.session.commit()
msg = "Comentário enviado! Obrigado!"
except:
db.session.rollback()
traceback.print_exc()
#raise
data = {}
data['message'] = msg
return jsonify(data)
示例15: comment_idea
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import content [as 别名]
def comment_idea(idea_id):
form = CommentForm()
idea = db.session.query(Idea).filter(Idea.id == idea_id).first()
team = db.session.query(Team).filter(Team.id == idea.team_id).first()
if form.validate_on_submit():
if idea:
comment = Comment()
comment.content = form.comment.data
idea.comment.append(comment)
current_user.comment.append(comment)
db.session.add(comment)
for member in comment.idea.team.members:
notif = PersonalNotification()
notif.content = current_user.username + " commented on your team's idea."
member.notification.append(notif)
db.session.commit()
return redirect(url_for('teamProfile', teamId=team.id))
else:
flash("Idea does not exist.", "error")
return redirect(url_for('all_ideas'))
return render_template('comment_idea.html', form=form, idea_id=idea_id, team=team)