Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
 def GetEligibleStateKeys(self):
     if self.state:
         return [self.state]
     if self.region:
         return State.query(State.region == self.region).fetch(
             keys_only=True)
     # National championships are not based on residence, they're based on
     # citizenship.
     return None
Exemple #4
0
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)
Exemple #5
0
def update_states():
    with client.context():
        me = auth.user()
        if not me or not me.HasAnyRole([Roles.GLOBAL_ADMIN, Roles.WEBMASTER]):
            abort(403)

        futures = []
        all_regions = {}
        NORTHEAST = MakeRegion('ne', 'Northeast', 'Northeastern', all_regions,
                               futures)
        SOUTHEAST = MakeRegion('se', 'Southeast', 'Southeastern', all_regions,
                               futures)
        GREAT_LAKES = MakeRegion('gl', 'Great Lakes', 'Great Lakes',
                                 all_regions, futures)
        HEARTLAND = MakeRegion('hl', 'Heartland', 'Heartland', all_regions,
                               futures)
        SOUTH = MakeRegion('s', 'South', 'Southern', all_regions, futures)
        NORTHWEST = MakeRegion('nw', 'Northwest', 'Northwestern', all_regions,
                               futures)
        WEST = MakeRegion('w', 'West', 'Western', all_regions, futures)

        for future in futures:
            future.wait()
        del futures[:]

        all_states = {}
        for state_id, state_name, region in (
            ('al', 'Alabama', SOUTHEAST), ('ak', 'Alaska', NORTHWEST),
            ('az', 'Arizona', WEST), ('ar', 'Arkansas',
                                      SOUTH), ('ca', 'California', WEST),
            ('co', 'Colorado', WEST), ('ct', 'Connecticut', NORTHEAST),
            ('de', 'Delaware', NORTHEAST), ('fl', 'Florida', SOUTHEAST),
            ('ga', 'Georgia', SOUTHEAST), ('hi', 'Hawaii',
                                           WEST), ('id', 'Idaho', NORTHWEST),
            ('il', 'Illinois', GREAT_LAKES), ('in', 'Indiana', GREAT_LAKES),
            ('ia', 'Iowa', HEARTLAND), ('ks', 'Kansas', HEARTLAND),
            ('ky', 'Kentucky', GREAT_LAKES), ('la', 'Louisiana', SOUTH),
            ('me', 'Maine', NORTHEAST), ('md', 'Maryland',
                                         NORTHEAST), ('ma', 'Massachusetts',
                                                      NORTHEAST),
            ('mi', 'Michigan',
             GREAT_LAKES), ('mn', 'Minnesota',
                            HEARTLAND), ('ms', 'Mississippi',
                                         SOUTH), ('mo', 'Missouri', HEARTLAND),
            ('mt', 'Montana', NORTHWEST), ('ne', 'Nebraska',
                                           HEARTLAND), ('nv', 'Nevada', WEST),
            ('nh', 'New Hampshire',
             NORTHEAST), ('nj', 'New Jersey',
                          NORTHEAST), ('nm', 'New Mexico',
                                       WEST), ('ny', 'New York', NORTHEAST),
            ('nc', 'North Carolina',
             SOUTHEAST), ('nd', 'North Dakota',
                          HEARTLAND), ('oh', 'Ohio',
                                       GREAT_LAKES), ('ok', 'Oklahoma', SOUTH),
            ('or', 'Oregon', NORTHWEST), ('pa', 'Pennsylvania', NORTHEAST),
            ('ri', 'Rhode Island',
             NORTHEAST), ('sc', 'South Carolina',
                          SOUTHEAST), ('sd', 'South Dakota',
                                       HEARTLAND), ('tn', 'Tennessee',
                                                    SOUTHEAST), ('tx', 'Texas',
                                                                 SOUTH),
            ('ut', 'Utah', WEST), ('vt', 'Vermont',
                                   NORTHEAST), ('va', 'Virginia', SOUTHEAST),
            ('wa', 'Washington',
             NORTHWEST), ('wv', 'West Virginia',
                          NORTHEAST), ('wi', 'Wisconsin',
                                       GREAT_LAKES), ('wy', 'Wyoming',
                                                      NORTHWEST)):
            MakeState(state_id, state_name, region, True, all_states, futures)

        for territory_id, territory_name, region in (
            ('dc', 'D. C.', NORTHEAST), ('pr', 'Puerto Rico', SOUTHEAST),
            ('gu', 'Guam', WEST), ('mp', 'Northern Mariana Islands', WEST),
            ('as', 'American Samoa', WEST), ('vi', 'U.S. Virgin Islands',
                                             SOUTHEAST)):
            MakeState(territory_id, territory_name, region, False, all_states,
                      futures)

        for future in futures:
            future.wait()
        del futures[:]

        for region in Region.query().iter():
            if region.key.id() not in all_regions:
                region.delete()
        for state in State.query().iter():
            if state.key.id() not in all_states:
                state.delete()
        return 'ok'
Exemple #6
0
 def all_states(self):
     return [state for state in State.query().order(State.name).iter()]