本文整理汇总了Python中models.Match.put方法的典型用法代码示例。如果您正苦于以下问题:Python Match.put方法的具体用法?Python Match.put怎么用?Python Match.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Match
的用法示例。
在下文中一共展示了Match.put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import put [as 别名]
def post(self):
date = self.request.POST[u'date'].strip()
time = self.request.POST[u'time'].strip()
team1 = self.request.POST[u'team1'].strip()
team2 = self.request.POST[u'team2'].strip()
location = self.request.POST[u'location'].strip()
timestamp = datetime.datetime(2011, 02, 16, 20, 30, 15)
key_name = "%s_%s_%s" % (team1, team2, timestamp.strftime("%Y_%m_%d_%H_%M_%S"))
match = Match(team1 = team1,
team2 = team2,
key_name = key_name,
timestamp = timestamp,
)
match.put()
self.redirect(u'/admin')
示例2: get
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import put [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()
示例3: create_match
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import put [as 别名]
def create_match(self, request):
"""Create a Match between two Users"""
if request.player_1_name == request.player_2_name:
raise endpoints.ConflictException(
'Cannot create a match between a player and themselves!')
for player_name in [request.player_1_name, request.player_2_name]:
if not User.query(User.name == player_name).get():
raise endpoints.ConflictException(
'No user named {} exists!'.format(player_name))
match = Match(player_1_name=request.player_1_name,
player_2_name=request.player_2_name,
player_1_penalty=0,
player_2_penalty=0,
games_remaining=randint(1, 20),
is_active=True)
match_key = match.put()
return StringMessage(message='Match created between {} and {}! '
'(key={})'.format(request.player_1_name,
request.player_2_name,
match_key.urlsafe()))