本文整理汇总了Python中models.Team.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python Team.get_by_key_name方法的具体用法?Python Team.get_by_key_name怎么用?Python Team.get_by_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Team
的用法示例。
在下文中一共展示了Team.get_by_key_name方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import get_by_key_name [as 别名]
def get(self, first_eid):
df = DatafeedUsfirstEvents()
event = df.getEvent(first_eid)
event = EventUpdater.createOrUpdate(event)
teams = df.getEventRegistration(first_eid)
eventteams_count = 0
for team_dict in teams:
# This could be refactored to do a lot fewer DB requests by batching the Team and EventTeam gets.
# -gregmarra 5 Dec 2010
team = Team.get_by_key_name("frc" + str(team_dict["number"]))
if team is None:
team = Team(
team_number = int(team_dict["number"]),
first_tpid = int(team_dict["tpid"]),
key_name = "frc" + str(team_dict["number"])
)
team.put()
et = EventTeam.get_or_insert(
key_name = event.key().name() + "_" + team.key().name(),
event = event,
team = team)
eventteams_count = eventteams_count + 1
template_values = {
'event': event,
'eventteams_count': eventteams_count,
}
path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/usfirst_event_get.html')
self.response.out.write(template.render(path, template_values))
示例2: getTeamInfo
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import get_by_key_name [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_key_name(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["event_keys"] = [a.event.key().name() for a in team.events]
team_dict["location"] = team.address
try:
team.do_split_address()
team_dict["location"] = team.split_address["full_address"]
team_dict["locality"] = team.split_address["locality"]
team_dict["region"] = team.split_address["region"]
team_dict["country"] = team.split_address["country"]
except Exception, e:
logging.error("Failed to include Address for api_team_info_%s" % team_key)
memcache.set(memcache_key, team_dict, 3600)
else:
return None
示例3: addTeamDetails
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import get_by_key_name [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_key_name(team_dict["key"])
for e in [a.event for a in team.events]:
match_list = e.match_set.filter("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.key().name()
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"] = simplejson.loads(match.alliances_json)
matches_list.append(match_dict)
memcache.set(memcache_key, matches_list, 600)
team_dict["matches"] = matches_list
return team_dict
示例4: get
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import get_by_key_name [as 别名]
def get(self, team_number):
team = Team.get_by_key_name("frc" + team_number)
template_values = {
'team' : team,
}
path = os.path.join(os.path.dirname(__file__), '../../templates/admin/teams/details.html')
self.response.out.write(template.render(path, template_values))
示例5: get
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import get_by_key_name [as 别名]
def get(self):
try:
q = self.request.get("q")
logging.info("search query: %s" % q)
if q.isdigit():
team_key_name = "frc%s" % q
team = Team.get_by_key_name(team_key_name)
if team:
self.redirect(team.details_url())
return None
except Exception, e:
logging.warning("warning: %s" % e)
示例6: scrapeTpid
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import get_by_key_name [as 别名]
def scrapeTpid(self, number, skip=0, year=2011):
"""
Searches the FIRST list of all teams for the requested team's tpid, caching
all it encounters in the datastore. This has the side effect of creating Team
objects along the way.
This code is taken directly from Pat Fairbank's frclinks source and modified
slightly to fit in the TBA framework. He has given us permission to borrow
his code directly.
"""
teams_to_put = list()
while 1:
logging.info("Fetching 250 teams based on %s data, skipping %s" % (year, skip))
# TODO: Make this robust to season changes. -gregmarra 9 Jan 2011
teamList = urlfetch.fetch(
'https://my.usfirst.org/myarea/index.lasso?page=searchresults&' +
'programs=FRC&reports=teams&sort_teams=number&results_size=250&' +
'omit_searchform=1&season_FRC=%s&skip_teams=%s' % (year, skip),
deadline=10)
teamResults = self.teamRe.findall(teamList.content)
tpid = None
for teamResult in teamResults:
teamNumber = self.teamNumberRe.findall(teamResult)[0]
teamTpid = self.tpidRe.findall(teamResult)[0]
if teamNumber == number:
tpid = teamTpid
logging.info("Team %s TPID was %s in year %s." % (teamNumber, teamTpid, year))
team = Team.get_by_key_name('frc' + str(teamNumber))
new_team = Team(
team_number = int(teamNumber),
first_tpid = int(teamTpid),
first_tpid_year = int(year),
key_name = "frc" + str(teamNumber)
)
if team is None:
teams_to_put.append(new_team)
else:
team = TeamUpdater.updateMerge(new_team, team)
teams_to_put.append(team)
skip = int(skip) + 250
db.put(teams_to_put)
teams_to_put = list()
if tpid:
return tpid
if len(self.lastPageRe.findall(teamList.content)) == 0:
return None
示例7: addTeamEvents
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import get_by_key_name [as 别名]
def addTeamEvents(self, team_dict, year):
"""
Consume a Team dict, and return it with a year's Events.
"""
memcache_key = "api_team_events_%s_%s" % (team_dict["key"], year)
event_list = memcache.get(memcache_key)
if event_list is None:
team = Team.get_by_key_name(team_dict["key"])
event_list = [self.getEventInfo(e.key().name()) for e in [a.event for a in team.events if a.year == int(year)]]
for event_dict in event_list:
event_dict["team_wlt"] = EventHelper.getTeamWLT(team_dict["key"], event_dict["key"])
memcache.set(memcache_key, event_list, 600)
team_dict["events"] = event_list
return team_dict
示例8: get
# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import get_by_key_name [as 别名]
def get(self, team_number, year=None):
if type(year) == str:
year = int(year)
explicit_year = True
else:
year = datetime.datetime.now().year
explicit_year = False
memcache_key = "team_detail_%s_%s" % ("frc" + team_number, year)
html = memcache.get(memcache_key)
if html is None:
team = Team.get_by_key_name("frc" + team_number)
#todo better 404 handling
if not team:
self.redirect("/")
events = [a.event for a in team.events if a.year == year]
for event in events:
if not event.start_date:
event.start_date = datetime.datetime(year, 12, 31) #unknown goes last
events = sorted(events, key=lambda event: event.start_date)
years = sorted(set([a.year for a in team.events if a.year != None]))
participation = list()
# Return an array of event names and a list of matches from that event that the
# team was a participant in.
year_wlt_list = list()
for e in events:
match_list = e.match_set.filter("team_key_names =", team.key().name())
matches = MatchHelper.organizeMatches(match_list)
wlt = EventHelper.getTeamWLTFromMatches(team.key().name(), match_list)
year_wlt_list.append(wlt)
if wlt["win"] + wlt["loss"] + wlt["tie"] == 0:
display_wlt = None
else:
display_wlt = wlt
participation.append({ 'event' : e,
'matches' : matches,
'wlt': display_wlt })
team.do_split_address()
year_wlt = {"win": 0, "loss": 0, "tie": 0}
for wlt in year_wlt_list:
year_wlt["win"] += wlt["win"]
year_wlt["loss"] += wlt["loss"]
year_wlt["tie"] += wlt["tie"]
if year_wlt["win"] + year_wlt["loss"] + year_wlt["tie"] == 0:
year_wlt = None
template_values = { "explicit_year": explicit_year,
"team": team,
"participation": participation,
"year": year,
"years": years,
"year_wlt": year_wlt }
path = os.path.join(os.path.dirname(__file__), '../templates/teams/details.html')
html = template.render(path, template_values)
memcache.set(memcache_key, html, 300)
self.response.out.write(html)