コード例 #1
0
ファイル: AdminHandlers.py プロジェクト: mach327/RootTheBox
 def render_page(self, errors=None):
     ''' Render page with extra arguments '''
     if errors is not None and not isinstance(errors, list):
         errors = [str(errors), ]
     self.render('admin/upgrades/swat.html',
         pending_bribes=Swat.all_pending(),
         in_progress_bribes=Swat.all_in_progress(),
         completed_bribes=Swat.all_completed(),
         errors=errors,
     )
コード例 #2
0
 def create_swat(self, user, target):
     ''' Create Swat request object in database '''
     price = Swat.get_price(target)
     assert 0 < price
     user.team.money -= price
     swat = Swat(
         user_id=user.id,
         target_id=target.id,
         paid=price,
     )
     dbsession.add(swat)
     dbsession.add(user.team)
     dbsession.flush()
コード例 #3
0
 def render_page(self, errors=None):
     ''' Render page with extra arguments '''
     if errors is not None and not isinstance(errors, list):
         errors = [
             str(errors),
         ]
     self.render(
         'admin/upgrades/swat.html',
         pending_bribes=Swat.all_pending(),
         in_progress_bribes=Swat.all_in_progress(),
         completed_bribes=Swat.all_completed(),
         errors=errors,
     )
コード例 #4
0
 def post(self, *args, **kwargs):
     ''' Validate user arguments for SWAT request '''
     target = User.by_uuid(self.get_argument('uuid', ''))
     if target is not None and not target.has_permission(ADMIN_PERMISSION):
         if not Swat.user_is_pending(target) and not Swat.user_is_in_progress(target):
             user = self.get_current_user()
             if not target in user.team.members:
                 if Swat.get_price(target) <= user.team.money:
                     self.create_swat(user, target)
                     self.redirect('/swat')
                 else:
                     self.render_page("You cannot afford this bribe")
             else:
                 self.render_page("You cannot SWAT your own team")               
         else:
             self.render_page("A bribe is already exists for this player")
     else:
         self.render_page("Target user does not exist")
コード例 #5
0
 def render_page(self, errors=None):
     ''' Render page with extra arguments '''
     if errors is not None and not isinstance(errors, list):
         errors = [str(errors),]
     user = self.get_current_user()
     targets = filter(lambda target: target not in user.team.members, User.all_users())
     self.render('upgrades/swat.html',
         targets=targets,
         user_bribes=Swat.ordered_by_user_id(user.id),
         errors=None,
     )
コード例 #6
0
 def create_swat(self, user, target):
     ''' Create Swat request object in database '''
     price = Swat.get_price(target)
     assert 0 < price
     user.team.money -= price
     swat = Swat(
         user_id=user.id,
         target_id=target.id,
         paid=price,
     )
     dbsession.add(swat)
     dbsession.add(user.team)
     dbsession.flush()
コード例 #7
0
 def accept_bribe(self):
     ''' Accept bribe, and lock user's account '''
     swat = Swat.by_uuid(self.get_argument('uuid', ''))
     if swat is not None and not swat.completed:
         logging.info("Accepted SWAT with uuid: %s", swat.uuid)
         swat.accepted = True
         swat.target.locked = True
         dbsession.add(swat)
         dbsession.add(swat.target)
         dbsession.flush()
         self.render_page()
     else:
         logging.warn("Invalid request to accept bribe with uuid: %r" %
                      (self.get_argument('uuid', ''), ))
         self.render_page('Requested SWAT object does not exist')
コード例 #8
0
ファイル: AdminHandlers.py プロジェクト: mach327/RootTheBox
 def accept_bribe(self):
     ''' Accept bribe, and lock user's account '''
     swat = Swat.by_uuid(self.get_argument('uuid', ''))
     if swat is not None and not swat.completed:
         logging.info("Accepted SWAT with uuid: %s", swat.uuid)
         swat.accepted = True
         swat.target.locked = True
         dbsession.add(swat)
         dbsession.add(swat.target)
         dbsession.flush()
         self.render_page()
     else:
         logging.warn("Invalid request to accept bribe with uuid: %r" %
             (self.get_argument('uuid', ''),)
         )
         self.render_page('Requested SWAT object does not exist')