本文整理汇总了Python中models.district.District.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python District.get_by_id方法的具体用法?Python District.get_by_id怎么用?Python District.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.district.District
的用法示例。
在下文中一共展示了District.get_by_id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: postUpdateHook
# 需要导入模块: from models.district import District [as 别名]
# 或者: from models.district.District import get_by_id [as 别名]
def postUpdateHook(cls, districts, updated_attr_list, is_new_list):
"""
To run after a district has been updated.
For new districts, tries to guess the names based on other year's data
"""
for (district, is_new, updated_attrs) in zip(districts, is_new_list, updated_attr_list):
if is_new and (not district.display_name or not district.elasticsearch_name):
last_year_key = District.renderKeyName(district.year - 1, district.abbreviation)
last_year_district = District.get_by_id(last_year_key)
update = False
if last_year_district:
if not district.display_name:
district.display_name = last_year_district.display_name
update = True
if not district.elasticsearch_name:
district.elasticsearch_name = last_year_district.elasticsearch_name
update = True
if update:
cls.createOrUpdate(district, run_post_update_hook=False)
if 'display_name' in updated_attrs or 'elasticsearch_name' in updated_attrs:
# Set all other instances of this district to have the values
all_past_years = DistrictHistoryQuery(district.abbreviation).fetch()
to_put = []
for other_district in all_past_years:
if other_district.year != district.year:
other_district.display_name = district.display_name
other_district.elasticsearch_name = district.elasticsearch_name
to_put.append(other_district)
cls.createOrUpdate(to_put, run_post_update_hook=False)
示例2: get
# 需要导入模块: from models.district import District [as 别名]
# 或者: from models.district.District import get_by_id [as 别名]
def get(self, type):
self._require_registration('/account/')
user_id = self.user_bundle.account.key.id()
logging.info("Sending for {}".format(type))
try:
type = int(type)
except ValueError:
# Not passed a valid int, just stop here
logging.info("Invalid number passed")
self.redirect('/apidocs/webhooks')
return
event = Event.get_by_id('2014necmp')
match = Match.get_by_id('2014necmp_f1m1')
district = District.get_by_id('2014ne')
if type == NotificationType.UPCOMING_MATCH:
notification = UpcomingMatchNotification(match, event)
elif type == NotificationType.MATCH_SCORE:
notification = MatchScoreNotification(match)
elif type == NotificationType.LEVEL_STARTING:
notification = CompLevelStartingNotification(match, event)
elif type == NotificationType.ALLIANCE_SELECTION:
notification = AllianceSelectionNotification(event)
elif type == NotificationType.AWARDS:
notification = AwardsUpdatedNotification(event)
elif type == NotificationType.MEDIA_POSTED:
# Not implemented yet
pass
elif type == NotificationType.DISTRICT_POINTS_UPDATED:
notification = DistrictPointsUpdatedNotification(district)
elif type == NotificationType.SCHEDULE_UPDATED:
notification = ScheduleUpdatedNotification(event, match)
elif type == NotificationType.FINAL_RESULTS:
# Not implemented yet
pass
elif type == NotificationType.MATCH_VIDEO:
notification = MatchVideoNotification(match)
elif type == NotificationType.EVENT_MATCH_VIDEO:
notification = EventMatchVideoNotification(match)
else:
# Not passed a valid int, return
self.redirect('/apidocs/webhooks')
return
keys = PushHelper.get_client_ids_for_users([user_id])
logging.info("Keys: {}".format(keys))
if notification:
# This page should not push notifications to the firebase queue
# Nor should its notifications be tracked in analytics
notification.send(keys, push_firebase=False, track_call=False)
self.redirect('/apidocs/webhooks')
示例3: getDistrictRankings
# 需要导入模块: from models.district import District [as 别名]
# 或者: from models.district.District import get_by_id [as 别名]
def getDistrictRankings(self, district_key):
district = District.get_by_id(district_key)
if not district:
return None
year = int(district_key[:4])
district_short = district_key[4:]
advancement = {}
for page in range(1, 15): # Ensure this won't loop forever
url = self.FMS_API_DISTRICT_RANKINGS_PATTERN % (year, district_short.upper(), page)
result = self._parse(url, FMSAPIDistrictRankingsParser(advancement))
if not result:
break
advancement, more_pages = result
if not more_pages:
break
district.advancement = advancement
return [district]
示例4: get
# 需要导入模块: from models.district import District [as 别名]
# 或者: from models.district.District import get_by_id [as 别名]
def get(self, district_key):
district = District.get_by_id(district_key)
if not district:
self.response.out.write("District {} does not exist!".format(district_key))
return
events_future = DistrictEventsQuery(district_key).fetch_async()
teams_future = DistrictTeamsQuery(district_key).fetch_async()
events = events_future.get_result()
for event in events:
event.prep_details()
EventHelper.sort_events(events)
team_totals = DistrictHelper.calculate_rankings(events, teams_future, district.year)
rankings = []
current_rank = 1
for key, points in team_totals:
point_detail = {}
point_detail["rank"] = current_rank
point_detail["team_key"] = key
point_detail["event_points"] = []
for event, event_points in points["event_points"]:
event_points['event_key'] = event.key.id()
event_points['district_cmp'] = (
event.event_type_enum == EventType.DISTRICT_CMP or
event.event_type_enum == EventType.DISTRICT_CMP_DIVISION)
point_detail["event_points"].append(event_points)
point_detail["rookie_bonus"] = points.get("rookie_bonus", 0)
point_detail["point_total"] = points["point_total"]
rankings.append(point_detail)
current_rank += 1
if rankings:
district.rankings = rankings
DistrictManipulator.createOrUpdate(district)
if 'X-Appengine-Taskname' not in self.request.headers: # Only write out if not in taskqueue
self.response.out.write("Finished calculating rankings for: {}".format(district_key))
示例5: post
# 需要导入模块: from models.district import District [as 别名]
# 或者: from models.district.District import get_by_id [as 别名]
def post(self, type):
self._require_registration('/account/')
event_key = self.request.get('event_key')
match_key = self.request.get('match_key')
district_key = self.request.get('district_key')
user_id = self.user_bundle.account.key.id()
logging.info("Sending for {}".format(type))
try:
type = int(type)
except ValueError:
# Not passed a valid int, just stop here
logging.info("Invalid number passed")
return
event = None
if type != NotificationType.DISTRICT_POINTS_UPDATED:
if event_key == "":
logging.info("No event key")
self.response.out.write("No event key specified!")
return
event = Event.get_by_id(event_key)
if event is None:
logging.info("Invalid event key passed")
self.response.out.write("Invalid event key!")
return
if type == NotificationType.UPCOMING_MATCH:
if match_key == "":
logging.info("No match key")
self.response.out.write("No match key specified!")
return
match = Match.get_by_id(match_key)
if match is None:
logging.info("Invalid match key passed")
self.response.out.write("Invalid match key!")
return
notification = UpcomingMatchNotification(match, event)
elif type == NotificationType.MATCH_SCORE:
if match_key == "":
logging.info("No match key")
self.response.out.write("No match key specified!")
return
match = Match.get_by_id(match_key)
if match is None:
logging.info("Invalid match key passed")
self.response.out.write("Invalid match key!")
return
notification = MatchScoreNotification(match)
elif type == NotificationType.LEVEL_STARTING:
if match_key == "":
logging.info("No match key")
self.response.out.write("No match key specified!")
return
match = Match.get_by_id(match_key)
if match is None:
logging.info("Invalid match key passed")
self.response.out.write("Invalid match key!")
return
notification = CompLevelStartingNotification(match, event)
elif type == NotificationType.ALLIANCE_SELECTION:
notification = AllianceSelectionNotification(event)
elif type == NotificationType.AWARDS:
notification = AwardsUpdatedNotification(event)
elif type == NotificationType.MEDIA_POSTED:
# Not implemented yet
pass
elif type == NotificationType.DISTRICT_POINTS_UPDATED:
if district_key == "":
logging.info("No district key")
self.response.out.write("No district key specified!")
return
district = District.get_by_id(district_key)
if district is None:
logging.info("Invalid district key passed")
self.response.out.write("Invalid district key!")
return
notification = DistrictPointsUpdatedNotification(district)
elif type == NotificationType.SCHEDULE_UPDATED:
if match_key == "":
logging.info("No match key")
self.response.out.write("No match key specified!")
return
match = Match.get_by_id(match_key)
#.........这里部分代码省略.........