本文整理汇总了Python中models.media.Media.create_reference方法的典型用法代码示例。如果您正苦于以下问题:Python Media.create_reference方法的具体用法?Python Media.create_reference怎么用?Python Media.create_reference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.media.Media
的用法示例。
在下文中一共展示了Media.create_reference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_target_model
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def create_target_model(self, suggestion):
# Setup
to_replace = None
to_replace_id = self.request.POST.get('replace-preferred-{}'.format(suggestion.key.id()), None)
year = int(self.request.POST.get('year-{}'.format(suggestion.key.id())))
# Override year if necessary
suggestion.contents['year'] = year
suggestion.contents_json = json.dumps(suggestion.contents)
suggestion._contents = None
# Remove preferred reference from another Media if specified
team_reference = Media.create_reference(
suggestion.contents['reference_type'],
suggestion.contents['reference_key'])
if to_replace_id:
to_replace = Media.get_by_id(to_replace_id)
if team_reference not in to_replace.preferred_references:
# Preferred reference must have been edited earlier. Skip this Suggestion for now.
return
to_replace.preferred_references.remove(team_reference)
# Add preferred reference to current Media (images only) if explicitly listed in preferred_keys or if to_replace_id exists
media_type_enum = suggestion.contents['media_type_enum']
preferred_references = []
if media_type_enum in MediaType.image_types and ('preferred::{}'.format(suggestion.key.id()) in self.preferred_keys or to_replace_id):
preferred_references = [team_reference]
media = MediaCreator.create_media_model(suggestion, team_reference, preferred_references)
# Do all DB writes
if to_replace:
MediaManipulator.createOrUpdate(to_replace, auto_union=False)
return MediaManipulator.createOrUpdate(media)
示例2: get
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def get(self):
suggestions = Suggestion.query().filter(
Suggestion.review_state == Suggestion.REVIEW_PENDING).filter(
Suggestion.target_model == "media")
reference_keys = []
for suggestion in suggestions:
reference_keys.append(Media.create_reference(
suggestion.contents['reference_type'],
suggestion.contents['reference_key']))
if 'details_json' in suggestion.contents:
suggestion.details = json.loads(suggestion.contents['details_json'])
if 'image_partial' in suggestion.details:
suggestion.details['thumbnail'] = suggestion.details['image_partial'].replace('_l', '_m')
reference_futures = ndb.get_multi_async(reference_keys)
references = map(lambda r: r.get_result(), reference_futures)
suggestions_and_references = zip(suggestions, references)
self.template_values.update({
"suggestions_and_references": suggestions_and_references,
})
path = os.path.join(os.path.dirname(__file__), '../../templates/suggest_team_media_review_list.html')
self.response.out.write(template.render(path, self.template_values))
示例3: _process_request
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def _process_request(self, request, event_key):
try:
video_list = json.loads(request.body)
except Exception:
self._errors = json.dumps({"Error": "Invalid JSON. Please check input."})
self.abort(400)
return
if not isinstance(video_list, list) or not video_list:
self._errors = json.dumps({"Error": "Invalid JSON. Please check input."})
self.abort(400)
return
media_to_put = []
event_reference = Media.create_reference('event', self.event.key_name)
for youtube_id in video_list:
media = Media(
id=Media.render_key_name(MediaType.YOUTUBE_VIDEO, youtube_id),
foreign_key=youtube_id,
media_type_enum=MediaType.YOUTUBE_VIDEO,
details_json=None,
private_details_json=None,
year=self.event.year,
references=[event_reference],
preferred_references=[],
)
media_to_put.append(media)
MediaManipulator.createOrUpdate(media_to_put)
示例4: get_media_and_team_ref
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def get_media_and_team_ref(self, team_number):
media_key_name = self.request.get("media_key_name")
media = Media.get_by_id(media_key_name)
if not media:
self.abort(400)
team_ref = Media.create_reference('team', 'frc{}'.format(team_number))
return media, team_ref
示例5: from_suggestion
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def from_suggestion(cls, suggestion):
team_reference = Media.create_reference(
suggestion.contents['reference_type'],
suggestion.contents['reference_key'])
media = MediaCreator.create_media_model(suggestion, team_reference)
return MediaManipulator.createOrUpdate(media)
示例6: get
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def get(self):
suggestions = Suggestion.query().filter(
Suggestion.review_state == Suggestion.REVIEW_PENDING).filter(
Suggestion.target_model == "event_media").fetch(limit=50)
# Quick and dirty way to group images together
suggestions = sorted(suggestions, key=lambda x: 0 if x.contents['media_type_enum'] in MediaType.image_types else 1)
reference_keys = []
for suggestion in suggestions:
reference_key = suggestion.contents['reference_key']
reference = Media.create_reference(
suggestion.contents['reference_type'],
reference_key)
reference_keys.append(reference)
if 'details_json' in suggestion.contents:
suggestion.details = json.loads(suggestion.contents['details_json'])
if 'image_partial' in suggestion.details:
suggestion.details['thumbnail'] = suggestion.details['image_partial'].replace('_l', '_m')
reference_futures = ndb.get_multi_async(reference_keys)
references = map(lambda r: r.get_result(), reference_futures)
suggestions_and_references = zip(suggestions, references)
self.template_values.update({
"suggestions_and_references": suggestions_and_references,
})
self.response.out.write(jinja2_engine.render('suggestions/suggest_event_media_review_list.html', self.template_values))
示例7: get
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def get(self):
super(SuggestDesignsReviewController, self).get()
if self.request.get('action') and self.request.get('id'):
# Fast-path review
self._fastpath_review()
suggestions = Suggestion.query().filter(
Suggestion.review_state == Suggestion.REVIEW_PENDING).filter(
Suggestion.target_model == "robot").fetch(limit=50)
reference_keys = []
for suggestion in suggestions:
reference_key = suggestion.contents['reference_key']
reference = Media.create_reference(
suggestion.contents['reference_type'],
reference_key)
reference_keys.append(reference)
reference_futures = ndb.get_multi_async(reference_keys)
references = map(lambda r: r.get_result(), reference_futures)
suggestions_and_references = zip(suggestions, references)
self.template_values.update({
"suggestions_and_references": suggestions_and_references,
})
self.response.out.write(jinja2_engine.render('suggestions/suggest_designs_review.html', self.template_values))
示例8: _process_accepted
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def _process_accepted(self, accept_key):
"""
Performs all actions for an accepted Suggestion in a Transaction.
Suggestions are processed one at a time (instead of in batch) in a
Transaction to prevent possible race conditions.
Actions include:
- Creating and saving a new Media for the Suggestion
- Removing a reference from another Media's preferred_references
- Marking the Suggestion as accepted and saving it
"""
# Async get
suggestion_future = Suggestion.get_by_id_async(accept_key)
# Resolve async Futures
suggestion = suggestion_future.get_result()
# Make sure Suggestion hasn't been processed (by another thread)
if suggestion.review_state != Suggestion.REVIEW_PENDING:
return
team_reference = Media.create_reference(
suggestion.contents['reference_type'],
suggestion.contents['reference_key'])
media = MediaCreator.create_media(suggestion, team_reference)
# Mark Suggestion as accepted
suggestion.review_state = Suggestion.REVIEW_ACCEPTED
suggestion.reviewer = self.user_bundle.account.key
suggestion.reviewed_at = datetime.datetime.now()
# Do all DB writes
MediaManipulator.createOrUpdate(media)
suggestion.put()
示例9: create_target_model
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def create_target_model(self, suggestion):
# Setup
to_replace = None
to_replace_id = self.request.POST.get("replace-preferred-{}".format(suggestion.key.id()), None)
# Remove preferred reference from another Media if specified
team_reference = Media.create_reference(
suggestion.contents["reference_type"], suggestion.contents["reference_key"]
)
if to_replace_id:
to_replace = Media.get_by_id(to_replace_id)
if team_reference not in to_replace.preferred_references:
return # Preferred reference must have been edited earlier. Skip this Suggestion for now.
to_replace.preferred_references.remove(team_reference)
# Add preferred reference to current Media (images only) if explicitly listed in preferred_keys or if to_replace_id exists
media_type_enum = suggestion.contents["media_type_enum"]
preferred_references = []
if media_type_enum in MediaType.image_types and (
"preferred::{}".format(suggestion.key.id()) in self.preferred_keys or to_replace_id
):
preferred_references = [team_reference]
media = MediaCreator.create_media_model(suggestion, team_reference, preferred_references)
# Mark Suggestion as accepted
suggestion.review_state = Suggestion.REVIEW_ACCEPTED
suggestion.reviewer = self.user_bundle.account.key
suggestion.reviewed_at = datetime.datetime.now()
# Do all DB writes
if to_replace:
MediaManipulator.createOrUpdate(to_replace, auto_union=False)
MediaManipulator.createOrUpdate(media)
示例10: get
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def get(self):
suggestions = (
Suggestion.query()
.filter(Suggestion.review_state == Suggestion.REVIEW_PENDING)
.filter(Suggestion.target_model == "media")
.fetch(limit=50)
)
# Quick and dirty way to group images together
suggestions = sorted(
suggestions, key=lambda x: 0 if x.contents["media_type_enum"] in MediaType.image_types else 1
)
reference_keys = []
existing_preferred_keys_futures = []
for suggestion in suggestions:
reference_key = suggestion.contents["reference_key"]
reference = Media.create_reference(suggestion.contents["reference_type"], reference_key)
reference_keys.append(reference)
if "details_json" in suggestion.contents:
suggestion.details = json.loads(suggestion.contents["details_json"])
if "image_partial" in suggestion.details:
suggestion.details["thumbnail"] = suggestion.details["image_partial"].replace("_l", "_m")
# Find existing preferred images
existing_preferred_keys_futures.append(
Media.query(
Media.media_type_enum.IN(MediaType.image_types),
Media.references == reference,
Media.preferred_references == reference,
Media.year == suggestion.contents["year"],
).fetch_async(keys_only=True)
)
reference_futures = ndb.get_multi_async(reference_keys)
existing_preferred_futures = map(lambda x: ndb.get_multi_async(x.get_result()), existing_preferred_keys_futures)
references = map(lambda r: r.get_result(), reference_futures)
existing_preferred = map(lambda l: map(lambda x: x.get_result(), l), existing_preferred_futures)
suggestions_and_references_and_preferred = zip(suggestions, references, existing_preferred)
self.template_values.update(
{
"suggestions_and_references_and_preferred": suggestions_and_references_and_preferred,
"max_preferred": Media.MAX_PREFERRED,
}
)
self.response.out.write(
jinja2_engine.render("suggestions/suggest_team_media_review_list.html", self.template_values)
)
示例11: create_target_model
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def create_target_model(self, suggestion):
# Setup
# Remove preferred reference from another Media if specified
event_reference = Media.create_reference(
suggestion.contents['reference_type'],
suggestion.contents['reference_key'])
media = MediaCreator.create_media_model(suggestion, event_reference, [])
# Do all DB writes
return MediaManipulator.createOrUpdate(media)
示例12: _process_accepted
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def _process_accepted(self, accept_key, preferred_keys):
"""
Performs all actions for an accepted Suggestion in a Transaction.
Suggestions are processed one at a time (instead of in batch) in a
Transaction to prevent possible race conditions.
Actions include:
- Creating and saving a new Media for the Suggestion
- Removing a reference from another Media's preferred_references
- Marking the Suggestion as accepted and saving it
"""
# Async get
suggestion_future = Suggestion.get_by_id_async(accept_key)
# Setup
to_replace_id = self.request.POST.get('replace-preferred-{}'.format(accept_key), None)
# Resolve async Futures
suggestion = suggestion_future.get_result()
# Make sure Suggestion hasn't been processed (by another thread)
if suggestion.review_state != Suggestion.REVIEW_PENDING:
return
# Remove preferred reference from another Media if specified
team_reference = Media.create_reference(
suggestion.contents['reference_type'],
suggestion.contents['reference_key'])
if to_replace_id:
to_replace = Media.get_by_id(to_replace_id)
if team_reference not in to_replace.preferred_references:
return # Preferred reference must have been edited earlier. Skip this Suggestion for now.
to_replace.preferred_references.remove(team_reference)
# Add preferred reference to current Media (images only) if explicitly listed in preferred_keys or if to_replace_id exists
media_type_enum = suggestion.contents['media_type_enum']
preferred_references = []
if media_type_enum in MediaType.image_types and ('preferred::{}'.format(suggestion.key.id()) in preferred_keys or to_replace_id):
preferred_references = [team_reference]
media = MediaCreator.create_media(suggestion, team_reference, preferred_references)
# Mark Suggestion as accepted
suggestion.review_state = Suggestion.REVIEW_ACCEPTED
suggestion.reviewer = self.user_bundle.account.key
suggestion.reviewed_at = datetime.datetime.now()
# Do all DB writes
if to_replace_id:
MediaManipulator.createOrUpdate(to_replace, auto_union=False)
MediaManipulator.createOrUpdate(media)
suggestion.put()
示例13: get
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def get(self):
df = DatafeedResourceLibrary()
teams = df.getHallOfFameTeams()
if teams:
media_to_update = []
for team in teams:
team_reference = Media.create_reference('team', team['team_id'])
video_foreign_key = team['video']
if video_foreign_key:
media_to_update.append(Media(id=Media.render_key_name(MediaType.YOUTUBE_VIDEO, video_foreign_key),
media_type_enum=MediaType.YOUTUBE_VIDEO,
media_tag_enum=[MediaTag.CHAIRMANS_VIDEO],
references=[team_reference],
year=team['year'],
foreign_key=video_foreign_key))
presentation_foreign_key = team['presentation']
if presentation_foreign_key:
media_to_update.append(Media(id=Media.render_key_name(MediaType.YOUTUBE_VIDEO, presentation_foreign_key),
media_type_enum=MediaType.YOUTUBE_VIDEO,
media_tag_enum=[MediaTag.CHAIRMANS_PRESENTATION],
references=[team_reference],
year=team['year'],
foreign_key=presentation_foreign_key))
essay_foreign_key = team['essay']
if essay_foreign_key:
media_to_update.append(Media(id=Media.render_key_name(MediaType.EXTERNAL_LINK, essay_foreign_key),
media_type_enum=MediaType.EXTERNAL_LINK,
media_tag_enum=[MediaTag.CHAIRMANS_ESSAY],
references=[team_reference],
year=team['year'],
foreign_key=essay_foreign_key))
MediaManipulator.createOrUpdate(media_to_update)
else:
logging.info("No Hall of Fame teams found")
teams = []
template_values = {
'teams': teams,
}
if 'X-Appengine-Taskname' not in self.request.headers: # Only write out if not in taskqueue
path = os.path.join(os.path.dirname(__file__), '../templates/datafeeds/hall_of_fame_teams_get.html')
self.response.out.write(template.render(path, template_values))
示例14: _process_accepted
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def _process_accepted(self, accept_key):
"""
Performs all actions for an accepted Suggestion in a Transaction.
Suggestions are processed one at a time (instead of in batch) in a
Transaction to prevent possible race conditions.
Actions include:
- Creating and saving a new Media for the Suggestion
- Removing a reference from another Media's preferred_references
- Marking the Suggestion as accepted and saving it
"""
# Async get
suggestion_future = Suggestion.get_by_id_async(accept_key)
# Setup
to_replace_id = self.request.POST.get('replace-preferred-{}'.format(accept_key), None)
# Resolve async Futures
suggestion = suggestion_future.get_result()
# Make sure Suggestion hasn't been processed (by another thread)
if suggestion.review_state != Suggestion.REVIEW_PENDING:
return
team_reference = Media.create_reference(
suggestion.contents['reference_type'],
suggestion.contents['reference_key'])
media_type_enum = suggestion.contents['media_type_enum']
media = Media(
id=Media.render_key_name(suggestion.contents['media_type_enum'], suggestion.contents['foreign_key']),
foreign_key=suggestion.contents['foreign_key'],
media_type_enum=media_type_enum,
details_json=suggestion.contents.get('details_json', None),
private_details_json=suggestion.contents.get('private_details_json', None),
year=int(suggestion.contents['year']) if not suggestion.contents.get('is_social', False) else None,
references=[team_reference],
)
# Mark Suggestion as accepted
suggestion.review_state = Suggestion.REVIEW_ACCEPTED
suggestion.reviewer = self.user_bundle.account.key
suggestion.reviewed_at = datetime.datetime.now()
# Do all DB writes
MediaManipulator.createOrUpdate(media)
suggestion.put()
示例15: test_remove_media_reference
# 需要导入模块: from models.media import Media [as 别名]
# 或者: from models.media.Media import create_reference [as 别名]
def test_remove_media_reference(self):
self.loginUser()
self.giveTeamAdminAccess()
team_reference = Media.create_reference('team', 'frc1124')
suggestion_id = self.createMediaSuggestion()
suggestion = Suggestion.get_by_id(suggestion_id)
media = MediaCreator.create_media_model(suggestion, team_reference)
media_id = media.put()
self.assertTrue(ndb.Key(Team, 'frc1124') in media.references)
form = self.getMediaAdminForm('remove_media', media_id.id())
response = form.submit().follow()
self.assertEqual(response.status_int, 301)
media = media_id.get()
self.assertFalse(team_reference in media.references)