本文整理汇总了Python中models.Vote.already_vote方法的典型用法代码示例。如果您正苦于以下问题:Python Vote.already_vote方法的具体用法?Python Vote.already_vote怎么用?Python Vote.already_vote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Vote
的用法示例。
在下文中一共展示了Vote.already_vote方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import already_vote [as 别名]
def get(self, boker_id):
boker = Boker.get_by_id(int(boker_id))
if boker:
deferred.defer(update_num_view, str(boker.key()))
# Check post type, Video or Photo
if boker.video_id and boker.video_source:
self.template = 'video.html'
if self.current_user is not None:
user = User.get_by_key_name(self.current_user['id'])
can_like = not Like.already_like(user, boker)
else:
can_like = False
else:
active_contest = Contest.active_contest()
if active_contest:
is_nominee = Contest.is_nominee(boker)
if self.current_user is not None:
user = User.get_by_key_name(self.current_user['id'])
can_vote = not Vote.already_vote(user)
can_like = not Like.already_like(user, boker)
else:
can_vote = False
can_like = False
querystring = self.request.GET
return self.render_response(self.template, locals())
else:
self.abort(404)
示例2: post
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import already_vote [as 别名]
def post(self, boker_id):
action = self.request.get('action')
boker = Boker.get_by_id(int(boker_id))
user = User.get_by_key_name(self.current_user['id'])
if boker and user and action == 'vote':
# Avoid multi votes
if not Vote.already_vote(user):
vote = Vote(contest=Contest.active_contest(), user=user, boker=boker)
vote.put()
# Upate boker vote score
boker.num_vote += 1
boker.save()
# Trigger post action
user_access_token = self.current_user['access_token']
boker_url = settings.APP_DOMAIN + self.uri_for('boker_view', boker_id=boker_id)
deferred.defer(publish_vote_action, user_access_token, boker_url)
self.redirect(self.uri_for('boker_view', boker_id=boker_id)+'?vote=1')
self.redirect(self.uri_for('boker_view', boker_id=boker_id))