当前位置: 首页>>代码示例>>Python>>正文


Python Match.put方法代码示例

本文整理汇总了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')
开发者ID:phoenix24,项目名称:fb-apps,代码行数:20,代码来源:main.py

示例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()
开发者ID:dillongrove,项目名称:TheHackers,代码行数:43,代码来源:main.py

示例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()))
开发者ID:boaarmpit,项目名称:udacity_FSND_project4,代码行数:25,代码来源:api.py


注:本文中的models.Match.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。