本文整理汇总了Python中models.district_team.DistrictTeam类的典型用法代码示例。如果您正苦于以下问题:Python DistrictTeam类的具体用法?Python DistrictTeam怎么用?Python DistrictTeam使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DistrictTeam类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDistrictTeamsApiController
class TestDistrictTeamsApiController(unittest2.TestCase):
def setUp(self):
app = webapp2.WSGIApplication(
[webapp2.Route(r"/<district_abbrev:>/<year:([0-9]*)>", ApiDistrictTeamsController, methods=["GET"])],
debug=True,
)
self.testapp = webtest.TestApp(app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
self.testbed.init_taskqueue_stub(root_path=".")
self.team = Team(
id="frc281",
name="Michelin / Caterpillar / Greenville Technical College /\
jcpenney / Baldor / ASME / Gastroenterology Associates /\
Laserflex South & Greenville County Schools & Greenville\
Technical Charter High School",
team_number=281,
nickname="EnTech GreenVillians",
city="Greenville",
state_prov="SC",
country="USA",
website="www.entech.org",
motto="Infiltrating Young Minds One Robot at a Time",
)
self.district_team = DistrictTeam(id="2015ne_frc281", team=self.team.key, year=2015, district=3)
self.team.put()
self.district_team.put()
def tearDown(self):
self.testbed.deactivate()
def assertTeamJson(self, team):
team = team[0]
self.assertEqual(team["key"], self.team.key_name)
self.assertEqual(team["team_number"], self.team.team_number)
self.assertEqual(team["nickname"], self.team.nickname)
self.assertEqual(team["location"], self.team.location)
self.assertEqual(team["locality"], "Greenville")
self.assertEqual(team["country_name"], "USA")
self.assertEqual(team["region"], "SC")
self.assertEqual(team["website"], self.team.website)
self.assertEqual(team["motto"], self.team.motto)
def testDistrictsApi(self):
response = self.testapp.get(
"/ne/2015", headers={"X-TBA-App-Id": "tba-tests:team-districts-controller-test:v01"}
)
teams = json.loads(response.body)
self.assertTeamJson(teams)
示例2: setUp
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
self.testbed.init_taskqueue_stub(root_path=".")
self.eventteam_2015casj_frc254 = EventTeam(
id='2015casj_frc254',
event=ndb.Key(Event, '2015casj'),
team=ndb.Key(Team, 'frc254'),
year=2015,
)
self.eventteam_2015cama_frc604 = EventTeam(
id='2015cama_frc604',
event=ndb.Key(Event, '2015cama'),
team=ndb.Key(Team, 'frc604'),
year=2015,
)
self.eventteam_2010cama_frc604 = EventTeam(
id='2010cama_frc604',
event=ndb.Key(Event, '2010cama'),
team=ndb.Key(Team, 'frc604'),
year=2010,
)
self.eventteam_2015casj_frc254.put()
self.eventteam_2015cama_frc604.put()
self.eventteam_2010cama_frc604.put()
self.districtteam_2015fim_frc254 = DistrictTeam(
id='2015fim_frc254',
district=DistrictType.MICHIGAN,
team=ndb.Key(Team, 'frc254'),
year=2015,
)
self.districtteam_2015mar_frc604 = DistrictTeam(
id='2015mar_frc604',
district=DistrictType.MID_ATLANTIC,
team=ndb.Key(Team, 'frc604'),
year=2015,
)
self.districtteam_2015fim_frc254.put()
self.districtteam_2015mar_frc604.put()
示例3: TestTeamHistoryDistrictsApiController
class TestTeamHistoryDistrictsApiController(unittest2.TestCase):
def setUp(self):
app = webapp2.WSGIApplication([webapp2.Route(r'/<team_key:>', ApiTeamHistoryDistrictsController, methods=['GET'])], debug=True)
self.testapp = webtest.TestApp(app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
self.testbed.init_taskqueue_stub(root_path=".")
self.team = Team(
id="frc1124",
name="UberBots",
team_number=1124,
nickname="UberBots"
)
self.district_team = DistrictTeam(
id="2015ne_frc1124",
team=self.team.key,
year=2015,
district_key=ndb.Key(District, '2015ne')
)
self.district = District(
id='2015ne',
year=2015
)
self.team.put()
self.district_team.put()
self.district.put()
def tearDown(self):
self.testbed.deactivate()
def testDistrictsApi(self):
response = self.testapp.get('/frc1124', headers={"X-TBA-App-Id": "tba-tests:team-history-districts-controller-test:v01"})
district_dict = json.loads(response.body)
self.assertTrue("2015" in district_dict)
district_key = district_dict["2015"]
self.assertEqual(district_key, "2015ne")
示例4: setUp
def setUp(self):
app = webapp2.WSGIApplication([webapp2.Route(r'/<team_key:>', ApiTeamHistoryDistrictsController, methods=['GET'])], debug=True)
self.testapp = webtest.TestApp(app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
self.testbed.init_taskqueue_stub(root_path=".")
self.team = Team(
id="frc1124",
name="UberBots",
team_number=1124,
nickname="UberBots"
)
self.district_team = DistrictTeam(
id="2015ne_frc1124",
team=self.team.key,
year=2015,
district_key=ndb.Key(District, '2015ne')
)
self.district = District(
id='2015ne',
year=2015
)
self.team.put()
self.district_team.put()
self.district.put()
示例5: setUp
def setUp(self):
app = webapp2.WSGIApplication([webapp2.Route(r'/<district_abbrev:>/<year:([0-9]*)>', ApiDistrictTeamsController, methods=['GET'])], debug=True)
self.testapp = webtest.TestApp(app)
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_urlfetch_stub()
self.testbed.init_memcache_stub()
self.testbed.init_taskqueue_stub(root_path=".")
self.team = Team(
id="frc281",
name="Michelin / Caterpillar / Greenville Technical College /\
jcpenney / Baldor / ASME / Gastroenterology Associates /\
Laserflex South & Greenville County Schools & Greenville\
Technical Charter High School",
team_number=281,
nickname="EnTech GreenVillians",
address="Greenville, SC, USA",
website="www.entech.org",
motto = "Infiltrating Young Minds One Robot at a Time",
)
self.district_team = DistrictTeam(
id="2015ne_frc281",
team=self.team.key,
year=2015,
district=3
)
self.team.put()
self.district_team.put()
示例6: district_updated
def district_updated(affected_refs):
years = _filter(affected_refs['year'])
district_abbrevs = _filter(affected_refs['abbreviation'])
district_keys = _filter(affected_refs['key'])
district_team_keys_future = DistrictTeam.query(DistrictTeam.district_key.IN(list(district_keys))).fetch_async(None, keys_only=True)
district_event_keys_future = Event.query(Event.district_key.IN(list(district_keys))).fetch_async(keys_only=True)
queries_and_keys = []
for year in years:
queries_and_keys.append(DistrictsInYearQuery(year))
for abbrev in district_abbrevs:
queries_and_keys.append(DistrictHistoryQuery(abbrev))
for key in district_keys:
queries_and_keys.append(DistrictQuery(key.id()))
for dt_key in district_team_keys_future.get_result():
team_key = dt_key.id().split('_')[1]
queries_and_keys.append(TeamDistrictsQuery(team_key))
# Necessary because APIv3 Event models include the District model
affected_event_refs = {
'key': set(),
'year': set(),
'district_key': district_keys,
}
for event_key in district_event_keys_future.get_result():
affected_event_refs['key'].add(event_key)
affected_event_refs['year'].add(int(event_key.id()[:4]))
queries_and_keys += event_updated(affected_event_refs)
return queries_and_keys
示例7: team_updated
def team_updated(affected_refs):
team_keys = _filter(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)))
queries_and_keys.append((EventEventTeamsQuery(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
示例8: get
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))
示例9: _query_async
def _query_async(self):
district_key = self._query_args[0]
district_teams = yield DistrictTeam.query(
DistrictTeam.district_key == ndb.Key(District, district_key)).fetch_async()
team_keys = map(lambda district_team: district_team.team, district_teams)
teams = yield ndb.get_multi_async(team_keys)
raise ndb.Return(teams)
示例10: get
def get(self, team_number):
self._require_admin()
team = Team.get_by_id("frc" + team_number)
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()
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]
self.template_values.update({
'event_teams': event_teams,
'team': team,
'team_medias_by_year': team_medias_by_year,
'robots': robots,
'district_teams': district_teams,
})
path = os.path.join(os.path.dirname(__file__), '../../templates/admin/team_details.html')
self.response.out.write(template.render(path, self.template_values))
示例11: parse
def parse(self, response):
"""
Parse team info from FMSAPI
Returns a tuple of: list of models (Team, DistrictTeam, Robot),
and a Boolean indicating if there are more pages to be fetched
"""
# Get team json
# don't need to null check, if error, HTTP code != 200, so we wont' get here
current_page = response['pageCurrent']
total_pages = response['pageTotal']
teams = response['teams']
ret_models = []
for teamData in teams:
# Fix issue where FIRST's API returns dummy website for all teams
if teamData['website'] is not None and 'www.firstinspires.org' in teamData['website']:
website = None
else:
website = WebsiteHelper.format_url(teamData.get('website', None))
team = Team(
id="frc{}".format(teamData['teamNumber']),
team_number=teamData['teamNumber'],
name=teamData['nameFull'],
nickname=teamData['nameShort'],
school_name=teamData.get('schoolName'),
home_cmp=teamData.get('homeCMP').lower() if teamData.get('homeCMP') else None,
city=teamData['city'],
state_prov=teamData['stateProv'],
country=teamData['country'],
website=website,
rookie_year=teamData['rookieYear']
)
districtTeam = None
if teamData['districtCode']:
districtAbbrev = DistrictType.abbrevs[teamData['districtCode'].lower()]
districtTeam = DistrictTeam(
id=DistrictTeam.renderKeyName(self.year, districtAbbrev, team.key_name),
team=ndb.Key(Team, team.key_name),
year=self.year,
district=districtAbbrev,
district_key=ndb.Key(District, District.renderKeyName(self.year, teamData['districtCode'].lower())),
)
robot = None
if teamData['robotName']:
robot = Robot(
id=Robot.renderKeyName(team.key_name, self.year),
team=ndb.Key(Team, team.key_name),
year=self.year,
robot_name=teamData['robotName'].strip()
)
ret_models.append((team, districtTeam, robot))
return (ret_models, (current_page < total_pages))
示例12: parse
def parse(self, response):
"""
Parse team info from FMSAPI
Returns a tuple of: list of models (Team, DistrictTeam, Robot),
and a Boolean indicating if there are more pages to be fetched
"""
# Get team json
# don't need to null check, if error, HTTP code != 200, so we wont' get here
current_page = response['pageCurrent']
total_pages = response['pageTotal']
teams = response['teams']
ret_models = []
for teamData in teams:
# concat city/state/country to get address
address = u"{}, {}, {}".format(teamData['city'], teamData['stateProv'], teamData['country'])
team = Team(
id="frc{}".format(teamData['teamNumber']),
team_number=teamData['teamNumber'],
name=teamData['nameFull'],
nickname=teamData['nameShort'],
address=address,
website=teamData['website'],
rookie_year=teamData['rookieYear']
)
districtTeam = None
if teamData['districtCode']:
districtAbbrev = DistrictType.abbrevs[teamData['districtCode'].lower()]
districtTeam = DistrictTeam(
id=DistrictTeam.renderKeyName(self.year, districtAbbrev, team.key_name),
team=ndb.Key(Team, team.key_name),
year=self.year,
district=districtAbbrev
)
robot = None
if teamData['robotName']:
robot = Robot(
id=Robot.renderKeyName(team.key_name, self.year),
team=ndb.Key(Team, team.key_name),
year=self.year,
robot_name=teamData['robotName'].strip()
)
ret_models.append((team, districtTeam, robot))
return (ret_models, (current_page < total_pages))
示例13: get
def get(self, year):
year = int(year)
year_dcmps = DistrictChampsInYearQuery(year).fetch()
districts_to_write = []
for dcmp in year_dcmps:
district_abbrev = DistrictType.type_abbrevs[dcmp.event_district_enum]
district_key = District.renderKeyName(year, district_abbrev)
logging.info("Creating {}".format(district_key))
district = District(
id=district_key,
year=year,
abbreviation=district_abbrev,
display_name=DistrictType.type_names[dcmp.event_district_enum],
elasticsearch_name=next((k for k, v in DistrictType.elasticsearch_names.iteritems() if v == dcmp.event_district_enum), None)
)
districts_to_write.append(district)
logging.info("Writing {} new districts".format(len(districts_to_write)))
DistrictManipulator.createOrUpdate(districts_to_write, run_post_update_hook=False)
for dcmp in year_dcmps:
district_abbrev = DistrictType.type_abbrevs[dcmp.event_district_enum]
district_key = District.renderKeyName(year, district_abbrev)
district_events_future = DistrictEventsQuery(district_key).fetch_async()
district_events = district_events_future.get_result()
logging.info("Found {} events to update".format(len(district_events)))
events_to_write = []
for event in district_events:
event.district_key = ndb.Key(District, district_key)
events_to_write.append(event)
EventManipulator.createOrUpdate(events_to_write)
for dcmp in year_dcmps:
district_abbrev = DistrictType.type_abbrevs[dcmp.event_district_enum]
district_key = District.renderKeyName(year, district_abbrev)
districtteams_future = DistrictTeam.query(DistrictTeam.year == year, DistrictTeam.district == DistrictType.abbrevs.get(district_abbrev, None)).fetch_async()
districtteams = districtteams_future.get_result()
logging.info("Found {} DistrictTeams to update".format(len(districtteams)))
districtteams_to_write = []
for districtteam in districtteams:
districtteam.district_key = ndb.Key(District, district_key)
districtteams_to_write.append(districtteam)
DistrictTeamManipulator.createOrUpdate(districtteams_to_write)
示例14: parse
def parse(self, response):
"""
Parse team info from FMSAPI
Returns a tuple of models (Team, DistrictTeam, Robot)
"""
# Get team json
# don't need to null check, if error, HTTP code != 200, so we wont' get here
teams = response["teams"]
teamData = teams[0]
# concat city/state/country to get address
address = u"{}, {}, {}".format(teamData["city"], teamData["stateProv"], teamData["country"])
team = Team(
team_number=teamData["teamNumber"],
name=teamData["nameFull"],
nickname=teamData["nameShort"],
address=address,
rookie_year=teamData["rookieYear"],
)
districtTeam = None
if teamData["districtCode"]:
districtAbbrev = DistrictType.abbrevs[teamData["districtCode"].lower()]
districtTeam = DistrictTeam(
id=DistrictTeam.renderKeyName(self.year, districtAbbrev, team.key_name),
team=ndb.Key(Team, team.key_name),
year=self.year,
district=districtAbbrev,
)
robot = None
if teamData["robotName"]:
robot = Robot(
id=Robot.renderKeyName(team.key_name, self.year),
team=ndb.Key(Team, team.key_name),
year=self.year,
robot_name=teamData["robotName"].strip(),
)
return (team, districtTeam, robot)
示例15: get_team_cache_keys_and_controllers
def get_team_cache_keys_and_controllers(cls, affected_refs):
"""
Gets cache keys and controllers that references this team
"""
team_keys = 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)
event_keys = set()
for et_key in event_team_keys_future.get_result():
event_key_name = et_key.id().split('_')[0]
event_keys.add(ndb.Key(Event, event_key_name))
district_keys = set()
for dt_key in district_team_keys_future.get_result():
district_key_name = dt_key.id().split('_')[0]
district_keys.add(district_key_name)
return cls._get_teams_cache_keys_and_controllers(team_keys) + \
cls._get_eventteams_cache_keys_and_controllers(event_keys) + \
cls._get_teamlist_cache_keys_and_controllers(team_keys) + \
cls._get_districtteams_cache_keys_and_controllers(district_keys, team_keys) + \
cls._queries_to_cache_keys_and_controllers(get_affected_queries.team_updated(affected_refs))