當前位置: 首頁>>代碼示例>>Python>>正文


Python Team.by_id方法代碼示例

本文整理匯總了Python中models.Team.Team.by_id方法的典型用法代碼示例。如果您正苦於以下問題:Python Team.by_id方法的具體用法?Python Team.by_id怎麽用?Python Team.by_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Team.Team的用法示例。


在下文中一共展示了Team.by_id方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: post

# 需要導入模塊: from models.Team import Team [as 別名]
# 或者: from models.Team.Team import by_id [as 別名]
 def post(self, *args, **kwargs):
     game_objects = {
         'game_level': GameLevel,
         'corporation': Corporation,
         'flag': Flag,
         'box': Box,
         'hint': Hint,
     }
     obj_name = self.get_argument('obj', '')
     uuid = self.get_argument('uuid', '')
     if obj_name in game_objects.keys():
         obj = game_objects[obj_name].by_uuid(uuid)
         if obj is not None:
             self.write(obj.to_dict())
         else:
             self.write({'Error': 'Invalid uuid.'})
     elif obj_name == "stats":
         flag = Flag.by_uuid(uuid)
         if flag is not None:
             if options.banking:
                 flaginfo = [{"name": flag.name, "token": flag.token, "price": "$" + str(flag.value)}]
             else:
                 flaginfo = [{"name": flag.name, "token": flag.token, "price": str(flag.value) + " points"}]
             captures = []
             for item in Flag.captures(flag.id):
                 team = Team.by_id(item[0])
                 if team:
                     captures.append({"name": team.name})
             attempts = []
             for item in Penalty.by_flag_id(flag.id):
                 team = Team.by_id(item.team_id)
                 if team:
                     attempts.append({"name": team.name, "token": item.token})
             hints = []
             for item in Hint.taken_by_flag(flag.id):
                 team = Team.by_id(item.team_id)
                 hint = Hint.by_id(item.hint_id)
                 if team:
                     if options.banking:
                         hints.append({"name": team.name, "price": "$" + str(hint.price)})
                     else:
                         hints.append({"name": team.name, "price": str(hint.price) + " points"})
             obj = {
                 "flag": flaginfo,
                 "captures": captures, 
                 "attempts": attempts, 
                 "hints": hints,
                 }
             self.write(obj)
         else:
             self.write({'Error': 'Invalid uuid.'})
     else:
         self.write({'Error': 'Invalid object type.'})
     self.finish()
開發者ID:moloch--,項目名稱:RootTheBox,代碼行數:56,代碼來源:AdminGameObjectHandlers.py

示例2: post

# 需要導入模塊: from models.Team import Team [as 別名]
# 或者: from models.Team.Team import by_id [as 別名]
 def post(self, *args, **kwargs):
     ''' Called to purchase an item '''
     uuid = self.get_argument('uuid', '')
     item = MarketItem.by_uuid(uuid)
     if not item is None:
         user = self.get_current_user()
         team = Team.by_id(user.team.id)  # Refresh object
         if user.has_item(item.name):
             self.render('market/view.html',
                         user=user,
                         errors=["You have already purchased this item."]
                         )
         elif team.money < item.price:
             message = "You only have $%d" % (team.money,)
             self.render('market/view.html', user=user, errors=[message])
         else:
             logging.info("%s (%s) purchased '%s' for $%d" % (
                 user.handle, team.name, item.name, item.price
             ))
             self.purchase_item(team, item)
             self.event_manager.item_purchased(user, item)
             self.redirect('/user/market')
     else:
         self.render('market/view.html',
                     user=self.get_current_user(),
                     errors=["Item does not exist."]
                     )
開發者ID:AnarKyx01,項目名稱:RootTheBox,代碼行數:29,代碼來源:MarketHandlers.py


注:本文中的models.Team.Team.by_id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。