def regional(): with client.context(): year = datetime.date.today().year championships = Championship.query( ndb.AND(Championship.year == year, Championship.region != None)).fetch() competitions = ndb.get_multi([c.competition for c in championships]) states = State.query().fetch() regions = Region.query().order(Region.name).fetch() championships.sort( key=lambda championship: championship.competition.get().start_date) championship_regions = [ championship.region for championship in championships ] regions_missing_championships = [ region for region in regions if region.key not in championship_regions ] return render_template( 'regional.html', c=common.Common(wca_disclaimer=True), year=year, championships=championships, regions_missing_championships=regions_missing_championships)
def edit_championships(): with client.context(): me = auth.user() if not me or not me.HasAnyRole(Roles.AdminRoles()): abort(403) all_us_competitions = (Competition.query( Competition.country == ndb.Key(Country, 'USA')).order( Competition.name).fetch()) national_championships = (Championship.query( Championship.national_championship == True).order( -Championship.year).fetch()) regional_championships = (Championship.query( Championship.region != None).order( Championship.region).order(-Championship.year).fetch()) state_championships = (Championship.query( Championship.state != None).order( Championship.state).order(-Championship.year).fetch()) states = State.query().fetch() regions = Region.query().fetch() return render_template('admin/edit_championships.html', c=common.Common(), all_us_competitions=all_us_competitions, national_championships=national_championships, regional_championships=regional_championships, state_championships=state_championships, states=states, regions=regions)
def champions_table(event_id, championship_type, championship_region='', year=0): with client.context(): is_national = championship_type == 'national' is_regional = championship_type == 'regional' is_state = championship_type == 'state' all_champions = [] filters = [] if is_national: filters.append(Champion.national_champion == True) elif year: filters.append(Champion.year == int(year)) if is_regional: filters.append(Champion.region != None) elif is_state: filters.append(Champion.state != None) elif is_regional: filters.append( Champion.region == ndb.Key(Region, championship_region)) elif is_state: filters.append( Champion.state == ndb.Key(State, championship_region)) filters.append(Champion.event == ndb.Key(Event, str(event_id))) all_champions = Champion.query(ndb.AND(*filters)).fetch() if year and is_regional: all_champions.sort(key=lambda c: c.region.id()) championship_formatter = lambda c: c.region.get().name all_regions = Region.query().fetch() elif year and is_state: all_champions.sort(key=lambda c: c.state.id()) championship_formatter = lambda c: c.state.get().name all_states = State.query().fetch() else: all_champions.sort(key=lambda c: c.championship.id(), reverse=True) championship_formatter = lambda c: c.year return render_template('champions_table.html', c=common.Common(), champions=all_champions, championship_formatter=championship_formatter)
def state_rankings_table(event_id, state_id, use_average): with client.context(): ranking_class = RankAverage if use_average == '1' else RankSingle state = State.get_by_id(state_id) if not state: self.response.write('Unrecognized state %s' % state_id) return event = Event.get_by_id(event_id) if not event: self.response.write('Unrecognized event %s' % event_id) return rankings = (ranking_class.query( ndb.AND(ranking_class.event == event.key, ranking_class.state == state.key)).order( ranking_class.best).fetch(100)) people = ndb.get_multi([ranking.person for ranking in rankings]) people_by_id = {person.key.id(): person for person in people} return render_template('state_rankings_table.html', c=common.Common(), is_average=(use_average == '1'), rankings=rankings, people_by_id=people_by_id)
def title_policy(): with client.context(): return render_template('regional_title.html', c=common.Common())
def state_rankings(): with client.context(): return render_template('state_rankings.html', c=common.Common(wca_disclaimer=True))