本文整理汇总了Python中models.event_team.EventTeam.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python EventTeam.get_by_id方法的具体用法?Python EventTeam.get_by_id怎么用?Python EventTeam.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.event_team.EventTeam
的用法示例。
在下文中一共展示了EventTeam.get_by_id方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import get_by_id [as 别名]
def post(self, event_key_id):
self._require_admin()
event = Event.get_by_id(event_key_id)
if not event:
self.redirect("/admin/event/" + event.key_name)
return
event_details = event.details
if not event_details or not event_details.alliance_selections:
# No alliance data to modify
self.redirect("/admin/event/" + event.key_name)
return
team_in = "frc{}".format(self.request.get("backup_in"))
team_out = "frc{}".format(self.request.get("backup_out"))
# Make sure both teams are attending the event
et_in = EventTeam.get_by_id("{}_{}".format(event.key_name, team_in))
et_out = EventTeam.get_by_id("{}_{}".format(event.key_name, team_out))
if not et_in and et_out:
# Bad teams supplied
self.redirect("/admin/event/" + event.key_name)
return
for alliance in event_details.alliance_selections:
if team_out in alliance.get('picks', []):
alliance['backup'] = {}
alliance['backup']['in'] = team_in
alliance['backup']['out'] = team_out
EventDetailsManipulator.createOrUpdate(event_details)
break
self.redirect("/admin/event/" + event.key_name)
return
示例2: test_repair
# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import get_by_id [as 别名]
def test_repair(self):
event_team = EventTeam.get_by_id("2011ct_frc177")
self.assertEqual(event_team.year, None)
broken_event_teams = EventTeam.query(EventTeam.year == None).fetch()
self.assertGreater(len(broken_event_teams), 0)
fixed_event_teams = EventTeamRepairer.repair(broken_event_teams)
fixed_event_teams = EventTeamManipulator.createOrUpdate(fixed_event_teams)
event_team = EventTeam.get_by_id("2011ct_frc177")
self.assertEqual(event_team.year, 2011)
示例3: test_doEventTeamUpdate
# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import get_by_id [as 别名]
def test_doEventTeamUpdate(self):
# call EventTeamUpdate with 2010sc
eventteamupdate = EventTeamUpdate()
eventteamupdate.response = Response()
eventteamupdate.get("2010sc")
# Teams were generated by EventTeamUpdate, make sure EventTeams
# exist and feature Team Keys
event_team_from_match_one = EventTeam.get_by_id("2010sc_frc69")
self.assertEqual(event_team_from_match_one.event, self.event.key)
self.assertEqual(event_team_from_match_one.team, ndb.Key(Team, "frc69"))
event_team_from_match_two = EventTeam.get_by_id("2010sc_frc20")
self.assertEqual(event_team_from_match_two.event, self.event.key)
self.assertEqual(event_team_from_match_two.team, ndb.Key(Team, "frc20"))
示例4: _getteam_status
# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import get_by_id [as 别名]
def _getteam_status(cls, request):
team_number = request['result']['parameters']['team_number']
team_key = 'frc{}'.format(team_number)
team = Team.get_by_id(team_key)
if team:
events = TeamYearEventsQuery(team_key, datetime.datetime.now().year).fetch()
current_event = None
for event in events:
if event.now:
current_event = event
if current_event:
event_team = EventTeam.get_by_id('{}_{}'.format(current_event.key.id(), team_key))
text = EventTeamStatusHelper.generate_team_at_event_status_string(
team_key, event_team.status, formatting=False, event=current_event)
tts = 'Team {} {}'.format(
cls._team_number_tts(team_number),
EventTeamStatusHelper.generate_team_at_event_status_string(
team_key, event_team.status, formatting=False, event=current_event, include_team=False, verbose=True))
additional_prompt = ' Would you like to know more about {} or another team?'.format(team_number)
text += additional_prompt
tts += additional_prompt
messages = cls._create_simple_response(text, tts=tts) +\
cls._create_link_chip(current_event.display_name, 'https://www.thebluealliance.com/event/{}'.format(current_event.key.id()))
else:
fmt = 'Team {0} is not currently competing. Would you like to know more about {0} or another team?'
text = fmt.format(
team_number)
tts = fmt.format(
cls._team_number_tts(team_number))
messages = cls._create_simple_response(text, tts=tts)
messages += cls._create_suggestion_chips([
'Next match',
'Location',
'Rookie year',
'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,
}
示例5: _render
# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import get_by_id [as 别名]
def _render(self, team_key, event_key):
event_team = EventTeam.get_by_id('{}_{}'.format(event_key, team_key))
status = None
if event_team:
status = event_team.status
self._last_modified = event_team.updated
else:
self._last_modified = datetime.datetime.now()
if status:
status.update({
'alliance_status_str': EventTeamStatusHelper.generate_team_at_event_alliance_status_string(team_key, status),
'playoff_status_str': EventTeamStatusHelper.generate_team_at_event_playoff_status_string(team_key, status),
'overall_status_str': EventTeamStatusHelper.generate_team_at_event_status_string(team_key, status),
})
return json.dumps(status, ensure_ascii=True, indent=2, sort_keys=True)
示例6: _render
# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import get_by_id [as 别名]
def _render(self, team_number):
self.response.headers['content-type'] = 'text/plain; charset="utf-8"'
user = self.request.get('user')
if user:
user_str = '@{}, '.format(user)
else:
user_str = ''
team_event_or_error = validate_team(user_str, team_number)
if type(team_event_or_error) == str:
return team_event_or_error
_, event = team_event_or_error
event_code_upper = event.event_short.upper()
event_team = EventTeam.get_by_id('{}_frc{}'.format(event.key.id(), team_number))
team_key = 'frc{}'.format(team_number)
status = EventTeamStatusHelper.generate_team_at_event_status_string(team_key, event_team.status)
if status:
status = status.replace('<b>', '').replace('</b>', '')
return '{}[{}] {}'.format(user_str, event_code_upper, status)
示例7: _render
# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import get_by_id [as 别名]
def _render(self, district_abbrev, year=None, explicit_year=False):
district = DistrictQuery('{}{}'.format(year, district_abbrev)).fetch()
if not district:
self.abort(404)
events_future = DistrictEventsQuery(district.key_name).fetch_async()
# needed for district teams
district_teams_future = DistrictTeamsQuery(district.key_name).fetch_async()
# needed for valid_years
history_future = DistrictHistoryQuery(district.abbreviation).fetch_async()
# needed for valid_districts
districts_in_year_future = DistrictsInYearQuery(district.year).fetch_async()
# needed for active team statuses
live_events = []
if year == datetime.datetime.now().year: # Only show active teams for current year
live_events = EventHelper.getWeekEvents()
live_eventteams_futures = []
for event in live_events:
live_eventteams_futures.append(EventTeamsQuery(event.key_name).fetch_async())
events = events_future.get_result()
EventHelper.sort_events(events)
events_by_key = {}
for event in events:
events_by_key[event.key.id()] = event
week_events = EventHelper.groupByWeek(events)
valid_districts = set()
districts_in_year = districts_in_year_future.get_result()
for dist in districts_in_year:
valid_districts.add((dist.display_name, dist.abbreviation))
valid_districts = sorted(valid_districts, key=lambda (name, _): name)
teams = TeamHelper.sortTeams(district_teams_future.get_result())
team_keys = set([t.key.id() for t in teams])
num_teams = len(teams)
middle_value = num_teams / 2
if num_teams % 2 != 0:
middle_value += 1
teams_a, teams_b = teams[:middle_value], teams[middle_value:]
# Currently Competing Team Status
event_team_keys = []
for event, teams_future in zip(live_events, live_eventteams_futures):
for team in teams_future.get_result():
if team.key.id() in team_keys:
event_team_keys.append(ndb.Key(EventTeam, '{}_{}'.format(event.key.id(), team.key.id()))) # Should be in context cache
ndb.get_multi(event_team_keys) # Warms context cache
live_events_with_teams = []
for event, teams_future in zip(live_events, live_eventteams_futures):
teams_and_statuses = []
has_teams = False
for team in teams_future.get_result():
if team.key.id() in team_keys:
has_teams = True
event_team = EventTeam.get_by_id('{}_{}'.format(event.key.id(), team.key.id())) # Should be in context cache
status_str = {
'alliance': EventTeamStatusHelper.generate_team_at_event_alliance_status_string(team.key.id(), event_team.status),
'playoff': EventTeamStatusHelper.generate_team_at_event_playoff_status_string(team.key.id(), event_team.status),
}
teams_and_statuses.append((
team,
event_team.status,
status_str
))
if has_teams:
teams_and_statuses.sort(key=lambda x: x[0].team_number)
live_events_with_teams.append((event, teams_and_statuses))
live_events_with_teams.sort(key=lambda x: x[0].name)
live_events_with_teams.sort(key=lambda x: EventHelper.distantFutureIfNoStartDate(x[0]))
live_events_with_teams.sort(key=lambda x: EventHelper.distantFutureIfNoEndDate(x[0]))
# Get valid years
district_history = history_future.get_result()
valid_years = map(lambda d: d.year, district_history)
valid_years = sorted(valid_years)
self.template_values.update({
'explicit_year': explicit_year,
'year': year,
'valid_years': valid_years,
'valid_districts': valid_districts,
'district_name': district.display_name,
'district_abbrev': district_abbrev,
'week_events': week_events,
'events_by_key': events_by_key,
'rankings': district.rankings,
'advancement': district.advancement,
'teams_a': teams_a,
'teams_b': teams_b,
'live_events_with_teams': live_events_with_teams,
})
return jinja2_engine.render('district_details.html', self.template_values)
示例8: get
# 需要导入模块: from models.event_team import EventTeam [as 别名]
# 或者: from models.event_team.EventTeam import get_by_id [as 别名]
def get(self):
self._require_registration()
user = self.user_bundle.account.key
now = datetime.datetime.now()
year = self.request.get('year')
if year and year.isdigit():
year = int(year)
else:
year = now.year
team_favorites_future = Favorite.query(Favorite.model_type == ModelType.TEAM, ancestor=user).fetch_async()
favorite_team_keys = map(lambda f: ndb.Key(Team, f.model_key), team_favorites_future.get_result())
favorite_teams_future = ndb.get_multi_async(favorite_team_keys)
favorite_teams = [team_future.get_result() for team_future in favorite_teams_future]
favorite_teams_events_futures = []
favorite_teams_awards_futures = {}
for team in favorite_teams:
favorite_teams_events_futures.append(TeamYearEventsQuery(team.key_name, year).fetch_async())
favorite_teams_awards_futures[team.key.id()] = TeamYearAwardsQuery(team.key_name, year).fetch_async()
past_events_by_event = {}
live_events_by_event = {}
future_events_by_event = {}
favorite_event_team_keys = []
for team, events_future in zip(favorite_teams, favorite_teams_events_futures):
events = events_future.get_result()
if not events:
continue
EventHelper.sort_events(events) # Sort by date
for event in events:
favorite_event_team_keys.append(ndb.Key(EventTeam, '{}_{}'.format(event.key.id(), team.key.id())))
if event.within_a_day:
if event.key_name not in live_events_by_event:
live_events_by_event[event.key_name] = (event, [])
live_events_by_event[event.key_name][1].append(team)
elif event.start_date < now:
if event.key_name not in past_events_by_event:
past_events_by_event[event.key_name] = (event, [])
past_events_by_event[event.key_name][1].append(team)
else:
if event.key_name not in future_events_by_event:
future_events_by_event[event.key_name] = (event, [])
future_events_by_event[event.key_name][1].append(team)
event_team_awards = defaultdict(lambda: defaultdict(list))
for team_key, awards_future in favorite_teams_awards_futures.items():
for award in awards_future.get_result():
event_team_awards[award.event.id()][team_key].append(award)
ndb.get_multi(favorite_event_team_keys) # Warms context cache
past_events_with_teams = []
for event, teams in past_events_by_event.itervalues():
teams_and_statuses = []
for team in teams:
event_team = EventTeam.get_by_id('{}_{}'.format(event.key.id(), team.key.id())) # Should be in context cache
status_str = {
'alliance': EventTeamStatusHelper.generate_team_at_event_alliance_status_string(team.key.id(), event_team.status),
'playoff': EventTeamStatusHelper.generate_team_at_event_playoff_status_string(team.key.id(), event_team.status),
}
teams_and_statuses.append((
team,
event_team.status,
status_str,
AwardHelper.organizeAwards(event_team_awards[event.key.id()][team.key.id()])
))
teams_and_statuses.sort(key=lambda x: x[0].team_number)
past_events_with_teams.append((event, teams_and_statuses))
past_events_with_teams.sort(key=lambda x: x[0].name)
past_events_with_teams.sort(key=lambda x: EventHelper.distantFutureIfNoStartDate(x[0]))
past_events_with_teams.sort(key=lambda x: EventHelper.distantFutureIfNoEndDate(x[0]))
live_events_with_teams = []
for event, teams in live_events_by_event.itervalues():
teams_and_statuses = []
for team in teams:
event_team = EventTeam.get_by_id('{}_{}'.format(event.key.id(), team.key.id())) # Should be in context cache
status_str = {
'alliance': EventTeamStatusHelper.generate_team_at_event_alliance_status_string(team.key.id(), event_team.status),
'playoff': EventTeamStatusHelper.generate_team_at_event_playoff_status_string(team.key.id(), event_team.status),
}
teams_and_statuses.append((
team,
event_team.status,
status_str
))
teams_and_statuses.sort(key=lambda x: x[0].team_number)
live_events_with_teams.append((event, teams_and_statuses))
live_events_with_teams.sort(key=lambda x: x[0].name)
live_events_with_teams.sort(key=lambda x: EventHelper.distantFutureIfNoStartDate(x[0]))
live_events_with_teams.sort(key=lambda x: EventHelper.distantFutureIfNoEndDate(x[0]))
future_events_with_teams = []
for event, teams in future_events_by_event.itervalues():
teams.sort(key=lambda t: t.team_number)
#.........这里部分代码省略.........