本文整理汇总了Python中models.team.Team.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Team.get_by_id方法的具体用法?Python Team.get_by_id怎么用?Python Team.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.team.Team
的用法示例。
在下文中一共展示了Team.get_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
def get(self, key_name):
df = DatafeedUsfirst()
legacy_df = DatafeedUsfirstLegacy()
team = df.getTeamDetails(Team.get_by_id(key_name))
if not team:
logging.warning("getTeamDetails with DatafeedUsfirst for event id {} failed. Retrying with DatafeedUsfirstLegacy.".format(key_name))
team = legacy_df.getTeamDetails(Team.get_by_id(key_name))
else:
legacy_team = legacy_df.getTeamDetails(Team.get_by_id(key_name))
if legacy_team is not None:
team.rookie_year = legacy_team.rookie_year # only available on legacy df
if team:
team = TeamManipulator.createOrUpdate(team)
success = True
else:
success = False
template_values = {
'key_name': key_name,
'team': team,
'success': success,
}
path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_team_details_get.html')
self.response.out.write(template.render(path, template_values))
示例2: _render
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
def _render(self, *args, **kw):
team_a = Team.get_by_id(self._team_key_a) if self._team_key_a else None
team_b = Team.get_by_id(self._team_key_b) if self._team_key_b else None
self.template_values.update({
'team_a': team_a,
'team_b': team_b,
})
return jinja2_engine.render('2champs.html', self.template_values)
示例3: get
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
def get(self, key_name):
# Combines data from three datafeeds with priorities:
# 1) DatafeedFMSAPI
# 2) DatafeedUsfirst (missing rookie year)
# 3) DatafeedUsfirstLegacy (has all info)
legacy_df = DatafeedUsfirstLegacy()
usfirst_df = DatafeedUsfirst()
fms_df = DatafeedFMSAPI('v2.0')
# Start with lowest priority
legacy_team = legacy_df.getTeamDetails(Team.get_by_id(key_name))
usfirst_team = usfirst_df.getTeamDetails(Team.get_by_id(key_name))
fms_details = fms_df.getTeamDetails(tba_config.MAX_YEAR, key_name)
# Separate out the multiple models returned from FMSAPI call
# Since we're only hitting one team at a time, the response won't
# ever be paginated so we can ignore the possibility
if fms_details and fms_details[0]:
models, more_pages = fms_details
fms_team, district_team, robot = models[0]
else:
fms_team = None
district_team = None
robot = None
team = None
if usfirst_team:
team = TeamManipulator.updateMergeBase(usfirst_team, legacy_team)
if fms_team:
team = TeamManipulator.updateMergeBase(fms_team, team)
if district_team:
district_team = DistrictTeamManipulator.createOrUpdate(district_team)
if robot:
robot = RobotManipulator.createOrUpdate(robot)
if team:
team = TeamManipulator.createOrUpdate(team)
success = True
else:
success = False
logging.warning("getTeamDetails failed for team: {}".format(key_name))
template_values = {
'key_name': key_name,
'team': team,
'success': success,
'district': district_team,
'robot': robot,
}
path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_team_details_get.html')
self.response.out.write(template.render(path, template_values))
示例4: get
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
def get(self, key_name):
# Combines data from three datafeeds with priorities:
# 1) DatafeedFMSAPI (missing website)
# 2) DatafeedUsfirst (missing rookie year)
# 3) DatafeedUsfirstLegacy (has all info)
legacy_df = DatafeedUsfirstLegacy()
usfirst_df = DatafeedUsfirst()
fms_df = DatafeedFMSAPI('v2.0')
# Start with lowest priority
legacy_team = legacy_df.getTeamDetails(Team.get_by_id(key_name))
usfirst_team = usfirst_df.getTeamDetails(Team.get_by_id(key_name))
fms_details = fms_df.getTeamDetails(date.today().year, key_name)
if fms_details:
fms_team, district_team, robot = fms_details
else:
fms_team = None
district_team = None
robot = None
team = None
if usfirst_team:
team = TeamManipulator.updateMergeBase(usfirst_team, legacy_team)
if fms_team:
team = TeamManipulator.updateMergeBase(fms_team, team)
if district_team:
district_team = DistrictTeamManipulator.createOrUpdate(district_team)
if robot:
robot = RobotManipulator.createOrUpdate(robot)
if team:
team = TeamManipulator.createOrUpdate(team)
success = True
else:
success = False
logging.warning("getTeamDetails failed for team: {}".format(key_name))
template_values = {
'key_name': key_name,
'team': team,
'success': success,
'district': district_team,
'robot': robot,
}
path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_team_details_get.html')
self.response.out.write(template.render(path, template_values))
示例5: test_create_lots_of_teams
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
def test_create_lots_of_teams(self):
number = 500
teams = [Team(
id = "frc%s" % team_number,
team_number = team_number)
for team_number in range(number)]
TeamManipulator.createOrUpdate(teams)
team = Team.get_by_id("frc177")
self.assertEqual(team.key_name, "frc177")
self.assertEqual(team.team_number, 177)
team = Team.get_by_id("frc%s" % (number - 1))
self.assertEqual(team.key_name, "frc%s" % (number - 1))
self.assertEqual(team.team_number, number - 1)
示例6: getTeamInfo
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
def getTeamInfo(self, team_key):
"""
Return a Team dict with basic information.
"""
memcache_key = "api_team_info_%s" % team_key
team_dict = memcache.get(memcache_key)
if team_dict is None:
team = Team.get_by_id(team_key)
if team is not None:
team_dict = dict()
team_dict["key"] = team.key_name
team_dict["team_number"] = team.team_number
team_dict["name"] = team.name
team_dict["nickname"] = team.nickname
team_dict["website"] = team.website
team_dict["location"] = team.location
event_teams = EventTeam.query(EventTeam.team == team.key,\
EventTeam.year == datetime.now().year)\
.fetch(1000, projection=[EventTeam.event])
team_dict["events"] = [event_team.event.id() for event_team in event_teams]
try:
team_dict["location"] = team.location
team_dict["locality"] = team.locality
team_dict["region"] = team.region
team_dict["country_name"] = team.country_name
except Exception, e:
logging.warning("Failed to include Address for api_team_info_%s: %s" % (team_key, e))
#TODO: Reduce caching time before 2013 season. 2592000 is one month -gregmarra
if tba_config.CONFIG["memcache"]: memcache.set(memcache_key, team_dict, 2592000)
else:
raise IndexError
示例7: addTeamDetails
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
def addTeamDetails(self, team_dict, year):
"""
Consume a Team dict, and return it with a year's Events filtered and Matches added
"""
# TODO Matches should live under Events - gregmarra 1 feb 2011
# TODO Filter Events by year - gregmarra 1 feb 2011
memcache_key = "api_team_details_%s_%s" % (team_dict["key"], year)
matches_list = memcache.get(memcache_key)
if matches_list is None:
matches = list()
team = Team.get_by_id(team_dict["key"])
for e in [a.event.get() for a in EventTeam.query(EventTeam.team == team.key).fetch(1000) if a.year == year]:
match_list = Match.query(Match.event == event.key, Match.team_key_names == team.key_name).fetch(500)
matches.extend(match_list)
matches_list = list()
for match in matches:
match_dict = dict()
match_dict["key"] = match.key_name
match_dict["event"] = match.event
match_dict["comp_level"] = match.comp_level
match_dict["set_number"] = match.set_number
match_dict["match_number"] = match.match_number
match_dict["team_keys"] = match.team_key_names
match_dict["alliances"] = json.loads(match.alliances_json)
matches_list.append(match_dict)
#TODO: Reduce caching time before 2013 season. 2592000 is one month -gregmarra
if tba_config.CONFIG["memcache"]: memcache.set(memcache_key, matches_list, 2592000)
team_dict["matches"] = matches_list
return team_dict
示例8: _render
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
def _render(self, team_number):
team = Team.get_by_id("frc" + team_number)
if not team:
return self.redirect("/error/404")
event_team_keys_future = EventTeam.query(EventTeam.team == team.key).fetch_async(1000, keys_only=True)
award_keys_future = Award.query(Award.team == team.key).fetch_async(1000, keys_only=True)
event_teams_futures = ndb.get_multi_async(event_team_keys_future.get_result())
awards_futures = ndb.get_multi_async(award_keys_future.get_result())
event_keys = [event_team_future.get_result().event for event_team_future in event_teams_futures]
events_futures = ndb.get_multi_async(event_keys)
awards_by_event = {}
for award_future in awards_futures:
award = award_future.get_result()
if award.event.id() not in awards_by_event:
awards_by_event[award.event.id()] = [award]
else:
awards_by_event[award.event.id()].append(award)
event_awards = []
current_event = None
matches_upcoming = None
short_cache = False
for event_future in events_futures:
event = event_future.get_result()
if event.now:
current_event = event
team_matches_future = Match.query(Match.event == event.key, Match.team_key_names == team.key_name)\
.fetch_async(500, keys_only=True)
matches = ndb.get_multi(team_matches_future.get_result())
matches_upcoming = MatchHelper.upcomingMatches(matches)
if event.within_a_day:
short_cache = True
if event.key_name in awards_by_event:
sorted_awards = AwardHelper.organizeAwards(awards_by_event[event.key_name])['list']
else:
sorted_awards = []
event_awards.append((event, sorted_awards))
event_awards = sorted(event_awards, key=lambda (e, _): e.start_date if e.start_date else datetime.datetime(e.year, 12, 31))
years = sorted(set([et.get_result().year for et in event_teams_futures if et.get_result().year != None]))
template_values = {'team': team,
'event_awards': event_awards,
'years': years,
'current_event': current_event,
'matches_upcoming': matches_upcoming}
if short_cache:
self._cache_expiration = self.SHORT_CACHE_EXPIRATION
path = os.path.join(os.path.dirname(__file__), '../templates/team_history.html')
return template.render(path, template_values)
示例9: get
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
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))
示例10: get
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
def get(self, team_number):
self._require_login()
self._require_registration()
team_key = 'frc{}'.format(team_number)
team = Team.get_by_id(team_key)
if not team:
self.abort(404)
user = self.user_bundle.account.key
favorite = Favorite.query(Favorite.model_key==team_key, Favorite.model_type==ModelType.TEAM, ancestor=user).get()
subscription = Subscription.query(Favorite.model_key==team_key, Favorite.model_type==ModelType.TEAM, ancestor=user).get()
if not favorite and not subscription: # New entry; default to being a favorite
is_favorite = True
else:
is_favorite = favorite is not None
enabled_notifications = [(en, NotificationType.render_names[en]) for en in NotificationType.enabled_team_notifications]
self.template_values['team'] = team
self.template_values['is_favorite'] = is_favorite
self.template_values['subscription'] = subscription
self.template_values['enabled_notifications'] = enabled_notifications
self.response.out.write(jinja2_engine.render('mytba_team.html', self.template_values))
示例11: get
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
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))
示例12: _getteam_rookieyear
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
def _getteam_rookieyear(cls, request):
team_number = request['result']['parameters']['team_number']
team = Team.get_by_id('frc{}'.format(team_number))
if team:
fmt = 'Team {0} first competed in {1}. Would you like to know more about {0} or another team?'
text = fmt.format(
team_number, team.rookie_year)
tts = fmt.format(
cls._team_number_tts(team_number), team.rookie_year)
messages = cls._create_simple_response(text, tts=tts) + \
cls._create_suggestion_chips([
'Next match',
'Current status',
'Location',
'Another team',
'No thanks',
])
else:
fmt = 'Team {0} does not exist. Please ask about another team.'
text = fmt.format(team_number)
tts = fmt.format(cls._team_number_tts(team_number))
messages = cls._create_simple_response(text, tts=tts)
return {
'speech': text,
'messages': messages,
}
示例13: get
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
def get(self, team_key):
team = Team.get_by_id(team_key)
lat_lon = team.get_lat_lon()
if lat_lon:
fields = [
search.GeoField(name='location', value=search.GeoPoint(lat_lon[0], lat_lon[1]))
]
search.Index(name="teamLocation").put(search.Document(doc_id=team.key.id(), fields=fields))
示例14: _render
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
def _render(self, team_number, year):
team = Team.get_by_id("frc{}".format(team_number))
if not team:
self.abort(404)
rendered_result = TeamRenderer.render_team_details(self, team, int(year), False)
if rendered_result is None:
self.abort(404)
else:
return rendered_result
示例15: get
# 需要导入模块: from models.team import Team [as 别名]
# 或者: from models.team.Team import get_by_id [as 别名]
def get(self):
try:
q = self.request.get("q")
logging.info("search query: %s" % q)
if q.isdigit():
team_id = "frc%s" % q
team = Team.get_by_id(team_id)
if team:
self.redirect(team.details_url)
return None
except Exception, e:
logging.warning("warning: %s" % e)