本文整理汇总了Python中models.Topic.get_cached_videos_for_topic方法的典型用法代码示例。如果您正苦于以下问题:Python Topic.get_cached_videos_for_topic方法的具体用法?Python Topic.get_cached_videos_for_topic怎么用?Python Topic.get_cached_videos_for_topic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Topic
的用法示例。
在下文中一共展示了Topic.get_cached_videos_for_topic方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get_cached_videos_for_topic [as 别名]
def get(self, readable_id=""):
# This method displays a video in the context of a particular topic.
# To do that we first need to find the appropriate topic. If we aren't
# given the topic title in a query param, we need to find a topic that
# the video is a part of. That requires finding the video, given it readable_id
# or, to support old URLs, it's youtube_id.
video = None
topic = None
video_id = self.request.get('v')
topic_id = self.request_string('topic', default="")
readable_id = urllib.unquote(readable_id).decode("utf-8")
readable_id = re.sub('-+$', '', readable_id) # remove any trailing dashes (see issue 1140)
# If either the readable_id or topic title is missing,
# redirect to the canonical URL that contains them
redirect_to_canonical_url = False
if video_id: # Support for old links
query = Video.all()
query.filter('youtube_id =', video_id)
video = query.get()
if not video:
raise MissingVideoException("Missing video w/ youtube id '%s'" % video_id)
readable_id = video.readable_id
topic = video.first_topic()
if not topic:
raise MissingVideoException("No topic has video w/ youtube id '%s'" % video_id)
redirect_to_canonical_url = True
if topic_id is not None and len(topic_id) > 0:
topic = Topic.get_by_id(topic_id)
key_id = 0 if not topic else topic.key().id()
# If a topic_id wasn't specified or the specified topic wasn't found
# use the first topic for the requested video.
if topic is None:
# Get video by readable_id just to get the first topic for the video
video = Video.get_for_readable_id(readable_id)
if video is None:
raise MissingVideoException("Missing video '%s'" % readable_id)
topic = video.first_topic()
if not topic:
raise MissingVideoException("No topic has video '%s'" % readable_id)
redirect_to_canonical_url = True
exid = self.request_string('exid', default=None)
if redirect_to_canonical_url:
qs = {'topic': topic.id}
if exid:
qs['exid'] = exid
urlpath = "/video/%s" % urllib.quote(readable_id)
url = urlparse.urlunparse(('', '', urlpath, '', urllib.urlencode(qs), ''))
self.redirect(url, True)
return
# If we got here, we have a readable_id and a topic, so we can display
# the topic and the video in it that has the readable_id. Note that we don't
# query the Video entities for one with the requested readable_id because in some
# cases there are multiple Video objects in the datastore with the same readable_id
# (e.g. there are 2 "Order of Operations" videos).
videos = Topic.get_cached_videos_for_topic(topic)
previous_video = None
next_video = None
for v in videos:
if v.readable_id == readable_id:
v.selected = 'selected'
video = v
elif video is None:
previous_video = v
else:
next_video = v
break
# If we're at the beginning or end of a topic, show the adjacent topic.
# previous_topic/next_topic are the topic to display.
# previous_video_topic/next_video_topic are the subtopics the videos
# are actually in.
previous_topic = None
previous_video_topic = None
next_topic = None
next_video_topic = None
if not previous_video:
previous_topic = topic
while not previous_video:
previous_topic = previous_topic.get_previous_topic()
if previous_topic:
(previous_video, previous_video_topic) = previous_topic.get_last_video_and_topic()
else:
break
if not next_video:
#.........这里部分代码省略.........