コード例 #1
0
ファイル: main.py プロジェクト: PaulWagener/khan-website
    def show_video(handler, readable_id, topic_id,
                   redirect_to_canonical_url=False):
        topic = None
        query_string = ''

        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 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)

            if handler.request.query_string:
                query_string = '?' + handler.request.query_string

            redirect_to_canonical_url = True


        if redirect_to_canonical_url:
            url = "/%s/v/%s%s" % (topic.get_extended_slug(),
                                  urllib.quote(readable_id),
                                  query_string)
            logging.info("Redirecting to %s" % url)
            handler.redirect(url, True)
            return None

        # Note: Bingo conversions are tracked on the client now,
        # so they have been removed here. (tomyedwab)

        topic_data = topic.get_play_data()

        discussion_options = qa.add_template_values({}, handler.request)
        video_data = Video.get_play_data(readable_id, topic,
                                         discussion_options)
        if video_data is None:
            raise MissingVideoException("Missing video '%s'" % readable_id)

        template_values = {
            "topic_data": topic_data,
            "topic_data_json": api.jsonify.jsonify(topic_data),
            "video": video_data,
            "video_data_json": api.jsonify.jsonify(video_data),
            "selected_nav_link": 'watch',
        }

        return template_values
コード例 #2
0
    def show_video(handler, readable_id, topic_id,
                   redirect_to_canonical_url=False):
        topic = None
        query_string = ''

        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 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)

            if handler.request.query_string:
                query_string = '?' + handler.request.query_string

            redirect_to_canonical_url = True


        if redirect_to_canonical_url:
            url = "/%s/v/%s%s" % (topic.get_extended_slug(),
                                  urllib.quote(readable_id),
                                  query_string)
            logging.info("Redirecting to %s" % url)
            handler.redirect(url, True)
            return None

        # Note: Bingo conversions are tracked on the client now,
        # so they have been removed here. (tomyedwab)

        topic_data = topic.get_play_data()

        discussion_options = qa.add_template_values({}, handler.request)
        video_data = Video.get_play_data(readable_id, topic,
                                         discussion_options)
        if video_data is None:
            raise MissingVideoException("Missing video '%s'" % readable_id)

        template_values = {
            "topic_data": topic_data,
            "topic_data_json": api.jsonify.jsonify(topic_data),
            "video": video_data,
            "video_data_json": api.jsonify.jsonify(video_data),
            "selected_nav_link": 'watch',
        }

        return template_values
コード例 #3
0
ファイル: main.py プロジェクト: johnfelipe/khan-multilingual
    def show_topic(handler, topic):
        selected_topic = topic
        parent_topic = db.get(topic.parent_keys[0])

        # If the parent is a supertopic, use that instead
        if parent_topic.id in Topic._super_topic_ids:
            topic = parent_topic
        elif not (topic.id in Topic._super_topic_ids
                  or topic.has_children_of_type(["Video"])):
            handler.redirect("/", True)
            return

        template_values = {
            "main_topic": topic,
            "selected_topic": selected_topic,
        }
        handler.render_jinja2_template('viewtopic.html', template_values)
コード例 #4
0
ファイル: main.py プロジェクト: Hao-Hsuan/KhanLatest
    def show_topic(handler, topic):
        selected_topic = topic
        parent_topic = db.get(topic.parent_keys[0])

        # If the parent is a supertopic, use that instead
        if parent_topic.id in Topic._super_topic_ids:
            topic = parent_topic
        elif not (topic.id in Topic._super_topic_ids or
                  topic.has_children_of_type(["Video"])):
            handler.redirect("/", True)
            return

        template_values = {
            "main_topic": topic,
            "selected_topic": selected_topic,
        }
        handler.render_jinja2_template('viewtopic.html', template_values)