本文整理汇总了Python中models.Comment.key方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.key方法的具体用法?Python Comment.key怎么用?Python Comment.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import key [as 别名]
def post(self, post_id):
comm_content = self.request.get('comment')
if not comm_content:
return
cid = self.request.get('comment_id')
if cid:
comment = Comment.by_id(cid)
if comment:
if self.user.key().id() == comment.author:
comment.content = comm_content
comment.put()
else:
return self.error(404)
else: # when cid does not exist --> create new comment
new_comment = Comment(post_id=post_id, content=comm_content, author=self.user)
new_comment.put()
cid = new_comment.key().id()
self.write(json.dumps({'cid': cid, 'comm_author': self.user.name, 'comm_content': comm_content}))
示例2: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import key [as 别名]
def post(self):
path = urllib.unquote(self.request.path)
m = parts.search(path)
if m is None:
self.error(404)
return
this_path = m.group(1)
this_page = m.group(3) or 'index'
this_ext = m.group(4) or 'html'
# get section and node
section = Section.all().filter('path =', this_path).get()
node = Node.all().filter('section =', section).get()
if section is None or node is None:
self.error(404)
return
self.request.charset = 'utf8'
# remove the horribleness from comment
if this_page == 'comment' and this_ext == 'html':
# firstly, check the 'faux' field and if something is in there, redirect
faux = self.request.get('faux')
if len(faux) > 0:
logging.info('COMMENT: Spam comment detected (Faux field not empty)')
self.redirect('/')
return
# comment submission for each section
node = Node.get( self.request.get('node') )
name = self.request.get('name')
email = self.request.get('email')
website = self.request.get('website')
comment_text = re.sub('\r', '', self.request.get('comment'));
# if there are more than 4 links (https?://) in the comment, we consider it spam
if spammy_links(comment_text):
logging.info('COMMENT: Spam comment detected (Too many links)')
self.redirect('/')
return
# now create the comment
comment = Comment(
node = node,
name = name,
email = email,
website = website,
comment = comment_text,
)
comment.set_derivatives()
comment.put()
# send a mail to the admin
admin_email = util.config_value('Admin Email')
if mail.is_email_valid(admin_email):
url_post = util.construct_url() + node.section.path + node.name + '.html'
url_mod = util.construct_url() + '/admin/comment/?key=' + str(comment.key()) + ';status='
url_del = util.construct_url() + '/admin/comment/del.html?key='+ str(comment.key())
body = 'From: ' + name + ' <' + email + '>\n'
body = body + 'Site: ' + website + '\n\n'
body = body + comment_text + '\n\n'
body = body + '*** Actions ***\n\n'
body = body + 'ViewPost = ' + url_post + '\n\n'
body = body + 'Approve = ' + url_mod + 'approve\n'
body = body + 'Reject = ' + url_mod + 'reject\n'
body = body + 'Delete = ' + url_del + '\n'
mail.send_mail(admin_email, admin_email, 'New comment on ' + section.path + node.name + '.html', body)
else:
# don't do anything
logging.info('No valid email set, skipping sending admin an email for new comment')
# redirect to the comment page
self.redirect('comment.html?key=' + str(comment.key()))
return
elif this_page == 'message' and this_ext == 'html':
# firstly, check the 'faux' field and if something is in there, redirect
faux = self.request.get('faux')
if len(faux) > 0:
logging.info('MESSAGE: Spam detected, not saving')
self.redirect('/')
return
# message submission for each section
type = self.request.get('type')
subject = self.request.get('subject')
message = self.request.POST.items()
redirect = self.request.get('redirect')
# create the full URL we should be redirecting to
full_redirect = util.construct_redirect( redirect )
# now create the message
msg = Message(
type = type,
subject = subject,
#.........这里部分代码省略.........