本文整理汇总了Python中models.Game.new_or_get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Game.new_or_get_by_id方法的具体用法?Python Game.new_or_get_by_id怎么用?Python Game.new_or_get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Game
的用法示例。
在下文中一共展示了Game.new_or_get_by_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_or_get_by_id [as 别名]
def get(self):
uid = self.get_argument('uid', '')
toid = self.get_argument('toid', '')
message = self.get_argument('message', '')
if uid == '':
self.write('{"error":"uid parameter need"}')
return
if toid == '':
self.write('{"error":"toid parameter need"}')
return
if message == '':
self.write('{"error":"message parameter need"}')
return
me = User.new_or_get_by_id(uid)
if me == None:
self.write('{"error":"not found"}')
o = User.new_or_get_by_id(toid)
if 'token' in o.prop:
if o.prop['token'] != '(null)':
payload = {'aps':{'alert':''}}
if 'nickname' in o.prop:
payload['aps']['alert'] = o.prop['nickname'] + '님이 메세지를 보냈습니다!'
payload['aps']['alert'] = '누국가가 당신에게 메세지를 보냈습니다!'
payload['aps']['sound'] = 'jinx.wav'
send_pushnoti(o.prop['token'], payload)
gl = Gamelist.new_or_get_by_id(uid)
glto = Gamelist.new_or_get_by_id(toid)
gid = gl.get_current_game_id(toid)
newgame = gid is None
if newgame:
gid = Game.make_id(uid, toid)
g = Game.new_or_get_by_id(gid)
if g.say(uid, message):
g.set()
gl.set_game(g)
glto.set_game(g)
if newgame:
gl.add_current_game(toid, gid)
glto.add_current_game(uid, gid)
gl.set()
glto.set()
Queue.push(uid, gid, toid, message, g.round)
data = {}
data['game'] = g.to_dict(uid, True)
self.write(json.dumps(data))