本文整理汇总了Python中models.Comment.put方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.put方法的具体用法?Python Comment.put怎么用?Python Comment.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [as 别名]
def get(self):
post_id = int(self.request.get('id'))
post = Post.get_by_id(post_id)
post.comment += 1
post.put()
comment = Comment(post=post.key, content=self.request.get("content"))
comment.put()
示例2: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [as 别名]
def post(self, key):
issue = db.get(key)
name = self.request.get("name")
email = self.request.get("email")
text = self.request.get("comment")
comment = Comment(
name = name,
email = email,
comment = text,
issue = issue,
)
comment.put()
context = {
'issue': issue,
}
# prepare the context for the template
# calculate the template path
path = os.path.join(os.path.dirname(__file__), 'templates',
'issue.html')
# render the template with the provided context
self.response.out.write(template.render(path, context))
示例3: post_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [as 别名]
def post_comment(text, author, suggestion):
brtext = text.replace('\n', '<br/>')
comment = Comment(text=brtext, author=author, suggestion=suggestion)
comment.put()
author.lastposted = date.today()
author.put()
notify_comment(text, comment)
示例4: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [as 别名]
def post(self, post_id):
session = get_current_session()
if session.has_key('user'):
message = helper.sanitizeHtml(self.request.get('message'))
user = session['user']
key = self.request.get('comment_key')
if len(message) > 0 and key == keys.comment_key:
try:
post = Post.all().filter('nice_url =', helper.parse_post_id( post_id ) ).get()
if post == None: #If for some reason the post doesn't have a nice url, we try the id. This is also the case of all old stories
post = db.get( helper.parse_post_id( post_id ) )
post.remove_from_memcache()
comment = Comment(message=message,user=user,post=post)
comment.put()
helper.killmetrics("Comment","Root", "posted", session, "",self)
vote = Vote(user=user, comment=comment, target_user=user)
vote.put()
Notification.create_notification_for_comment_and_user(comment,post.user)
self.redirect('/noticia/' + post_id)
except db.BadKeyError:
self.redirect('/')
else:
self.redirect('/noticia/' + post_id)
else:
self.redirect('/login')
示例5: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [as 别名]
def post(self):
commentText = self.request.get("comment")
nameText = self.request.get("name")
#time = datetime.now()
comment = Comment(text=commentText, name=nameText, time=localTime())
comment.put()
self.redirect("/")
示例6: post_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [as 别名]
def post_comment(key):
battle = Battle.get(key)
now = datetime.now()
if request.form.has_key('leftbox'):
comment = request.form.get('leftbox')
left_comment = Comment(parent=battle, comment=comment, author=users.get_current_user(), side="left", when=now)
if request.files['left_image']:
image_file = request.files['left_image']
headers = image_file.headers['Content-Type']
blob_key = parse_options_header(headers)[1]['blob-key']
left_comment.blob_key = blob_key
left_comment.image_url = images.get_serving_url(blob_key)
left_comment.put()
send_emails(key, comment)
elif request.form.has_key('rightbox'):
comment = request.form.get('rightbox')
right_comment = Comment(parent=battle, comment=comment, author=users.get_current_user(), side="right", when=now)
if request.files['right_image']:
image_file = request.files['right_image']
headers = image_file.headers['Content-Type']
blob_key = parse_options_header(headers)[1]['blob-key']
right_comment.blob_key = blob_key
right_comment.image_url = images.get_serving_url(blob_key)
right_comment.put()
send_emails(key, comment)
return left_right(key)
示例7: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [as 别名]
def post(self, forum_id, post_reference):
user = self.user_model
post = ForumPost.query(ForumPost.forum_name == forum_id, ForumPost.reference == post_reference).get()
text = cgi.escape(self.request.get('text'))
sender = cgi.escape(self.request.get('sender'))
recipient = cgi.escape(self.request.get('recipient'))
replied_to_urlsafe = cgi.escape(self.request.get('parent'))
comment = Comment(parent = post.key)
if len(replied_to_urlsafe) != 0:
replied_to_key = ndb.Key(urlsafe=replied_to_urlsafe)
parent_comment = replied_to_key.get()
comment.parent = replied_to_key
comment.offset = parent_comment.offset + 20
recipient_comment = ndb.Key(urlsafe=replied_to_urlsafe).get()
comment.recipient = recipient_comment.sender
comment.sender = user.username
comment.root = False
else:
comment.sender = sender
comment.recipient = recipient
comment.text = text
comment.time = datetime.datetime.now() - datetime.timedelta(hours=7) #For PST
comment.put()
if comment.root == False:
parent_comment.children.append(comment.key)
parent_comment.put()
post.comment_count += 1
post.put()
self.redirect('/tech/{}/{}'.format(forum_id, post_reference))
示例8: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [as 别名]
def post(self):
photo_id = int(self.request.get('pid'))
Author = self.request.get('comment-name')
comment = self.request.get('comment')
photo = Image.get_Detail(photo_id)
logging.error("Author is" + Author)
logging.error(comment)
if Author == '' or comment == '':
pic_id = "/Home#" + str(photo_id)
self.redirect(pic_id)
else:
if photo:
try:
comment = Comment(
Author=Author,
Comment=comment, Image=photo.key)
comment.put()
logging.info("Horray, a comment is saved.")
except:
logging.error("Error saving comment in datastore.")
finally:
pic_id = "/Home#" + str(photo_id)
render = template.render('templates/redirect.html',
{'link': pic_id, 'message': 'Commented'})
self.response.write(render)
示例9: random_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [as 别名]
def random_comment(blog_post):
possible_comments = [
'Wow cool!',
'Neato!',
'Lame.',
'First post!',
'Was on Reddit yesterday.',
'Pics or didn\'t happen.',
'tl;dr was awesome',
'I was so sad today, this made me laugh so much thanks lol.',
'Do you think they care?',
'Do you believe in life after love?',
'I like this version better.',
'That was just great.',
'Upvoting because after reading your username, I\'m pretty sure you\'re trolling.',
'Lol. I saw this one first and was a bit confused.',
'I laughed so much!',
'This is awesome',
'Windows XP is the Playstation 2 of Operating Systems.',
'I think we\'ve all been there at one point'
]
ts = datetime.now() + timedelta(days=-random.randint(1, 50))
c = Comment(content=possible_comments[random.randint(0, len(possible_comments)-1)], timestamp=ts, blog_post=blog_post.key)
c.put()
示例10: view_post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [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),
)
示例11: comment_insert
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [as 别名]
def comment_insert(self, request):
if request.from_datastore:
my_quote = request
else:
my_quote = Comment(sculpture_key=request.sculpture_key, author=request.author, content=request.content)
my_quote.put()
return my_quote
示例12: comment_insert
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [as 别名]
def comment_insert(self,comment):
comment_key = ndb.Key('AIESEC','Comment')
post_key = ndb.Key('AIESEC','Post')
user_key = ndb.Key('AIESEC','User')
comment = Comment(parent = comment_key, text = comment.text,
post = Post(parent = post_key, title = comment.post.title, eID = comment.post.eID),
owner = User(parent = user_key, user_id = comment.owner.user_id, email = comment.owner.email)
)
comment.put()
return comment
示例13: comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [as 别名]
def comment(command_args, account):
cc = Comment(body = command_args,
task = account.task,
created = datetime.datetime.now())
cc.put()
command = Command(user=account.user,
created=datetime.datetime.now(),
root="COMMENT",
args=command_args,
task=account.task)
command.put()
示例14: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [as 别名]
def post(self):
post = BlogPost.get_by_id(int(self.request.get('postid')))
c = Comment(
body = self.request.get('body'),
post = post,
author_name = self.getCurrentUserName()
)
c.put()
#post.comments_count += 1
post.put()
templ_vals = {
'comment': c
}
self.render_to_response('comment.html',templ_vals)
示例15: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import put [as 别名]
def post(self, post_id):
comment_text = self.request.get('comment')
#comments can't be empty
if not comment_text:
self.response.out.write(json.dumps({'err_msg': True}))
return
key = db.Key.from_path('Post', int(post_id))
post = self.get_post(key)
comment = Comment(user = self.user,
post = post,
comment = comment_text)
comment.put()
self.response.out.write(comment.render(self.user))