def points(self): team = Team.find(self.request.input('team')) team.points = self.request.input('points') team.save() self.request.session.flash('success', 'Successfully Changed Points') return self.request.back()
def teams(self): teams = Team.where('league_id', self.league.id).get() return self.view.render('leagues/teams', { 'league': self.league, 'teams': teams })
def can_create_teams(self): if self.is_subscribed(): return True if Team.where('owner_id', self.id).count() > 5: return False return True
def remove(self): team = Team.find(self.request.input('team')) league = League.find(team.league_id) if league.current_id == team.owner_id: league.skip_user() team.league_id = None team.save() self.request.session.flash('success', 'Successfully Removed Team') return self.request.back()
def draft(self): if self.request.has('draft'): DraftedPokemon.create(team_id=self.league.current.team( self.league).id, pokemon_id=self.request.input('pokemon'), league_id=self.league.id) DraftedPokemon.where('queue_id', self.request.input('pokemon')).where( 'league_id', self.league.id).delete() # Get Pokemon pokemon = Pokemon.find(self.request.input('pokemon')) team = Team.find(self.league.current.team(self.league).id) team.points -= pokemon.points team.save() self.league.broadcast('{} was drafted by {} for {} points'.format( pokemon.name, team.name, pokemon.points)) self.league.next_drafter() self.league.broadcast("It is currently {}'s turn to draft.".format( team.owner.name)) self.request.session.flash( 'success', 'Successfully Drafted {0}'.format(pokemon.name)) self.request.redirect_to('league.draft', {'id': self.league.id}) elif self.request.has('unqueue'): DraftedPokemon \ .where('queue_id', self.request.input('pokemon')) \ .where('team_id', self.request.user() .team(self.league).id).where('league_id', self.league.id) \ .first().delete() self.request.session.flash('success', 'Successfully Unqueued') return self.request.redirect_to('league.draft', {'id': self.league.id}) elif self.request.has('queue'): DraftedPokemon.create(team_id=auth().team(self.league).id, queue_id=self.request.input('pokemon'), league_id=self.league.id) self.request.session.flash('success', 'Queue Successful') return self.request.redirect_to('league.draft', {'id': self.league.id}) self.request.session.flash('warning', 'Could not draft at this time') return self.request.redirect_to('league.draft', {'id': self.league.id})
def store(self, upload: Upload): try: logo = request().input('logo').filename except AttributeError: logo = '' create_team = Team.create(name=request().input('name'), owner_id=auth().id, picture=logo) # upload logo if logo: upload.store(request().input('logo')) if create_team: return request().back( default='create/team?message=Created Successfully') return request().redirect('/create/team?message=Could Not Create Team')
def in_league(self, league): return Team.where('league_id', league.id).where('owner_id', self.id).get().count()
def get_all_leagues(self): league_id_collection = Team.where('owner_id', self.id).where_not_null('league_id').get().pluck('league_id') return League.where_in('id', league_id_collection).get()
def get_all_teams(self): return Team.where('owner_id', self.id).get()
def get_joinable_teams(self): return Team.where('owner_id', self.id).where_null('league_id').get()
def team(self, league): return Team.where('owner_id', self.id).where('league_id', league.id).first()
def teams(self, Request, View): league = League.find(Request.param('id')) teams = Team.where('league_id', league.id).get() return View('leagues/teams', {'league': league, 'teams': teams})
def get_teams(self): return Team.where('league_id', self.id).get()