本文整理汇总了Python中models.event.Event.validate_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python Event.validate_key_name方法的具体用法?Python Event.validate_key_name怎么用?Python Event.validate_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.event.Event
的用法示例。
在下文中一共展示了Event.validate_key_name方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import validate_key_name [as 别名]
def main(key, url):
print "Configuring GAE Remote API on {} to import {}".format(url, key)
if 'localhost' in url:
remote_api_stub.ConfigureRemoteApi(None, '/_ah/remote_api', local_auth_func, url)
else:
remote_api_stub.ConfigureRemoteApiForOAuth(url, '/_ah/remote_api')
print "Loading data from The Blue Alliance requires an API key"
print "Please go to https://thebluealliance.com/account and generate a read API key"
apiv3_key = raw_input("Enter your API key: ")
global AUTH_TOKEN
AUTH_TOKEN = apiv3_key
if Match.validate_key_name(key):
match_data = fetch_match(key)
store_match(match_data)
elif Event.validate_key_name(key):
update_event(key)
elif Team.validate_key_name(key):
team_data = fetch_team(key)
store_team(team_data)
elif key.isdigit():
event_keys = [event['key'] for event in fetch_endpoint('events/{}'.format(key))]
for event in event_keys:
update_event(event)
else:
print "Unknown key :("
示例2: create_target_model
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import validate_key_name [as 别名]
def create_target_model(self, suggestion):
event_id = self.request.get("event_short", None)
event_key = str(self.request.get("year")) + str.lower(str(self.request.get("event_short")))
if not event_id:
# Need to supply a key :(
return 'missing_key', None
if not Event.validate_key_name(event_key):
# Bad event key generated
return 'bad_key', None
start_date = None
if self.request.get("start_date"):
start_date = datetime.strptime(self.request.get("start_date"), "%Y-%m-%d")
end_date = None
if self.request.get("end_date"):
end_date = datetime.strptime(self.request.get("end_date"), "%Y-%m-%d")
existing_event = Event.get_by_id(event_key)
if existing_event:
return 'duplicate_key', None
first_code = self.request.get("first_code", '')
event = Event(
id=event_key,
end_date=end_date,
event_short=self.request.get("event_short"),
event_type_enum=EventType.OFFSEASON,
district_key=None,
venue=self.request.get("venue"),
venue_address=self.request.get("venue_address"),
city=self.request.get("city"),
state_prov=self.request.get("state"),
country=self.request.get("country"),
name=self.request.get("name"),
short_name=self.request.get("short_name"),
start_date=start_date,
website=self.request.get("website"),
year=int(self.request.get("year")),
first_code=first_code,
official=(not first_code == ''),
)
EventManipulator.createOrUpdate(event)
author = suggestion.author.get()
OutgoingNotificationHelper.send_suggestion_result_email(
to=author.email,
subject="[TBA] Offseason Event Suggestion: {}".format(event.name),
email_body="""Dear {},
Thank you for suggesting an offseason event to The Blue Alliance. Your suggestion has been approved and you can find the event at https://thebluealliance.com/event/{}
If you are the event's organizer and would like to upload teams attending, match videos, or real-time match results to TBA before or during the event, you can do so using the TBA EventWizard - request auth keys here: https://www.thebluealliance.com/request/apiwrite
Thanks for helping make TBA better,
The Blue Alliance Admins
""".format(author.nickname, event_key)
)
return 'success', event_key
开发者ID:NikhilNarayana,项目名称:the-blue-alliance,代码行数:62,代码来源:suggest_offseason_event_review_controller.py
示例3: _render
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import validate_key_name [as 别名]
def _render(self, *args, **kw):
path = os.path.join(os.path.dirname(__file__), "../templates/eventwizard.html")
selected_event_key = self.request.get('event', '')
if selected_event_key and Event.validate_key_name(selected_event_key):
selected_event = Event.get_by_id(selected_event_key)
if selected_event:
self.template_values['selected_event'] = selected_event
return template.render(path, self.template_values)
示例4: createTeamMediaSuggestion
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import validate_key_name [as 别名]
def createTeamMediaSuggestion(cls, author_account_key, media_url, team_key, year_str, private_details_json=None, is_social=False, default_preferred=False):
"""Create a Team Media Suggestion. Returns status (success, suggestion_exists, media_exists, bad_url)"""
media_dict = MediaParser.partial_media_dict_from_url(media_url)
if media_dict is not None:
if media_dict.get("is_social", False) != is_social:
return 'bad_url', None
existing_media = Media.get_by_id(Media.render_key_name(media_dict['media_type_enum'], media_dict['foreign_key']))
if existing_media is None or team_key not in [reference.id() for reference in existing_media.references]:
foreign_type = Media.SLUG_NAMES[media_dict['media_type_enum']]
suggestion_id = Suggestion.render_media_key_name(year_str, 'team', team_key, foreign_type, media_dict['foreign_key'])
suggestion = Suggestion.get_by_id(suggestion_id)
if not suggestion or suggestion.review_state != Suggestion.REVIEW_PENDING:
media_dict['year'] = int(year_str) if year_str else None
media_dict['reference_type'] = 'team'
media_dict['reference_key'] = team_key
media_dict['default_preferred'] = default_preferred
if private_details_json is not None:
media_dict['private_details_json'] = private_details_json
target_model = "media"
if media_dict.get("is_social", False):
target_model = "social-media"
if media_dict.get('media_type', '') in MediaType.robot_types:
target_model = "robot"
if Event.validate_key_name(team_key):
target_model = 'event_media'
media_dict['reference_type'] = 'event'
suggestion = Suggestion(
id=suggestion_id,
author=author_account_key,
target_model=target_model,
target_key=team_key,
)
suggestion.contents = media_dict
suggestion.put()
return 'success', suggestion
else:
return 'suggestion_exists', None
else:
return 'media_exists', None
else:
return 'bad_url', None
示例5: main
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import validate_key_name [as 别名]
def main(key, url):
print "Configuring GAE Remote API on {} to import {}".format(url, key)
if 'localhost' in url:
remote_api_stub.ConfigureRemoteApi(None, '/_ah/remote_api', local_auth_func, url)
else:
remote_api_stub.ConfigureRemoteApiForOAuth(url, '/_ah/remote_api')
print "Loading data from The Blue Alliance requires an API key"
print "Please go to https://thebluealliance.com/account and generate a read API key"
apiv3_key = raw_input("Enter your API key: ")
global AUTH_TOKEN
AUTH_TOKEN = apiv3_key
if Match.validate_key_name(key):
match_data = fetch_match(key)
store_match(match_data)
elif Event.validate_key_name(key):
event_data = fetch_event(key)
event = store_event(event_data)
event_teams = fetch_event_detail(key, 'teams')
teams = map(store_team, event_teams)
map(lambda t: store_eventteam(t, event), teams)
event_matches = fetch_event_detail(key, 'matches')
map(store_match, event_matches)
event_rankings = fetch_event_detail(key, 'rankings')
store_eventdetail(event, 'rankings2', event_rankings['rankings'] if event_rankings else [])
event_alliances = fetch_event_detail(key, 'alliances')
store_eventdetail(event, 'alliance_selections', event_alliances)
event_awards = fetch_event_detail(key, 'awards')
map(lambda t: store_award(t, event), event_awards)
elif Team.validate_key_name(key):
team_data = fetch_team(key)
store_team(team_data)
else:
print "Unknown key :("
示例6: post
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import validate_key_name [as 别名]
def post(self):
self.verify_permissions()
suggestion = Suggestion.get_by_id(int(self.request.get("suggestion_id")))
verdict = self.request.get("verdict")
if verdict == "accept":
event_id = self.request.get("event_short", None)
event_key = str(self.request.get("year")) + str.lower(str(self.request.get("event_short")))
if not event_id:
# Need to supply a key :(
self.redirect("/suggest/offseason/review?success=missing_key")
return
if not Event.validate_key_name(event_key):
# Bad event key generated
self.redirect("/suggest/offseason/review?success=bad_key")
return
start_date = None
if self.request.get("start_date"):
start_date = datetime.strptime(self.request.get("start_date"), "%Y-%m-%d")
end_date = None
if self.request.get("end_date"):
end_date = datetime.strptime(self.request.get("end_date"), "%Y-%m-%d")
event = Event(
id=event_key,
end_date=end_date,
event_short=self.request.get("event_short"),
event_type_enum=EventType.OFFSEASON,
event_district_enum=DistrictType.NO_DISTRICT,
venue=self.request.get("venue"),
venue_address=self.request.get("venue_address"),
city=self.request.get("city"),
state_prov=self.request.get("state"),
country=self.request.get("country"),
name=self.request.get("name"),
short_name=self.request.get("short_name"),
start_date=start_date,
website=self.request.get("website"),
year=int(self.request.get("year")),
official=False,
)
EventManipulator.createOrUpdate(event)
suggestion.review_state = Suggestion.REVIEW_ACCEPTED
suggestion.reviewer = self.user_bundle.account.key
suggestion.reviewed_at = datetime.now()
suggestion.put()
self.redirect("/suggest/offseason/review?success=accept&event_key=%s" % event.key.id())
return
elif verdict == "reject":
suggestion.review_state = Suggestion.REVIEW_REJECTED
suggestion.reviewer = self.user_bundle.account.key
suggestion.reviewed_at = datetime.now()
suggestion.put()
self.redirect("/suggest/offseason/review?success=reject")
return
self.redirect("/suggest/offseason/review")
示例7: test_invalid_event_key
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import validate_key_name [as 别名]
def test_invalid_event_key(self):
self.assertEqual(Event.validate_key_name(self.invalid_event_key), False)
self.assertEqual(Event.validate_key_name(self.invalid_event_key2), False)
self.assertEqual(Event.validate_key_name(self.invalid_event_key3), False)
示例8: test_valid_event_key
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import validate_key_name [as 别名]
def test_valid_event_key(self):
self.assertEqual(Event.validate_key_name(self.valid_event_key), True)
示例9: is_valid_model_key
# 需要导入模块: from models.event import Event [as 别名]
# 或者: from models.event.Event import validate_key_name [as 别名]
def is_valid_model_key(cls, key):
return (Team.validate_key_name(key) or
Event.validate_key_name(key) or
Match.validate_key_name(key) or
District.validate_key_name(key))