本文整理汇总了Python中models.match.Match.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Match.get_by_id方法的具体用法?Python Match.get_by_id怎么用?Python Match.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.match.Match
的用法示例。
在下文中一共展示了Match.get_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testAcceptNewKey
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import get_by_id [as 别名]
def testAcceptNewKey(self):
self.loginUser()
self.givePermission()
suggestion_id = self.createSuggestion()
form = self.getSuggestionForm()
form.set('accept_keys[]', suggestion_id)
form.set('key-{}'.format(suggestion_id), '2016necmp_f1m2')
response = form.submit().follow()
self.assertEqual(response.status_int, 200)
# Make sure we mark the Suggestion as REVIEWED
suggestion = Suggestion.get_by_id(suggestion_id)
self.assertIsNotNone(suggestion)
self.assertEqual(suggestion.review_state, Suggestion.REVIEW_ACCEPTED)
# Make sure the video gets associated
match = Match.get_by_id(self.match2.key_name)
self.assertIsNotNone(match)
self.assertIsNotNone(match.youtube_videos)
self.assertTrue('H-54KMwMKY0' in match.youtube_videos)
# Make sure we don't add it to the first match
match = Match.get_by_id(self.match.key_name)
self.assertIsNotNone(match)
self.assertIsNotNone(match.youtube_videos)
self.assertFalse('H-54KMwMKY0' in match.youtube_videos)
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:28,代码来源:test_suggest_match_video_review_controller.py
示例2: test_createOrUpdate
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import get_by_id [as 别名]
def test_createOrUpdate(self):
MatchManipulator.createOrUpdate(self.old_match)
self.assertOldMatch(Match.get_by_id("2012ct_qm1"))
self.assertEqual(Match.get_by_id("2012ct_qm1").alliances_json, """{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""")
MatchManipulator.createOrUpdate(self.new_match)
self.assertMergedMatch(Match.get_by_id("2012ct_qm1"))
示例3: get
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import get_by_id [as 别名]
def get(self, match_key):
self._require_login()
self._require_registration()
match = Match.get_by_id(match_key)
if not match:
self.abort(404)
user = self.user_bundle.account.key
favorite = Favorite.query(Favorite.model_key==match_key, Favorite.model_type==ModelType.MATCH, ancestor=user).get()
subscription = Subscription.query(Favorite.model_key==match_key, Favorite.model_type==ModelType.MATCH, 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_match_notifications]
self.template_values['match'] = match
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_match.html', self.template_values))
示例4: post
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import get_by_id [as 别名]
def post(self, match_key):
self._require_login()
self._require_registration()
current_user_id = self.user_bundle.account.key.id()
match = Match.get_by_id(match_key)
if self.request.get('favorite'):
favorite = Favorite(
parent=ndb.Key(Account, current_user_id),
user_id=current_user_id,
model_type=ModelType.MATCH,
model_key=match_key
)
MyTBAHelper.add_favorite(favorite)
else:
MyTBAHelper.remove_favorite(current_user_id, match_key, ModelType.MATCH)
subs = self.request.get_all('notification_types')
if subs:
subscription = Subscription(
parent=ndb.Key(Account, current_user_id),
user_id=current_user_id,
model_type=ModelType.MATCH,
model_key=match_key,
notification_types=[int(s) for s in subs]
)
MyTBAHelper.add_subscription(subscription)
else:
MyTBAHelper.remove_subscription(current_user_id, match_key, ModelType.MATCH)
self.redirect('/account/mytba?status=match_updated#my-matches')
示例5: getMatchDetails
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import get_by_id [as 别名]
def getMatchDetails(cls, match_key):
"""
Returns match details
"""
memcache_key = "api_match_details_%s" % match_key
match_dict = memcache.get(memcache_key)
if match_dict is None:
match = Match.get_by_id(match_key)
if match is None:
return None
match_dict = {}
match_dict["key"] = match.key_name
match_dict["event"] = match.event.id()
match_dict["competition_level"] = match.name
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)
match_dict["videos"] = match.videos
match_dict["time_string"] = match.time_string
if match.time is not None:
match_dict["time"] = match.time.strftime("%s")
else:
match_dict["time"] = None
if tba_config.CONFIG["memcache"]:
memcache.set(memcache_key, match_dict, (2 * (60 * 60)))
return match_dict
示例6: createMatchVideoYouTubeSuggestion
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import get_by_id [as 别名]
def createMatchVideoYouTubeSuggestion(cls, author_account_key, youtube_id, match_key):
"""Create a YouTube Match Video. Returns status (success, suggestion_exists, video_exists, bad_url)"""
if youtube_id:
match = Match.get_by_id(match_key)
if not match:
return 'bad_match'
if youtube_id not in match.youtube_videos:
year = match_key[:4]
suggestion_id = Suggestion.render_media_key_name(year, 'match', match_key, 'youtube', youtube_id)
suggestion = Suggestion.get_by_id(suggestion_id)
if not suggestion or suggestion.review_state != Suggestion.REVIEW_PENDING:
suggestion = Suggestion(
id=suggestion_id,
author=author_account_key,
target_key=match_key,
target_model="match",
)
suggestion.contents = {"youtube_videos": [youtube_id]}
suggestion.put()
return 'success'
else:
return 'suggestion_exists'
else:
return 'video_exists'
else:
return 'bad_url'
示例7: get
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import get_by_id [as 别名]
def get(self, match_key):
match = Match.get_by_id(match_key)
template_values = {
"match": match
}
path = os.path.join(os.path.dirname(__file__), '../../templates/admin/match_details.html')
self.response.out.write(template.render(path, template_values))
示例8: get
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import get_by_id [as 别名]
def get(self, match_key):
self._require_admin()
match = Match.get_by_id(match_key)
self.template_values.update({
"match": match
})
path = os.path.join(os.path.dirname(__file__), '../../templates/admin/match_details.html')
self.response.out.write(template.render(path, self.template_values))
示例9: test_2017flwp
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import get_by_id [as 别名]
def test_2017flwp(self):
event = Event(
id='2017flwp',
event_short='flwp',
year=2017,
event_type_enum=0,
timezone_id='America/New_York'
)
event.put()
MatchManipulator.createOrUpdate(DatafeedFMSAPI('v2.0', sim_time=datetime.datetime(2017, 3, 04, 21, 22)).getMatches('2017flwp'))
MatchHelper.deleteInvalidMatches(event.matches, event)
sf_matches = Match.query(Match.event == ndb.Key(Event, '2017flwp'), Match.comp_level == 'sf').fetch()
self.assertEqual(len(sf_matches), 5)
old_match = Match.get_by_id('2017flwp_sf1m3')
self.assertNotEqual(old_match, None)
self.assertEqual(old_match.alliances['red']['score'], 255)
self.assertEqual(old_match.alliances['blue']['score'], 255)
self.assertEqual(old_match.score_breakdown['red']['totalPoints'], 255)
self.assertEqual(old_match.score_breakdown['blue']['totalPoints'], 255)
ndb.get_context().clear_cache() # Prevent data from leaking between tests
MatchManipulator.createOrUpdate(DatafeedFMSAPI('v2.0', sim_time=datetime.datetime(2017, 3, 04, 21, 35)).getMatches('2017flwp'))
MatchHelper.deleteInvalidMatches(event.matches, event)
sf_matches = Match.query(Match.event == ndb.Key(Event, '2017flwp'), Match.comp_level == 'sf').fetch()
self.assertEqual(len(sf_matches), 6)
new_match = Match.get_by_id('2017flwp_sf1m3')
self.assertNotEqual(new_match, None)
self.assertEqual(old_match.alliances, new_match.alliances)
self.assertEqual(old_match.score_breakdown, new_match.score_breakdown)
tiebreaker_match = Match.get_by_id('2017flwp_sf1m4')
self.assertNotEqual(tiebreaker_match, None)
self.assertEqual(tiebreaker_match.alliances['red']['score'], 165)
self.assertEqual(tiebreaker_match.alliances['blue']['score'], 263)
self.assertEqual(tiebreaker_match.score_breakdown['red']['totalPoints'], 165)
self.assertEqual(tiebreaker_match.score_breakdown['blue']['totalPoints'], 263)
示例10: get
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match 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')
示例11: test_match_videos_add
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import get_by_id [as 别名]
def test_match_videos_add(self):
self.video_auth.put()
match1 = Match(
id="2014casj_qm1",
alliances_json="""{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""",
comp_level="qm",
event=ndb.Key(Event, '2014casj'),
year=2014,
set_number=1,
match_number=1,
team_key_names=[u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'],
youtube_videos=["abcdef"]
)
match1.put()
match2 = Match(
id="2014casj_sf1m1",
alliances_json="""{"blue": {"score": -1, "teams": ["frc3464", "frc20", "frc1073"]}, "red": {"score": -1, "teams": ["frc69", "frc571", "frc176"]}}""",
comp_level="sf",
event=ndb.Key(Event, '2014casj'),
year=2014,
set_number=1,
match_number=1,
team_key_names=[u'frc69', u'frc571', u'frc176', u'frc3464', u'frc20', u'frc1073'],
)
match2.put()
match_videos = {'qm1': 'aFZy8iibMD0', 'sf1m1': 'RpSgUrsghv4'}
request_body = json.dumps(match_videos)
request_path = '/api/trusted/v1/event/2014casj/match_videos/add'
sig = md5.new('{}{}{}'.format('321tEsTsEcReT', request_path, request_body)).hexdigest()
response = self.testapp.post(request_path, request_body, headers={'X-TBA-Auth-Id': 'tEsT_id_5', 'X-TBA-Auth-Sig': sig}, expect_errors=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(set(Match.get_by_id('2014casj_qm1').youtube_videos), {'abcdef', 'aFZy8iibMD0'})
self.assertEqual(set(Match.get_by_id('2014casj_sf1m1').youtube_videos), {'RpSgUrsghv4'})
示例12: post
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import get_by_id [as 别名]
def post(self, match_key_id):
self._require_admin()
logging.warning("Deleting %s at the request of %s / %s" % (
match_key_id,
self.user_bundle.user.user_id(),
self.user_bundle.user.email()))
match = Match.get_by_id(match_key_id)
event_key_id = match.event.id()
MatchManipulator.delete(match)
self.redirect("/admin/event/%s?deleted=%s" % (event_key_id, match_key_id))
示例13: testRejectSuggestion
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import get_by_id [as 别名]
def testRejectSuggestion(self):
self.loginUser()
self.givePermission()
suggestion_id = self.createSuggestion()
form = self.getSuggestionForm()
form.set('reject_keys[]', suggestion_id)
response = form.submit().follow()
self.assertEqual(response.status_int, 200)
# Make sure we mark the Suggestion as REVIEWED
suggestion = Suggestion.get_by_id(suggestion_id)
self.assertIsNotNone(suggestion)
self.assertEqual(suggestion.review_state, Suggestion.REVIEW_REJECTED)
# Make sure the video gets associated
match = Match.get_by_id(self.match.key_name)
self.assertIsNotNone(match)
self.assertFalse(match.youtube_videos)
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:20,代码来源:test_suggest_match_video_review_controller.py
示例14: testAcceptBadKey
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import get_by_id [as 别名]
def testAcceptBadKey(self):
self.loginUser()
self.givePermission()
suggestion_id = self.createSuggestion()
form = self.getSuggestionForm()
form.set('accept_keys[]', suggestion_id)
form.set('key-{}'.format(suggestion_id), '2016necmp_f1m3') # This match doesn't exist
response = form.submit().follow()
self.assertEqual(response.status_int, 200)
# Make sure we don't mark the Suggestion as REVIEWED
suggestion = Suggestion.get_by_id(suggestion_id)
self.assertIsNotNone(suggestion)
self.assertEqual(suggestion.review_state, Suggestion.REVIEW_PENDING)
# Make sure the video doesn't get associated
match = Match.get_by_id(self.match.key_name)
self.assertIsNotNone(match)
self.assertIsNotNone(match.youtube_videos)
self.assertFalse('H-54KMwMKY0' in match.youtube_videos)
开发者ID:CarlColglazier,项目名称:the-blue-alliance,代码行数:22,代码来源:test_suggest_match_video_review_controller.py
示例15: _process_request
# 需要导入模块: from models.match import Match [as 别名]
# 或者: from models.match.Match import get_by_id [as 别名]
def _process_request(self, request, event_key):
try:
match_videos = json.loads(request.body)
except Exception:
self._errors = json.dumps({"Error": "Invalid JSON. Please check input."})
self.abort(400)
matches_to_put = []
for partial_match_key, youtube_id in match_videos.items():
match_key = '{}_{}'.format(event_key, partial_match_key)
match = Match.get_by_id(match_key)
if match is None:
self._errors = json.dumps({"Error": "Match {} does not exist!".format(match_key)})
self.abort(400)
if youtube_id not in match.youtube_videos:
match.youtube_videos.append(youtube_id)
match.dirty = True # This is hacky -fangeugene 2014-10-26
matches_to_put.append(match)
MatchManipulator.createOrUpdate(matches_to_put)