Ejemplo n.º 1
0
  def get(self, region_or_state, year):
    # We should call RegionalsId or StateChampionshipId here, but we don't know
    # yet what kind of championship this is.
    championship_id = '%s_%s' % (region_or_state, year)

    championship = Championship.get_by_id(championship_id)
    if not championship:
      template = JINJA_ENVIRONMENT.get_template('error.html')
      self.response.write(template.render({
          'c': common.Common(self),
          'error': 'Sorry!  We don\'t know about that championship yet.',
      }))
      return
    competition = championship.competition.get()

    event_keys = set()
    # This query is ugly because we have two separate representations of
    # competitions in the datastore: ScheduleCompetition (competitions using the
    # scheduling system) and Competition (competitions from the WCA DB export).
    for competitor in SchedulePerson.query(
                          SchedulePerson.competition ==
                          ndb.Key(ScheduleCompetition, championship.competition.id())).iter():
      for event in competitor.registered_events:
        event_keys.add(event)
    events = sorted(ndb.get_multi(event_keys), key=lambda e: e.rank)
    deadline_without_timezone = (championship.residency_deadline or
                                 datetime.datetime.combine(competition.start_date,
                                                           datetime.time(0, 0, 0)))
    deadline = timezones.ToLocalizedTime(deadline_without_timezone,
                                         championship.residency_timezone or 'America/Los_Angeles')

    states = ndb.get_multi(championship.GetEligibleStateKeys())
    if championship.region:
      championship_title = championship.region.get().championship_name
      state_names = [state.name for state in State.query(State.region == championship.region).iter()]
      state_list = ' and '.join([', '.join(state_names[:-1]), state_names[-1]])
    elif championship.state:
      championship_title = championship.state.get().name + ' State'
      state_list = championship.state.get().name

    template = JINJA_ENVIRONMENT.get_template('championship_psych.html')
    self.response.write(template.render({
        'c': common.Common(self),
        'championship': championship,
        'competition': competition,
        'championship_title': championship_title,
        'championship_id': championship_id,
        'state_list': state_list,
        'events': events,
        'deadline': deadline,
        'deadline_passed': deadline_without_timezone < datetime.datetime.now(),
    }))
Ejemplo n.º 2
0
 def GetEndTime(self):
     if not self.end_time:
         return None
     return timezones.ToLocalizedTime(
         self.end_time,
         self.schedule.get().competition.get().timezone)
Ejemplo n.º 3
0
 def GetStaffSignupDeadline(self):
     if not self.staff_signup_deadline:
         return None
     return timezones.ToLocalizedTime(self.staff_signup_deadline,
                                      self.timezone)
Ejemplo n.º 4
0
    def get(self, competition_id):
        # Unlike most scheduling handlers, it's okay here if the competition doesn't
        # exist, because that may just mean the user is creating the competition
        # here for the first time.  In this case redirect to /update.
        if not ScheduleCompetition.get_by_id(competition_id):
            self.redirect_to('update_competition',
                             competition_id=competition_id)
            return
        if not self.SetCompetition(competition_id):
            return
        timezones_and_times = [
            (timezone, datetime.datetime.now(
                pytz.timezone(timezone)).strftime('%I:%M %p'))
            for timezone in pytz.country_timezones('us')
        ]
        schedule_versions = Schedule.query(
            Schedule.competition == self.competition.key).fetch()

        # We look at the live schedule, or the most-recently updated one, and make
        # sure that it has events and start/end dates.
        schedule_for_staff_signup = None
        has_live_schedule = False
        if schedule_versions:
            for schedule in schedule_versions:
                if schedule.is_live:
                    schedule_for_staff_signup = schedule
                    has_live_schedule = True
            if not schedule_for_staff_signup:
                schedule_for_staff_signup = sorted(
                    schedule_versions, key=lambda s: s.last_update_time)[-1]
            has_rounds = (ScheduleRound.query(
                ScheduleRound.schedule ==
                schedule_for_staff_signup.key).iter().has_next())

        championships = Championship.query(Championship.competition == ndb.Key(
            Competition, competition_id)).fetch()
        if championships:
            if championships[0].residency_deadline:
                residency_deadline = timezones.ToLocalizedTime(
                    championships[0].residency_deadline,
                    self.competition.timezone or 'America/New_York')
            else:
                # If the residency deadline hasn't been set, use the day before the
                # competition starts.
                residency_deadline = (
                    datetime.datetime.combine(
                        championships[0].competition.get().start_date,
                        datetime.time(0, 0, 0)) -
                    datetime.timedelta(days=1)).replace(tzinfo=pytz.timezone(
                        self.competition.timezone or 'America/New_York'))
        else:
            residency_deadline = None

        template = JINJA_ENVIRONMENT.get_template(
            'scheduling/edit_competition.html')
        self.response.write(
            template.render({
                'c':
                common.Common(self),
                'competition':
                self.competition,
                'timezones_and_times':
                timezones_and_times,
                'schedule_versions':
                schedule_versions,
                'staff_signup_enabled':
                schedule_for_staff_signup
                and schedule_for_staff_signup.start_date and has_rounds,
                'has_live_schedule':
                has_live_schedule,
                'residency_deadline':
                residency_deadline
            }))