本文整理汇总了Python中model.Comment类的典型用法代码示例。如果您正苦于以下问题:Python Comment类的具体用法?Python Comment怎么用?Python Comment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Comment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_comment
def add_comment():
comment = request.form.get("comment")
question_id = request.form.get("question_id")
question_info = Question.query.get(question_id)
question_author = User.query.filter(User.user_id == question_info.user_id).first()
date_string = datetime.today().strftime('%Y-%m-%d')
commented_item = Comment(user_id = session["user_id"], comment_timestamp = date_string, question_id = question_id, comment = comment)
db.session.add(commented_item)
db.session.commit()
comment_author = User.query.filter(User.user_id == commented_item.user_id).first()
comment_auth_image = comment_author.images[0]
result = {'comment_id': commented_item.comment_id,
'vote': commented_item.vote_count(),
'comment_author': comment_author.username,
'comment_auth_image':comment_auth_image.image,
'comment_timestamp': commented_item.comment_timestamp,
'user_id': comment_author.user_id}
notify_author_comment(commented_item.comment, question_author.email, question_author.username, question_info.question, question_info.title_question, comment_author.username)
return jsonify(result)
示例2: post
def post(self, id=""):
act = self.get_argument("act", "")
if act == "findid":
eid = self.get_argument("id", "")
self.redirect("%s/admin/comment/%s" % (BASE_URL, eid))
return
tf = {"true": 1, "false": 0}
post_dic = {
"author": self.get_argument("author"),
"email": self.get_argument("email", ""),
"content": safe_encode(self.get_argument("content").replace("\r", "\n")),
"url": self.get_argument("url", ""),
"visible": self.get_argument("visible", "false"),
"id": id,
}
post_dic["visible"] = tf[post_dic["visible"].lower()]
if MYSQL_TO_KVDB_SUPPORT:
obj = Comment.get_comment_by_id(id)
for k, v in obj.items():
if k not in post_dic:
post_dic[k] = v
Comment.update_comment_edit(post_dic)
clear_cache_by_pathlist(["post:%s" % id])
self.redirect("%s/admin/comment/%s" % (BASE_URL, id))
return
示例3: post
def post(self, postId):
post = Post.get_post_by_id(postId)
if not post or post.status != 0 or post.commentstatus == 1:
self.write('抱歉,评论功能已关闭。')
else:
username = self.get_argument('username', '')
email = self.get_argument('email', '')
content = self.get_argument('comment', '')
parentid = int(self.get_argument('parentid', 0))
if self.islogin:
curr_user_info = self.get_current_user_info
username = curr_user_info.username
email = curr_user_info.email
if username == '' or content == '' or not isemail(email):
self.flash(u'错误:称呼、电子邮件与内容是必填项')
self.redirect(post.url + '#comments')
return
username = username[:20]
content = content[:512]
if not self.islogin:
is_spam = spam_check(content, self.request.remote_ip)
else:
is_spam = 0
if is_spam:
self.flash(u'sorry,your comment is not posted')
self.redirect(post.url+'#comments')
location = get_location_byip(self.request.remote_ip)
Comment.post_comment(postid=postId, username=username, email=email, content=content, parentid=parentid,
ip=self.request.remote_ip, isspam=is_spam, location=location)
if is_spam:
self.flash(u'您的评论可能会被认定为Spam')
self.set_comment_user(username, email)
self.redirect(post.url + '#comments')
示例4: api_comments
def api_comments(*, page='1'):
page_index = get_page_index(page)
num = yield from Comment.findNumber('count(id)')
p = Page(num, page_index)
if num == 0:
return dict(page=p, comments=())
comments = yield from Comment.findAll(orderBy='created_at desc', limit=(p.offset, p.limit))
return dict(page=p, comments=comments)
示例5: get
def get(self):
page = int(self.get_argument('page', 1))
if self.get_argument('act', '') == 'delete':
Comment.delete_comment_by_id(int(self.get_argument('id', 0)))
pagesize = 20
rtn = Comment.get_comments(pagesize=pagesize)
self.datamap['comments'] = rtn[1]
self.datamap['count'] = rtn[0]
self.datamap['pagecount'] = int(math.ceil(float(rtn[0]) / pagesize))
self.write(render_admin.comment(self.datamap))
示例6: api_create_comment
def api_create_comment(id, request, *, content):
user = request.__user__
if user is None:
raise APIPermissionError('Please signin first.')
if not content or not content.strip():
raise APIValueError('content')
blog = yield from Blog.find(id)
if blog is None:
raise APIResourceNotFoundError('Blog')
comment = Comment(blog_id=blog.id, user_id=user.id, user_name=user.name, user_image=user.image, content=content.strip())
yield from comment.save()
return comment
示例7: api_craete_commnet
def api_craete_commnet(id, request, content):
if not id or not id.strip():
raise APIValueError('id','empty id')
if not content or not content.strip():
raise APIValueError('content','empty content')
commnet = Comment(blog_id=id, user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, content=content)
yield from commnet.save()
r = aiohttp.web.Response()
r.content_type = 'application/json'
r.body = json.dumps(commnet,ensure_ascii=False).encode('utf-8')
return r
示例8: post
def post(self):
if self.user.state == UserState.PROPOSED:
proposal_key_str = self.request.get('proposal_key_str')
proposal_key = ndb.Key(urlsafe=proposal_key_str)
content = self.request.get('content')
Comment.create_comment(proposal_key, self.user.username, content)
comments = proposal_key.get().get_comments()
comments_rendered = ''
for comment in comments:
comments_rendered += self.render_str('comment.html', comment=comment)
self.write(comments_rendered)
else:
self.abort(400)
示例9: post
def post(self,page):
code=page.param("code")
OptionSet.setValue("Akismet_code",code)
rm=page.param('autorm')
if rm and int(rm)==1:
rm=True
else:
rm=False
oldrm = OptionSet.getValue("Akismet_AutoRemove",False)
if oldrm!=rm:
OptionSet.setValue("Akismet_AutoRemove",rm)
spam=page.param("spam")
spam = len(spam)>0 and int(spam) or 0
sOther = ""
if spam>0:
cm = Comment.get_by_id(spam)
try:
url = Blog.all().fetch(1)[0].baseurl
self.SubmitAkismet({
'user_ip' : cm.ip,
'comment_type' : 'comment',
'comment_author' : cm.author.encode('utf-8'),
'comment_author_email' : cm.email,
'comment_author_url' : cm.weburl,
'comment_content' : cm.content.encode('utf-8')
},url,"Spam")
sOther = u"<div style='padding:8px;margin:8px;border:1px solid #aaa;color:red;'>评论已删除</div>"
cm.delit()
except:
sOther = u"<div style='padding:8px;margin:8px;border:1px solid #aaa;color:red;'>无法找到对应的评论项</div>"
return sOther + self.get(page)
示例10: get
def get(self, name = ''):
objs = Tag.get_tag_page_posts(name, 1)
catobj = Tag.get_tag_by_name(name)
if catobj:
pass
else:
self.redirect(BASE_URL)
return
allpost = catobj.id_num
allpage = allpost/EACH_PAGE_POST_NUM
if allpost%EACH_PAGE_POST_NUM:
allpage += 1
output = self.render('index.html', {
'title': "%s - %s"%( catobj.name, SITE_TITLE),
'keywords':catobj.name,
'description':SITE_DECR,
'objs': objs,
'cats': Category.get_all_cat_name(),
'tags': Tag.get_hot_tag_name(),
'page': 1,
'allpage': allpage,
'listtype': 'tag',
'name': name,
'namemd5': md5(name.encode('utf-8')).hexdigest(),
'comments': Comment.get_recent_comments(),
'links':Link.get_all_links(),
},layout='_layout.html')
self.write(output)
return output
示例11: get
def get(self, name = ''):
objs = Category.get_cat_page_posts(name, 1)
catobj = Category.get_cat_by_name(name)
if catobj:
pass
else:
self.redirect(BASE_URL)
return
allpost = catobj.id_num
allpage = allpost/EACH_PAGE_POST_NUM
if allpost%EACH_PAGE_POST_NUM:
allpage += 1
output = self.render('index.html', {
'title': "%s - %s"%( catobj.name, getAttr('SITE_TITLE')),
'keywords':catobj.name,
'description':getAttr('SITE_DECR'),
'objs': objs,
'cats': Category.get_all_cat_name(),
'tags': Tag.get_hot_tag_name(),
'archives': Archive.get_all_archive_name(),
'page': 1,
'allpage': allpage,
'listtype': 'cat',
'name': name,
'namemd5': md5(name.encode('utf-8')).hexdigest(),
'comments': Comment.get_recent_comments(),
'links':Link.get_all_links(),
'isauthor':self.isAuthor(),
'Totalblog':get_count('Totalblog',NUM_SHARDS,0),
},layout='_layout.html')
self.write(output)
return output
示例12: post
def post(self):
# this method is reserved for AJAX call to this object
# json response
result = {'message': ""}
comment_id = self.request.POST.get("comment_id", "")
operation = self.request.POST.get("operation", "")
logging.info("CommentManager, post data: comment_id = %s, operation = %s" % (comment_id, operation))
if comment_id:
comment = Comment.get_by_id(long(comment_id))
if comment:
if operation == "delete":
# update entry.commentcount
comment.entry.commentcount -= 1
comment.entry.put()
# delete this comment
comment.delete()
result['message'] = "comment '%s' has been deleted" % (comment_id)
else:
result['message'] = "unknown operation %s" % (operation)
else:
result['message'] = "unknown comment id %s" % (comment_id)
else:
result['message'] = "empty comment id"
json_response = json.encode(result)
logging.info("json response: %s" % (json_response))
self.response.content_type = "application/json"
return self.response.out.write(json_response)
示例13: api_delete_comments
def api_delete_comments(id, request):
check_admin(request)
c = yield from Comment.find(id)
if c is None:
raise APIResourceNotFoundError('Comment')
yield from c.remove()
return dict(id=id)
示例14: post
def post(self, post_id):
post_id = int(post_id)
post = Post.id(post_id)
if not post:
#TODO 404
return
pdict = self.request.POST
nickname = pdict.get("author")
email = pdict.get("email")
website = pdict.get("url")
comment = pdict.get("comment")
logging.info(website)
#def new(cls, belong, nickname, email, author=None, re=None, ip=None, website=None, hascheck=True, commenttype=CommentType.COMMENT):
try:
c = Comment.new(belong=post,
nickname=nickname,
email=email,
website=website,
content=comment,
ip=self.request.client_ip)
except Exception, ex:
logging.info(traceback.format_exc())
示例15: update_basic_info
def update_basic_info(
update_categories=False,
update_tags=False,
update_links=False,
update_comments=False,
update_archives=False,
update_pages=False):
from model import Entry,Archive,Comment,Category,Tag,Link
basic_info = ObjCache.get(is_basicinfo=True)
if basic_info is not None:
info = ObjCache.get_cache_value(basic_info.cache_key)
if update_pages:
info['menu_pages'] = Entry.all().filter('entrytype =','page')\
.filter('published =',True)\
.filter('entry_parent =',0)\
.order('menu_order').fetch(limit=1000)
if update_archives:
info['archives'] = Archive.all().order('-year').order('-month').fetch(12)
if update_comments:
info['recent_comments'] = Comment.all().order('-date').fetch(5)
if update_links:
info['blogroll'] = Link.all().filter('linktype =','blogroll').fetch(limit=1000)
if update_tags:
info['alltags'] = Tag.all().order('-tagcount').fetch(limit=100)
if update_categories:
info['categories'] = Category.all().fetch(limit=1000)
logging.debug('basic_info updated')
basic_info.update(info)