def _render(self, year=None, explicit_year=False):
        events = event_query.EventListQuery(year).fetch()
        EventHelper.sort_events(events)

        week_events = EventHelper.groupByWeek(events)

        district_enums = set()
        for event in events:
            if event.event_district_enum is not None and event.event_district_enum != DistrictType.NO_DISTRICT:
                district_enums.add(event.event_district_enum)

        districts = []  # a tuple of (district abbrev, district name)
        for district_enum in district_enums:
            districts.append((DistrictType.type_abbrevs[district_enum],
                              DistrictType.type_names[district_enum]))
        districts = sorted(districts, key=lambda d: d[1])

        self.template_values.update({
            "events": events,
            "explicit_year": explicit_year,
            "selected_year": year,
            "valid_years": self.VALID_YEARS,
            "week_events": week_events,
            "districts": districts,
        })

        path = os.path.join(os.path.dirname(__file__),
                            '../templates/event_list.html')
        return template.render(path, self.template_values)
Beispiel #2
0
 def first_event_datetime_utc(year=datetime.now().year):
     """ Computes day the first in-season event begins """
     events = event_query.EventListQuery(year).fetch()
     earliest_start = None
     timezone = None
     for event in events:
         if event.is_season_event and (earliest_start is None or
                                       event.start_date < earliest_start):
             earliest_start = event.start_date
             timezone = event.timezone_id
     return earliest_start
    def _render(self, year=None, explicit_year=False):
        state_prov = self.request.get('state_prov', None)

        districts_future = DistrictsInYearQuery(year).fetch_async()
        all_events_future = event_query.EventListQuery(
            year).fetch_async()  # Needed for state_prov
        if state_prov:
            events_future = Event.query(
                Event.year == year,
                Event.state_prov == state_prov).fetch_async()
        else:
            events_future = all_events_future

        events = events_future.get_result()
        if state_prov == '' or (state_prov and not events):
            self.redirect(self.request.path, abort=True)

        EventHelper.sort_events(events)

        week_events = EventHelper.groupByWeek(events)

        districts = []  # a tuple of (district abbrev, district name)
        for district in districts_future.get_result():
            districts.append((district.abbreviation, district.display_name))
        districts = sorted(districts, key=lambda d: d[1])

        valid_state_provs = set()
        for event in all_events_future.get_result():
            if event.state_prov:
                valid_state_provs.add(event.state_prov)
        valid_state_provs = sorted(valid_state_provs)

        self.template_values.update({
            "events": events,
            "explicit_year": explicit_year,
            "selected_year": year,
            "valid_years": self.VALID_YEARS,
            "week_events": week_events,
            "districts": districts,
            "state_prov": state_prov,
            "valid_state_provs": valid_state_provs,
        })

        if year == datetime.datetime.now().year:
            self._cache_expiration = self.SHORT_CACHE_EXPIRATION

        return jinja2_engine.render('event_list.html', self.template_values)
    def _render(self, year=None, explicit_year=False):
        state_prov = self.request.get('state_prov', None)

        all_events_future = event_query.EventListQuery(year).fetch_async()  # Needed for state_prov
        if state_prov:
            events_future = Event.query(Event.year==year, Event.state_prov==state_prov).fetch_async()
        else:
            events_future = all_events_future

        events = events_future.get_result()
        if state_prov == '' or (state_prov and not events):
            self.redirect(self.request.path, abort=True)

        EventHelper.sort_events(events)

        week_events = EventHelper.groupByWeek(events)

        district_enums = set()
        for event in events:
            if event.event_district_enum is not None and event.event_district_enum != DistrictType.NO_DISTRICT:
                district_enums.add(event.event_district_enum)

        districts = []  # a tuple of (district abbrev, district name)
        for district_enum in district_enums:
            districts.append((DistrictType.type_abbrevs[district_enum],
                              DistrictType.type_names[district_enum]))
        districts = sorted(districts, key=lambda d: d[1])

        valid_state_provs = set()
        for event in all_events_future.get_result():
            if event.state_prov:
                valid_state_provs.add(event.state_prov)
        valid_state_provs = sorted(valid_state_provs)

        self.template_values.update({
            "events": events,
            "explicit_year": explicit_year,
            "selected_year": year,
            "valid_years": self.VALID_YEARS,
            "week_events": week_events,
            "districts": districts,
            "state_prov": state_prov,
            "valid_state_provs": valid_state_provs,
        })

        return jinja2_engine.render('event_list.html', self.template_values)