def test_team_updated(self): affected_refs = { 'key': {ndb.Key(Team, 'frc254'), ndb.Key(Team, 'frc604')}, } cache_keys = [ q.cache_key for q in get_affected_queries.team_updated(affected_refs) ] self.assertEqual(len(cache_keys), 16) self.assertTrue(TeamQuery('frc254').cache_key in cache_keys) self.assertTrue(TeamQuery('frc604').cache_key in cache_keys) self.assertTrue(TeamListQuery(0).cache_key in cache_keys) self.assertTrue(TeamListQuery(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(TeamListYearQuery(2010, 1).cache_key in cache_keys) self.assertTrue(DistrictTeamsQuery('2015fim').cache_key in cache_keys) self.assertTrue(DistrictTeamsQuery('2015mar').cache_key in cache_keys) self.assertTrue(DistrictTeamsQuery('2016ne').cache_key in cache_keys) self.assertTrue(EventTeamsQuery('2015casj').cache_key in cache_keys) self.assertTrue(EventTeamsQuery('2015cama').cache_key in cache_keys) self.assertTrue(EventTeamsQuery('2010cama').cache_key in cache_keys) self.assertTrue( EventEventTeamsQuery('2015casj').cache_key in cache_keys) self.assertTrue( EventEventTeamsQuery('2015cama').cache_key in cache_keys) self.assertTrue( EventEventTeamsQuery('2010cama').cache_key in cache_keys)
def team_updated(affected_refs): team_keys = filter(None, affected_refs['key']) event_team_keys_future = EventTeam.query( EventTeam.team.IN([team_key for team_key in team_keys ])).fetch_async(None, keys_only=True) district_team_keys_future = DistrictTeam.query( DistrictTeam.team.IN([team_key for team_key in team_keys ])).fetch_async(None, keys_only=True) queries_and_keys = [] for team_key in team_keys: queries_and_keys.append((TeamQuery(team_key.id()))) page_num = _get_team_page_num(team_key.id()) queries_and_keys.append((TeamListQuery(page_num))) for et_key in event_team_keys_future.get_result(): year = int(et_key.id()[:4]) event_key = et_key.id().split('_')[0] page_num = _get_team_page_num(et_key.id().split('_')[1]) queries_and_keys.append((TeamListYearQuery(year, page_num))) queries_and_keys.append((EventTeamsQuery(event_key))) for dt_key in district_team_keys_future.get_result(): district_key = dt_key.id().split('_')[0] queries_and_keys.append((DistrictTeamsQuery(district_key))) return queries_and_keys
def _render(self, model_type=None): max_team_key = Team.query().order(-Team.team_number).fetch( 1, keys_only=True)[0] max_team_num = int(max_team_key.id()[3:]) max_team_page = int(max_team_num / 500) futures = [] for page_num in xrange(max_team_page + 1): futures.append( TeamListQuery(page_num).fetch_async(dict_version=3, return_updated=True)) team_list = [] for future in futures: partial_team_list, last_modified = future.get_result() team_list += partial_team_list if self._last_modified is None or last_modified > self._last_modified: self._last_modified = last_modified if model_type is not None: team_list = filter_team_properties(team_list, model_type) return json.dumps(team_list, ensure_ascii=True, indent=2, sort_keys=True)
def _render(self, page_num, year=None, model_type=None): if year is None: team_list, self._last_modified = TeamListQuery(int(page_num)).fetch(dict_version=3, return_updated=True) else: team_list, self._last_modified = TeamListYearQuery(int(year), int(page_num)).fetch(dict_version=3, return_updated=True) if model_type is not None: team_list = filter_team_properties(team_list, model_type) return json.dumps(team_list, ensure_ascii=True, indent=2, sort_keys=True)
def _render(self, page_num): teams = TeamListQuery(int(page_num)).fetch() team_list = [ModelToDict.teamConverter(team) for team in teams] return json.dumps(team_list, ensure_ascii=True)