本文整理汇总了Python中models.Match.hacker_list方法的典型用法代码示例。如果您正苦于以下问题:Python Match.hacker_list方法的具体用法?Python Match.hacker_list怎么用?Python Match.hacker_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Match
的用法示例。
在下文中一共展示了Match.hacker_list方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import hacker_list [as 别名]
def get(self):
self._current_user = self.require_login()
if not self._current_user:
self.response.out.write(json.dumps({"error": "please log in"}))
return
q = Queue.all().get()
if not q:
q = Queue()
#Push onto queue
if str(self._current_user.id) in q.users:
self.response.out.write(json.dumps({"success": "already in queue"}))
elif len(q.users) == 0:
q.users = [self._current_user.id]
self.response.out.write(json.dumps({"success": "added to queue"}))
else: #Found a match. Pop & Serve
matched = q.users[0]
q.users = q.users[1:]
#Randomly choose a project
projects = Project.all().fetch(1000)
random.seed()
project = random.choice(projects)
#Actually create the match
match = Match(project_id = str(project.key()),
users = [self._current_user.id, matched],
outcome = [0, 0])
hackers = Hacker.all().filter("user IN", match.users).fetch(8)
match.hacker_list = []
for hacker in hackers:
match.hacker_list.append(str(hacker.key()))
match.put()
#Notify the users via socket
broadcast(match, json.dumps({"success": "match found"}))
self.response.out.write("herp")
q.put()