本文整理汇总了Python中models.Vote.remove方法的典型用法代码示例。如果您正苦于以下问题:Python Vote.remove方法的具体用法?Python Vote.remove怎么用?Python Vote.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Vote
的用法示例。
在下文中一共展示了Vote.remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import remove [as 别名]
def post(self):
data = self.get_arguments()
try:
type = int(self.get_argument('type'))
flag = self.get_argument('flag')
slug = self.get_argument('slug')
spec = {'type': type, 'slug': slug}
cid = Content.one(spec)['_id']
uid = self.current_user['_id']
if int(flag) in [x for x,_y in MY_FLAGS]:
has_vote = Vote.one({'uid': uid ,'cid': cid})
if not has_vote:
Content.collection.update(
spec, {'$inc': { "votes." + flag: 1}}
)
vote = Vote()
vote['uid'], vote['cid'], vote['vote'] = uid, cid, int(flag)
vote.save()
return self.json_response("You have voted has been noted", "OK")
else:
Content.collection.update(
spec, {'$inc': { "votes." + flag: -1}}
)
Vote.remove({'uid': uid, 'cid': cid})
return self.json_response("Your vote has been removed", "OK")
raise Exception("Invalid vote")
except Exception, e:
raise
return self.json_response(e.__str__(), "ERROR", data)