Exemplo n.º 1
0
    def test_eventteam_updated(self):
        affected_refs = {
            'event': {ndb.Key(Event, '2015casj'),
                      ndb.Key(Event, '2015cama')},
            'team': {ndb.Key(Team, 'frc254'),
                     ndb.Key(Team, 'frc604')},
            'year': {2014, 2015}
        }
        cache_keys = [
            q.cache_key
            for q in get_affected_queries.eventteam_updated(affected_refs)
        ]

        self.assertEqual(len(cache_keys), 14)
        self.assertTrue(TeamEventsQuery('frc254').cache_key in cache_keys)
        self.assertTrue(TeamEventsQuery('frc604').cache_key in cache_keys)
        self.assertTrue(
            TeamParticipationQuery('frc254').cache_key in cache_keys)
        self.assertTrue(
            TeamParticipationQuery('frc604').cache_key in cache_keys)
        self.assertTrue(
            TeamYearEventsQuery('frc254', 2014).cache_key in cache_keys)
        self.assertTrue(
            TeamYearEventsQuery('frc254', 2015).cache_key in cache_keys)
        self.assertTrue(
            TeamYearEventsQuery('frc604', 2014).cache_key in cache_keys)
        self.assertTrue(
            TeamYearEventsQuery('frc604', 2015).cache_key in cache_keys)
        self.assertTrue(TeamListYearQuery(2014, 0).cache_key in cache_keys)
        self.assertTrue(TeamListYearQuery(2014, 1).cache_key in cache_keys)
        self.assertTrue(TeamListYearQuery(2015, 0).cache_key in cache_keys)
        self.assertTrue(TeamListYearQuery(2015, 1).cache_key in cache_keys)
        self.assertTrue(EventTeamsQuery('2015casj').cache_key in cache_keys)
        self.assertTrue(EventTeamsQuery('2015cama').cache_key in cache_keys)
    def get(self, team_number):
        self._require_admin()

        team = Team.get_by_id("frc" + team_number)
        if not team:
            self.abort(404)
        event_teams = EventTeam.query(EventTeam.team == team.key).fetch(500)
        team_medias = Media.query(Media.references == team.key).fetch(500)
        robots = Robot.query(Robot.team == team.key).fetch()
        district_teams = DistrictTeam.query(
            DistrictTeam.team == team.key).fetch()
        years_participated = sorted(
            TeamParticipationQuery(team.key_name).fetch())

        team_medias_by_year = {}
        for media in team_medias:
            if media.year in team_medias_by_year:
                team_medias_by_year[media.year].append(media)
            else:
                team_medias_by_year[media.year] = [media]
        media_years = sorted(team_medias_by_year.keys(), reverse=True)

        self.template_values.update({
            'event_teams': event_teams,
            'team': team,
            'team_media_years': media_years,
            'team_medias_by_year': team_medias_by_year,
            'robots': robots,
            'district_teams': district_teams,
            'years_participated': years_participated,
        })

        path = os.path.join(os.path.dirname(__file__),
                            '../../templates/admin/team_details.html')
        self.response.out.write(template.render(path, self.template_values))
Exemplo n.º 3
0
    def _render(self, team_key, year):
        if int(year) not in list(TeamParticipationQuery(team_key).fetch()):
            self.abort(404)

        if 'media_url' in self.request.POST:
            status, suggestion = SuggestionCreator.createTeamMediaSuggestion(
                author_account_key=self.auth_owner_key,
                media_url=self.request.POST["media_url"],
                team_key=team_key,
                year_str=year)

            if status == 'success':
                message = {
                    "success": True
                }
            else:
                message = {
                    "success": False,
                    "message": status
                }
        else:
            message = {
                "success": False,
                "message": "missing media_url"
            }

        return json.dumps(message, ensure_ascii=True, indent=2, sort_keys=True)
Exemplo n.º 4
0
    def _render(self, team_key):
        years_participated, self._last_modified = TeamParticipationQuery(
            team_key).fetch(return_updated=True)
        years_participated = sorted(years_participated)

        return json.dumps(years_participated,
                          ensure_ascii=True,
                          indent=2,
                          sort_keys=True)
Exemplo n.º 5
0
def eventteam_updated(affected_refs):
    event_keys = filter(None, affected_refs['event'])
    team_keys = filter(None, affected_refs['team'])
    years = filter(None, affected_refs['year'])

    queries_and_keys = []
    for team_key in team_keys:
        queries_and_keys.append(TeamEventsQuery(team_key.id()))
        queries_and_keys.append(TeamParticipationQuery(team_key.id()))
        page_num = _get_team_page_num(team_key.id())
        for year in years:
            queries_and_keys.append(TeamYearEventsQuery(team_key.id(), year))
            queries_and_keys.append(TeamListYearQuery(year, page_num))

    for event_key in event_keys:
        queries_and_keys.append(EventTeamsQuery(event_key.id()))

    return queries_and_keys
Exemplo n.º 6
0
 def update_team_location_index(cls, team):
     if team.normalized_location and team.normalized_location.lat_lng:
         partial_fields = [
             search.GeoField(name='location',
                             value=search.GeoPoint(
                                 team.normalized_location.lat_lng.lat,
                                 team.normalized_location.lat_lng.lon))
         ]
         # Teams by year
         for year in TeamParticipationQuery(team.key.id()).fetch():
             fields = partial_fields + [
                 search.NumberField(name='year', value=year)
             ]
             search.Index(name=cls.TEAM_LOCATION_INDEX).put(
                 search.Document(doc_id='{}_{}'.format(team.key.id(), year),
                                 fields=fields))
         # Any year
         search.Index(name=cls.TEAM_LOCATION_INDEX).put(
             search.Document(doc_id=team.key.id(), fields=partial_fields))
Exemplo n.º 7
0
    def _render(self, team_key):
        years_participated = sorted(TeamParticipationQuery(self.team_key).fetch())

        return json.dumps(years_participated, ensure_ascii=True)