本文整理汇总了Python中models.Comment.all方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.all方法的具体用法?Python Comment.all怎么用?Python Comment.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: left_right
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [as 别名]
def left_right(key):
upload_url = blobstore.create_upload_url('/post_comment/'+key)
battle = Battle.get(key)
left_comments = Comment.all().ancestor(battle).order('-votes').filter('side =','left')
right_comments = Comment.all().ancestor(battle).order('-votes').filter('side =','right')
if battle.expirationDate and battle.expirationDate < datetime.now():
return render_template('results.html',battle=battle,leftf=battle.left,rightf=battle.right,lc=left_comments,rc=right_comments)
return render_template('battle.html',battle=battle,key=key,
leftf=battle.left,rightf=battle.right,
lc=left_comments,rc=right_comments,upload_url=upload_url,current_user=users.get_current_user().email())
示例2: updateCurrentGames
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [as 别名]
def updateCurrentGames():
games = memcache.get("gamedates")
if not games:
games = GameDate.all()
games.order("date")
current_games = []
deletedGame = False
now = localTime()
datetimenow = datetime.datetime(month=now.month, year=now.year, day=now.day)
for game in games:
# if game.date.month <= now.month and game.date.day < now.day and game.date.year <= now.year:
if game.date < datetimenow:
game.delete()
deletedGame = True
else:
current_games.append(game)
# when we delete a game, we should also
# reset all players to be OUT and NOT goalie
if deletedGame:
players = Player.all()
for player in players:
player.inThisWeek = False
if not player.sub:
player.goalie = False
player.team = ""
player.put()
memcache.set("players", players)
comments = Comment.all()
for comment in comments:
comment.delete()
return current_games
示例3: get
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [as 别名]
def get(self):
# see if there is a key
comment = None
status = None
try:
comment = Comment.get( self.request.get('key') )
status = self.request.get('status')
except db.BadKeyError:
pass
if comment is None:
# show all the 'new' comments
comments = Comment.all().filter('status =', 'new').order('inserted').fetch(page_count+1)
more = True if len(comments) > page_count else False
comments = comments[:page_count]
vals = {
'comments' : comments,
'more' : more,
}
self.template( 'comment-list.html', vals, 'admin' )
else:
comment.status = status_map[status]
comment.put()
comment.node.regenerate()
self.redirect('./')
return
示例4: get
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [as 别名]
def get(self,post_id):
session = get_current_session()
if session.has_key('user'):
user = session['user']
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 ) )
comments = Comment.all().filter("post =", post.key()).order("-karma").fetch(1000)
comments = helper.order_comment_list_in_memory(comments)
prefetch.prefetch_comment_list(comments)
display_post_title = True
prefetch.prefetch_posts_list([post])
if helper.is_json(post_id):
comments_json = [c.to_json() for c in comments if not c.father_ref()]
if(self.request.get('callback')):
self.response.headers['Content-Type'] = "application/javascript"
self.response.out.write(self.request.get('callback')+'('+simplejson.dumps({'post':post.to_json(),'comments':comments_json})+')')
else:
self.response.headers['Content-Type'] = "application/json"
self.response.out.write(simplejson.dumps({'post':post.to_json(),'comments':comments_json}))
else:
self.response.out.write(template.render('templates/post.html', locals()))
except db.BadKeyError:
self.redirect('/')
示例5: get
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [as 别名]
def get(self):
game = GetNextGame()
# get all of the players and loop through them to figure out
# who is "in"
results = GetAllPlayers()
inGoalies = []
inPlayers = []
outPlayers = []
for player in results:
if player.inThisWeek:
if player.goalie:
inGoalies.append(player)
else:
inPlayers.append(player)
else:
outPlayers.append(player)
inPlayerMap = map(None, inPlayers, inGoalies)
# we query all of the comments and order them by time
comments = Comment.all()
comments.order("-time")
# the template system takes key/value pairs
values = {"game" : game, "inPlayerMap":inPlayerMap, "outPlayers":outPlayers, "comments":comments, "numGoalies": len(inGoalies), "numSkaters":len(inPlayers)}
# this is standard webapp/django template syntax
# we specify a template to use and a dictionary of values
path = os.path.join(os.path.dirname(__file__), 'templates/main.html')
self.response.out.write(template.render(path, values))
示例6: delete_post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [as 别名]
def delete_post(cls, post_id, user_id):
error_msg = None
posts = Post.all().order('-created').fetch(limit=10)
updated_post_list = posts
post = Post.get_by_id(post_id)
if user_id == post.created_by:
# delete comments of the post
comments = Comment.all().filter('post_id =', post_id).fetch(limit=10)
for c in comments:
Comment.delete(c)
# delete likes of the post
likes = Like.all().filter('post_id =', post_id).fetch(limit=10)
for l in likes:
Like.delete(l)
# delete the post
updated_post_list = cls.update_list_on_delete(
object_list=posts,
object_id=post_id
)
Post.delete(post)
else:
error_msg = 'You can delete only your own posts'
return updated_post_list, error_msg
示例7: view_post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [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: get
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [as 别名]
def get(self,post_id):
session = get_current_session()
if session.has_key('user'):
user = session['user']
try:
post = db.get(post_id)
comments = Comment.all().filter("post =", post.key()).order("-karma").fetch(1000)
self.response.out.write(template.render('templates/post.html', locals()))
except db.BadKeyError:
self.redirect('/')
示例9: get
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [as 别名]
def get(self,nickname):
perPage = 20
page = 1
realPage = 0
session = get_current_session()
if session.has_key('user'):
user = session['user']
thread_user = User.all().filter('lowercase_nickname =',nickname.lower()).fetch(1)[0]
user_comments = Comment.all().filter('user =',thread_user).order('-created').fetch(perPage, realPage * perPage)
comments = filter_user_comments(user_comments, thread_user)
self.response.out.write(template.render('templates/threads.html', locals()))
示例10: show_comments
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [as 别名]
def show_comments(environ):
comments_list = Comment.all()
div_comments = '<tr>'
for i in range(10):
div_comments += '<td>{%s}</td>' % i
div_comments += u'<td><a href="/delete/?comment={10}"' \
u' onclick="return confirm(\'Удалить комментарий?\')">Удалить</a></td></tr>'
comments = ''.join([div_comments.format(c.id, c.second_name, c.first_name, c.last_name, c.comment,
c.regions_name, c.city_name, c.phone, c.email, c.created, c.id)
for c in comments_list])
return render('comments.html', {'comments': comments})
示例11: get
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [as 别名]
def get(self, post_id):
session = get_current_session()
if session.has_key("user"):
user = session["user"]
try:
post = db.get(post_id)
comments = Comment.all().filter("post =", post.key()).order("-karma").fetch(1000)
display_post_title = True
prefetch_posts_list([post])
self.response.out.write(template.render("templates/post.html", locals()))
except db.BadKeyError:
self.redirect("/")
示例12: get
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [as 别名]
def get(self,nickname):
page = helper.sanitizeHtml(self.request.get('pagina'))
perPage = 6
page = int(page) if page else 1
realPage = page - 1
if realPage > 0:
prevPage = realPage
# this is used to tell the template to include the topic
threads = True
session = get_current_session()
if session.has_key('user'):
user = session['user']
thread_user = User.all().filter('lowercase_nickname =',nickname.lower()).fetch(1)
if len(thread_user) > 0:
thread_user = thread_user[0]
user_comments = Comment.all().filter('user =',thread_user).order('-created').fetch(perPage, realPage * perPage)
comments = helper.filter_user_comments(user_comments, thread_user)
if (page * perPage) < Comment.all().filter('user =', thread_user).count():
nextPage = page + 1
self.response.out.write(template.render('templates/threads.html', locals()))
else:
self.redirect('/')
示例13: delete_comment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [as 别名]
def delete_comment(cls, post_id, comment_id, user_id):
error_msg = ''
comments = Comment.all().filter('post_id =', post_id).order('-created').fetch(limit=10)
comment = Comment.get_by_id(comment_id)
if user_id == comment.created_by:
updated_comments = cls.update_list_on_delete(
object_list=comments,
object_id=comment_id
)
Comment.delete(comment)
else:
error_msg = 'You can delete only your own comments'
updated_comments = comments
return updated_comments, error_msg
示例14: view_post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [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))
示例15: base_context
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import all [as 别名]
def base_context():
context = Context({
'current_user':current_user(),
'admin':admin(),
'login_url':users.create_login_url('/blogs'),
'logout_url':users.create_logout_url('/blogs'),
'recent_comments':Comment.all().order('-date').fetch(5),
'categories':Category.all(),
'blogs_count':Blog.all().count(),
'archives':Archive.all().order('-year').order('-month'),
'friendlyURLs':FriendlyURL.all()
})
configuration=Configuration.all().fetch(1)
if configuration:
context.configuration=configuration[0]
return context