本文整理汇总了Python中models.suggestion.Suggestion.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Suggestion.get_by_id方法的具体用法?Python Suggestion.get_by_id怎么用?Python Suggestion.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.suggestion.Suggestion
的用法示例。
在下文中一共展示了Suggestion.get_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id [as 别名]
def post(self):
self._require_admin()
if self.request.get("verdict") == "accept":
webcast = dict()
webcast["type"] = self.request.get("webcast_type")
webcast["channel"] = self.request.get("webcast_channel")
if self.request.get("webcast_file"):
webcast["file"] = self.request.get("webcast_file")
event = Event.get_by_id(self.request.get("event_key"))
suggestion = Suggestion.get_by_id(int(self.request.get("suggestion_key")))
EventWebcastAdder.add_webcast(event, webcast)
MemcacheWebcastFlusher.flush()
suggestion.review_state = Suggestion.REVIEW_ACCEPTED
suggestion.reviewer = self.user_bundle.account.key
suggestion.reviewer_at = datetime.datetime.now()
suggestion.put()
self.redirect("/admin/suggestions/event/webcast/review?success=accept&event_key=%s" % event.key.id())
return
elif self.request.get("verdict") == "reject":
suggestion = Suggestion.get_by_id(int(self.request.get("suggestion_key")))
suggestion.review_state = Suggestion.REVIEW_REJECTED
suggestion.reviewer = self.user_bundle.account.key
suggestion.reviewer_at = datetime.datetime.now()
suggestion.put()
self.redirect("/admin/suggestions/event/webcast/review?success=reject")
return
elif self.request.get("verdict") == "reject_all":
suggestion_keys = self.request.get("suggestion_keys").split(",")
suggestions = [Suggestion.get_by_id(int(suggestion_key)) for suggestion_key in suggestion_keys]
for suggestion in suggestions:
event_key = suggestion.target_key
suggestion.review_state = Suggestion.REVIEW_REJECTED
suggestion.reviewer = self.user_bundle.account.key
suggestion.reviewer_at = datetime.datetime.now()
suggestion.put()
self.redirect("/admin/suggestions/event/webcast/review?success=reject_all&event_key=%s" % event_key)
return
self.redirect("/admin/suggestions/event/webcast/review")
开发者ID:BowlesCR,项目名称:the-blue-alliance,代码行数:54,代码来源:admin_event_webcast_suggestions_review_controller.py
示例2: test_accept_with_different_details
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id [as 别名]
def test_accept_with_different_details(self):
self.loginUser()
self.givePermission()
suggestion_id = self.createSuggestion()
form = self.getSuggestionForm('review_{}'.format(suggestion_id))
form['webcast_type'] = 'youtube'
form['webcast_channel'] = 'foobar'
form['webcast_file'] = 'meow'
response = form.submit('verdict', value='accept').follow()
self.assertEqual(response.status_int, 200)
request = response.request
self.assertEqual(request.GET.get('success'), 'accept')
# Process task queue
tasks = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME).get_filtered_tasks()
for task in tasks:
deferred.run(task.payload)
# 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 Event has no webcasts
event = Event.get_by_id('2016necmp')
self.assertIsNotNone(event.webcast)
self.assertEqual(len(event.webcast), 1)
webcast = event.webcast[0]
self.assertEqual(webcast['type'], 'youtube')
self.assertEqual(webcast['channel'], 'foobar')
self.assertEqual(webcast['file'], 'meow')
示例3: createEventMediaSuggestion
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id [as 别名]
def createEventMediaSuggestion(cls, author_account_key, media_url, event_key, private_details_json=None):
"""Create an Event 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['media_type_enum'] != MediaType.YOUTUBE_VIDEO:
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 event_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(event_key[:4], 'event', event_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'] = event_key[:4]
media_dict['reference_type'] = 'event'
media_dict['reference_key'] = event_key
target_model = 'event_media'
if private_details_json is not None:
media_dict['private_details_json'] = private_details_json
suggestion = Suggestion(
id=suggestion_id,
author=author_account_key,
target_model=target_model,
)
suggestion.contents = media_dict
suggestion.put()
return 'success', suggestion
else:
return 'suggestion_exists', None
else:
return 'media_exists', None
else:
return 'bad_url', None
示例4: createTeamMediaSuggestion
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id [as 别名]
def createTeamMediaSuggestion(cls, author_account_key, media_url, team_key, year_str):
"""Create a Team Media Suggestion. Returns status (success, exists, bad_url)"""
media_dict = MediaParser.partial_media_dict_from_url(media_url)
if media_dict is not 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_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)
media_dict['reference_type'] = 'team'
media_dict['reference_key'] = team_key
suggestion = Suggestion(
id=suggestion_id,
author=author_account_key,
target_model="media",
)
suggestion.contents = media_dict
suggestion.put()
return 'success'
else:
return 'suggestion_exists'
else:
return 'media_exists'
else:
return 'bad_url'
示例5: post
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id [as 别名]
def post(self):
self.verify_permissions()
suggestion_id = int(self.request.get("suggestion_id"))
verdict = self.request.get("verdict")
message = self.request.get("user_message")
admin_email_body = None
email_body = None
user = None
event_key = None
status = ''
if verdict == "accept":
status = 'accept'
auth_id, user, event_key, email_body = self._process_accepted(suggestion_id, message)
admin_email_body = """{} ({}) has accepted the request with the following message:
{}
View the key: https://www.thebluealliance.com/admin/api_auth/edit/{}
""".format(self.user_bundle.account.display_name, self.user_bundle.account.email, message, auth_id)
elif verdict == "reject":
suggestion = Suggestion.get_by_id(suggestion_id)
event_key = suggestion.contents['event_key']
user = suggestion.author.get()
event = Event.get_by_id(event_key)
suggestion.review_state = Suggestion.REVIEW_REJECTED
suggestion.reviewer = self.user_bundle.account.key
suggestion.reviewed_at = datetime.now()
suggestion.put()
status = 'reject'
email_body = """Hi {},
We have reviewer your request for auth tokens for {} {} and have regretfully declined with the following message:
{}
If you have any questions, please don't hesitate to reach out to us at [email protected]
Thanks,
TBA Admins
""".format(user.display_name, event.year, event.name, message)
admin_email_body = """{} ({}) has rejected this request with the following reason:
{}
""".format(self.user_bundle.account.display_name, self.user_bundle.account.email, message)
# Notify the user their keys are available
if email_body:
mail.send_mail(sender="The Blue Alliance Contact <[email protected]>",
to=user.email,
subject="The Blue Alliance Auth Tokens for {}".format(event_key),
body=email_body)
if admin_email_body:
# Subject should match the one in suggest_apiwrite_controller
subject = "Trusted API Key Request for {}".format(event_key)
SuggestionNotifier.send_admin_alert_email(subject, admin_email_body)
self.redirect("/suggest/apiwrite/review?success={}".format(status))
示例6: testAcceptNewKey
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion 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
示例7: createMatchVideoYouTubeSuggestion
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion 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'
示例8: test_suggest_media
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id [as 别名]
def test_suggest_media(self):
self.loginUser()
self.storeTeam()
form = self.getSuggestionForm('frc1124', 2016)
form['media_url'] = 'http://imgur.com/aF8T5ZE'
response = form.submit().follow()
self.assertEqual(response.status_int, 200)
request = response.request
self.assertEqual(request.GET.get('status'), 'success')
suggestion = Suggestion.get_by_id('media_2016_team_frc1124_imgur_aF8T5ZE')
self.assertIsNotNone(suggestion)
示例9: test_suggest_team
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id [as 别名]
def test_suggest_team(self):
self.loginUser()
self.storeTeam()
form = self.getSuggestionForm('frc1124')
form['media_url'] = 'https://github.com/frc1124'
response = form.submit().follow()
self.assertEqual(response.status_int, 200)
request = response.request
self.assertEqual(request.GET.get('status'), 'success')
suggestion = Suggestion.get_by_id('media_None_team_frc1124_github-profile_frc1124')
self.assertIsNotNone(suggestion)
示例10: testSuggestMedia
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id [as 别名]
def testSuggestMedia(self):
self.loginUser()
self.storeEvent()
form = self.getSuggestionForm('2016nyny')
form['media_url'] = 'https://www.youtube.com/watch?v=H-54KMwMKY0'
response = form.submit().follow()
self.assertEqual(response.status_int, 200)
request = response.request
self.assertEqual(request.GET.get('status'), 'success')
suggestion = Suggestion.get_by_id('media_2016_event_2016nyny_youtube_H-54KMwMKY0')
self.assertIsNotNone(suggestion)
示例11: test_create_suggestion
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id [as 别名]
def test_create_suggestion(self):
status = SuggestionCreator.createMatchVideoYouTubeSuggestion(self.account.key, "37F5tbrFqJQ", "2016test_f1m1")
self.assertEqual(status, 'success')
suggestion_id = "media_2016_match_2016test_f1m1_youtube_37F5tbrFqJQ"
suggestion = Suggestion.get_by_id(suggestion_id)
self.assertIsNotNone(suggestion)
self.assertEqual(suggestion.author, self.account.key)
self.assertEqual(suggestion.target_key, '2016test_f1m1')
self.assertEqual(suggestion.target_model, 'match')
self.assertIsNotNone(suggestion.contents)
self.assertIsNotNone(suggestion.contents.get('youtube_videos'))
self.assertEqual(len(suggestion.contents.get('youtube_videos')), 1)
self.assertEqual(suggestion.contents.get('youtube_videos')[0], "37F5tbrFqJQ")
示例12: testCleanUrl
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id [as 别名]
def testCleanUrl(self):
status = SuggestionCreator.createTeamMediaSuggestion(
self.account.key,
" http://imgur.com/ruRAxDm?foo=bar#meow ",
"frc1124",
"2016")
self.assertEqual(status, 'success')
# Ensure the Suggestion gets created
suggestion_id = Suggestion.render_media_key_name('2016', 'team', 'frc1124', 'imgur', 'ruRAxDm')
suggestion = Suggestion.get_by_id(suggestion_id)
self.assertIsNotNone(suggestion)
self.assertEqual(suggestion.review_state, Suggestion.REVIEW_PENDING)
self.assertEqual(suggestion.author, self.account.key)
self.assertEqual(suggestion.target_model, 'media')
示例13: test_reject_suggestion
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id [as 别名]
def test_reject_suggestion(self):
self.loginUser()
self.givePermission()
suggestion_id = self.createSuggestion()
form = self.getSuggestionForm()
form['accept_reject-{}'.format(suggestion_id)] = 'reject::{}'.format(suggestion_id)
response = form.submit().follow()
self.assertEqual(response.status_int, 200)
suggestion = Suggestion.get_by_id(suggestion_id)
self.assertIsNotNone(suggestion)
self.assertEqual(suggestion.review_state, Suggestion.REVIEW_REJECTED)
medias = Media.query().fetch()
self.assertEqual(len(medias), 0)
示例14: testRejectSuggestion
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id [as 别名]
def testRejectSuggestion(self):
self.loginUser()
self.givePermission()
suggestion_id = self.createSuggestion()
form = self.getSuggestionForm(suggestion_id)
response = form.submit('verdict', value='reject').follow()
self.assertEqual(response.status_int, 200)
auths = ApiAuthAccess.query().fetch()
self.assertEqual(len(auths), 0)
# Make sure we mark the Suggestion as REJECTED
suggestion = Suggestion.get_by_id(suggestion_id)
self.assertIsNotNone(suggestion)
self.assertEqual(suggestion.review_state, Suggestion.REVIEW_REJECTED)
示例15: test_submit_one_video
# 需要导入模块: from models.suggestion import Suggestion [as 别名]
# 或者: from models.suggestion.Suggestion import get_by_id [as 别名]
def test_submit_one_video(self):
self.loginUser()
response = self.testapp.post('/suggest/event/video?event_key=2016necmp', {
'num_videos': 1,
'video_id_0': '37F5tbrFqJQ',
'match_partial_0': 'f1m1'
}).follow()
self.assertEqual(response.status_int, 200)
request = response.request
self.assertEqual(request.GET.get('num_added'), '1')
suggestion_id = "media_2016_match_2016necmp_f1m1_youtube_37F5tbrFqJQ"
suggestion = Suggestion.get_by_id(suggestion_id)
self.assertIsNotNone(suggestion)