本文整理汇总了Python中models.Vote.ip方法的典型用法代码示例。如果您正苦于以下问题:Python Vote.ip方法的具体用法?Python Vote.ip怎么用?Python Vote.ip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Vote
的用法示例。
在下文中一共展示了Vote.ip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import ip [as 别名]
def post(self):
loser = db.get(str(self.request.get('loser')))
winner = db.get(str(self.request.get('winner')))
vote = Vote(winner=winner, loser=loser)
#To store username if the user is logged in
client = OAuthClient("twitter", self)
logged_in = client.get_cookie()
if logged_in:
info = client.get("/account/verify_credentials")
vote.name = info["screen_name"]
else:
vote.name = 'Guest'
#TODO: Stop spam-voting for same key from same ip repeatedly
vote.ip = self.request.remote_addr
if check_vote_spam(vote.ip, winner):
self.redirect('/msg=You+appear+to+be+votespamming,+please+stop+or+try+again+later')
else:
vote.put()
#Wins and losses
loser.losses = loser.losses+1
loser.win_percentage = loser.calc_win_percentage()
loser.put()
winner.wins = winner.wins+1
winner.win_percentage = winner.calc_win_percentage()
winner.put()
#Redirect so that people cannot repost twice
self.redirect('/?w=%s&l=%s' % (winner.key().id(), loser.key().id()))
示例2: post
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import ip [as 别名]
def post():
values = {}
vote_value = request.form['vote']
vote = Vote()
for item in request.form.getlist('value[]'):
if vote.get_vote_title(item) is not None:
values[item] = vote.get_vote_title(item)
elif int(item) == Vote.CUSTOM_VOTE_ID and vote_value:
values[item] = vote_value
if values:
# add vote
vote.ip = request.remote_addr
vote.votes = values
try:
vote_current = Vote.objects(ip=request.remote_addr,
created_at__gte=(datetime.datetime.now() - datetime.timedelta(minutes=15)))
if vote_current:
raise ValueError("You've already voted!")
vote.save()
suffix = VoteView.ordinal(len(Vote.objects))
return jsonify({'status': 'ok',
'message': 'Thank your for voting! You are the %s fan of python' % suffix})
except ValueError as e:
return jsonify({'status': 'error', 'message': e.message})
except Exception:
return jsonify({'status': 'error', 'message': 'Error while saving vote. Sorry :('})
else:
return jsonify({'status': 'error', 'message': 'Choose any option to vote'})