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, )
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()
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, )
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")
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, )
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')
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')