本文整理汇总了Python中models.Vote.user_id方法的典型用法代码示例。如果您正苦于以下问题:Python Vote.user_id方法的具体用法?Python Vote.user_id怎么用?Python Vote.user_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Vote
的用法示例。
在下文中一共展示了Vote.user_id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vote
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import user_id [as 别名]
def vote(definition_id):
body = request.get_json()
try:
definition = db.session.query(Definition).filter_by(id=definition_id).one()
except NoResultFound as ex:
return jsonify({'error': 'Definition does not exist'})
try:
user = db.session.query(User).filter_by(twitter_id=body.get('userId')).one()
except NoResultFound as ex:
return jsonify({'error': 'Auth Error'})
posted_auth_token = body.get('authToken')
token = encode_value(
user.oauth_token,
app.config.get('AUTH_SALT')
)
if token != posted_auth_token:
return jsonify({'error': 'Auth Error'})
try:
vote = db.session.query(Vote).filter_by(definition_id=definition.id).\
filter_by(user_id=user.id).one()
except NoResultFound as ex:
vote = Vote()
vote.definition_id = definition.id
vote.user_id = user.id
vote.vote = 1 if body.get('isUpvote') else -1
db.session.add(vote)
db.session.commit()
return jsonify({'vote': { 'id': vote.id}})
示例2: vote
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import user_id [as 别名]
def vote(req):
if req.method == 'POST':
vote_target = get_object_or_404(Gentleman, pk=req.POST['gentleman_id'])
try:
vote = Vote.objects.get(user=req.user)
except Vote.DoesNotExist:
vote = Vote()
vote.user_id = req.user.id
if 'execution' in req.POST:
vote.execution = vote_target
if 'grooming' in req.POST:
vote.grooming = vote_target
if 'creativity' in req.POST:
vote.creativity = vote_target
vote.save()
messages.warning(req, '%s' % req.user.vote)
return HttpResponseRedirect(reverse('home'))
示例3: vote
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import user_id [as 别名]
def vote(request):
if request.session['score']==0:
return HR(u'需要登录后才可以投票!')
else:
did=request.POST['did']
score=request.POST['score']
#查询是否已投票此(did)discussid
if Vote.objects.filter(user_id=request.session['uid'],discuss_id=did).count()==1:
return HR(u'亲,只能投票一次噢!')
d=Discuss.objects.get(id=did)
if d.user_id==request.session['uid']:
return HR(u'亲,不可以为自己投票的哦!')
#更新vote表
v=Vote()
v.user_id=request.session['uid']
v.discuss_id=did
v.vote =score
v.save()
#更新用户表,增加score
u=User.objects.get(id=d.user_id)
if score=='1':
d.support +=1
u.score+=1
else:
d.oppose +=1
u.score-=1
if u.score <1:
u.score=1
d.save()
u.save()
return HR(u'success')