本文整理汇总了Python中models.Comment.create方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.create方法的具体用法?Python Comment.create怎么用?Python Comment.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_with_comments
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import create [as 别名]
def create_with_comments(submissions_and_comments, db) :
# Print all the submissions
for s in submissions_and_comments:
create(s, db)
# You can get an unordered list of all comments flattened out with praw.helpers.flatten_tree(x.comments)
for c in s['comments']:
Comment.create(c, db)
示例2: ajax_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import create [as 别名]
def ajax_comment():
Comment.create(
user_id=session["user_id"],
message_id=int(request.form['message_id']),
content=request.form['comment_text']
)
comment = Comment.get(Comment.content == request.form["comment_text"])
comment_info = session['first_name'] + " " + session['last_name'] + " - "
comment_info += comment.created_at.strftime("%B %d %Y")
comment_dict = {
"comment": comment.content,
"comment_info": comment_info,
}
return jsonify(comment_dict)
示例3: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import create [as 别名]
def post(self):
postid = self.get_argument('comment_post_ID')
author = self.get_argument('author',None)
email = self.get_argument('email',None)
url = self.get_argument('url',None)
comment = self.get_argument('comment',None)
parent_id = self.get_argument('comment_parent',None)
if postid:
post = Post.get(id=int(postid))
if author and email and comment:
if len(author) >18:
self.flash('UserName is too long.')
return self.redirect("%s#respond"%(post.url))
if not _email_re.match(email):
self.flash(u'Email address is invalid.')
return self.redirect("%s#respond"%(post.url))
if url and not _url_re.match(url):
self.flash(u'website is invalid.')
return self.redirect("%s#respond"%(post.url))
comment = Comment.create(post=post,ip=self.request.remote_ip,
author=author,email=email,website=url,
content=comment,parent_id=parent_id)
self.set_cookie('comment_author',author)
self.set_cookie('comment_email',email)
self.set_cookie('comment_website',url)
return self.redirect(comment.url)
else:
self.flash(u"请填写必要信息(姓名和电子邮件和评论内容)")
return self.redirect("%s#respond"%(post.url))
示例4: process_comments
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import create [as 别名]
def process_comments(post_id):
"""process the comments the users entered """
content = request.form.get('comment')
user_id = session.get('loggedin', None)
if user_id:
user = User.get_user_by_id(user_id)
user_name = user.user_name
user_pic = user.profile_pic
new_comment = Comment.create(content=content, user_id=user_id, post_id=post_id)
comment_id = new_comment.comment_id
comment_timestamp = new_comment.timestamp
has_delete_button = user_id == new_comment.user_id
return jsonify(user_id=user_id, user_name=user_name, user_pic=user_pic, content=content,
has_delete_button=has_delete_button, comment_id=comment_id, comment_timestamp=comment_timestamp)
else:
return jsonify(user_id="undefined")
示例5: post_new_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import create [as 别名]
def post_new_comment():
postid = request.forms.get('postid')
name = request.forms.get('name').decode('utf-8')
email = request.forms.get('email').decode('utf-8')
url = request.forms.get('url').decode('utf-8')
content = request.forms.get('content').decode('utf-8')
parent = request.forms.get('parentid')
check = request.forms.get('check')
if check != "123456":
post = Post.get(id=postid)
redirect("/%s" % post.slug)
post = Post.get(id=postid)
post.comm_count = post.comm_count + 1
comment = Comment.create(post=post, author=escape(name),
email=escape(email), url=escape(url),
content=escape(content), parent=parent,
published=datetime.datetime.now())
post.save()
redirect("/%s#comment-%s" % (post.slug, comment.id))
示例6: POST
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import create [as 别名]
def POST(self):
if session.login == False:
return bad_request('请先登录')
data = web.data()
data = json.loads(data)
art_id = data.get('art_id')
user_id = session.user.id
content = data.get('content')
comment_data = {
'comment_time' : time.time(),
'art_id' : art_id,
'use_id' : user_id,
'content' : content,
}
try:
comment_id = Comment.create(**comment_data)
except Exception,e:
return bad_request('评论出现异常错误,稍后再试!')