Exemplo n.º 1
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
Exemplo n.º 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
Exemplo n.º 3
0
    def importIntoVersion(version):
        logging.info("comparing to version number %i" % version.number)
        topic = Topic.get_by_id("art-history", version)

        if not topic:
            parent = Topic.get_by_id("humanities---other", version)
            if not parent:
                raise Exception("Could not find the Humanities & Other topic to put art history into")
            topic = Topic.insert(title="Art History",
                                 parent=parent,
                                 id="art-history",
                                 standalone_title="Art History",
                                 description="Spontaneous conversations about works of art where the speakers are not afraid to disagree with each other or art history orthodoxy. Videos are made by Dr. Beth Harris and Dr. Steven Zucker along with other contributors.")
        
        urls = topic.get_urls(include_descendants=True)
        href_to_key_dict = dict((url.url, url.key()) for url in urls)
        
        videos = topic.get_videos(include_descendants=True)
        video_dict = dict((v.youtube_id, v) for v in videos)

        content = getSmartHistoryContent()
        if content is None:
            raise Exception("Aborting import, could not read from smarthistory")

        subtopics = topic.get_child_topics()
        subtopic_dict = dict((t.title, t) for t in subtopics)
        subtopic_child_keys = {}
        
        new_subtopic_keys = []

        child_keys = []
        i = 0
        for link in content:
            href = link["href"]
            title = link["title"]
            parent_title = link["parent"]
            content = link["content"]
            youtube_id = link["youtube_id"] if "youtube_id" in link else None
            extra_properties = {"original_url": href}

            if parent_title not in subtopic_dict:
                subtopic = Topic.insert(title=parent_title,
                                 parent=topic,
                                 standalone_title="Art History: %s" 
                                                  % parent_title,
                                 description="")

                subtopic_dict[parent_title] = subtopic
            else:
                subtopic = subtopic_dict[parent_title]
           
            if subtopic.key() not in new_subtopic_keys:
                new_subtopic_keys.append(subtopic.key())

            if parent_title not in subtopic_child_keys:
                 subtopic_child_keys[parent_title] = []
            
            if youtube_id:
                if youtube_id not in video_dict:
                    # make sure it didn't get imported before, but never put 
                    # into a topic
                    query = video_models.Video.all()
                    video = query.filter("youtube_id =", youtube_id).get()

                    if video is None:
                        logging.info("adding youtube video %i %s %s %s to %s" % 
                                     (i, youtube_id, href, title, parent_title))
                        
                        video_data = youtube_get_video_data_dict(youtube_id)
                        # use the title from the webpage not from the youtube 
                        # page
                        video = None
                        if video_data:
                            video_data["title"] = title
                            video_data["extra_properties"] = extra_properties
                            video = topic_models.VersionContentChange.add_new_content(
                                                                video_models.Video,
                                                                version,
                                                                video_data)
                        else:
                            logging.error(("Could not import youtube_id %s " +
                                          "for %s %s") % (youtube_id, href, title))
                            
                            raise Exception(("Could not import youtube_id %s " +
                                            " for %s %s") % (youtube_id, href, 
                                            title))

                else:
                    video = video_dict[youtube_id] 
                    if video.extra_properties != extra_properties:
                        logging.info(("changing extra properties of %i %s %s " +
                                     "from %s to %s") % (i, href, title, 
                                     video.extra_properties, extra_properties))
                        
                        video.extra_properties = extra_properties
                        video.put()
                                    
                if video:
                    subtopic_child_keys[parent_title].append(video.key())

            elif href not in href_to_key_dict:
                logging.info("adding %i %s %s to %s" % 
                             (i, href, title, parent_title))
                
                topic_models.VersionContentChange.add_new_content(
                    Url, 
                    version,
                    {"title": title,
                     "url": href
                    },
                    ["title", "url"])

                url = Url(url=href,
                          title=title,
                          id=id)

                url.put()
                subtopic_child_keys[parent_title].append(url.key())

            else:
                subtopic_child_keys[parent_title].append(href_to_key_dict[href])

            i += 1

        logging.info("updating child_keys")
        change = False
        for parent_title, child_keys in subtopic_child_keys.iteritems():
            subtopic = subtopic_dict[parent_title]
            if subtopic.child_keys != subtopic_child_keys[parent_title]:
                change = True
                subtopic.update(child_keys=subtopic_child_keys[parent_title])
        
        if topic.child_keys != new_subtopic_keys:    
            change = True
            topic.update(child_keys=new_subtopic_keys)
        
        if change:
            logging.info("finished updating version number %i" % version.number)
        else:
            logging.info("nothing changed")

        return change
Exemplo n.º 4
0
    def importIntoVersion(version):
        logging.info("comparing to version number %i" % version.number)
        topic = Topic.get_by_id("art-history", version)

        if not topic:
            parent = Topic.get_by_id("humanities---other", version)
            if not parent:
                raise Exception("Could not find the Humanities & Other topic to put art history into")
            topic = Topic.insert(title="Art History",
                                 parent=parent,
                                 id="art-history",
                                 standalone_title="Art History",
                                 description="Spontaneous conversations about works of art where the speakers are not afraid to disagree with each other or art history orthodoxy. Videos are made by Dr. Beth Harris and Dr. Steven Zucker along with other contributors.")
        
        urls = topic.get_urls(include_descendants=True)
        href_to_key_dict = dict((url.url, url.key()) for url in urls)
        
        videos = topic.get_videos(include_descendants=True)
        video_dict = dict((v.youtube_id, v) for v in videos)

        content = getSmartHistoryContent()
        if content is None:
            raise Exception("Aborting import, could not read from smarthistory")

        subtopics = topic.get_child_topics()
        subtopic_dict = dict((t.title, t) for t in subtopics)
        subtopic_child_keys = {}
        
        new_subtopic_keys = []

        child_keys = []
        i = 0
        for link in content:
            href = link["href"]
            title = link["title"]
            parent_title = link["parent"]
            content = link["content"]
            youtube_id = link["youtube_id"] if "youtube_id" in link else None
            extra_properties = {"original_url": href}

            if parent_title not in subtopic_dict:
                subtopic = Topic.insert(title=parent_title,
                                 parent=topic,
                                 standalone_title="Art History: %s" 
                                                  % parent_title,
                                 description="")

                subtopic_dict[parent_title] = subtopic
            else:
                subtopic = subtopic_dict[parent_title]
           
            if subtopic.key() not in new_subtopic_keys:
                new_subtopic_keys.append(subtopic.key())

            if parent_title not in subtopic_child_keys:
                 subtopic_child_keys[parent_title] = []
            
            if youtube_id:
                if youtube_id not in video_dict:
                    # make sure it didn't get imported before, but never put 
                    # into a topic
                    query = video_models.Video.all()
                    video = query.filter("youtube_id =", youtube_id).get()

                    if video is None:
                        logging.info("adding youtube video %i %s %s %s to %s" % 
                                     (i, youtube_id, href, title, parent_title))
                        
                        video_data = youtube_get_video_data_dict(youtube_id)
                        # use the title from the webpage not from the youtube 
                        # page
                        video = None
                        if video_data:
                            video_data["title"] = title
                            video_data["extra_properties"] = extra_properties
                            video = topic_models.VersionContentChange.add_new_content(
                                                                video_models.Video,
                                                                version,
                                                                video_data)
                        else:
                            logging.error(("Could not import youtube_id %s " +
                                          "for %s %s") % (youtube_id, href, title))
                            
                            raise Exception(("Could not import youtube_id %s " +
                                            " for %s %s") % (youtube_id, href, 
                                            title))

                else:
                    video = video_dict[youtube_id] 
                    if video.extra_properties != extra_properties:
                        logging.info(("changing extra properties of %i %s %s " +
                                     "from %s to %s") % (i, href, title, 
                                     video.extra_properties, extra_properties))
                        
                        video.extra_properties = extra_properties
                        video.put()
                                    
                if video:
                    subtopic_child_keys[parent_title].append(video.key())

            elif href not in href_to_key_dict:
                logging.info("adding %i %s %s to %s" % 
                             (i, href, title, parent_title))
                
                topic_models.VersionContentChange.add_new_content(
                    Url, 
                    version,
                    {"title": title,
                     "url": href
                    },
                    ["title", "url"])

                url = Url(url=href,
                          title=title,
                          id=id)

                url.put()
                subtopic_child_keys[parent_title].append(url.key())

            else:
                subtopic_child_keys[parent_title].append(href_to_key_dict[href])

            i += 1

        logging.info("updating child_keys")
        change = False
        for parent_title, child_keys in subtopic_child_keys.iteritems():
            subtopic = subtopic_dict[parent_title]
            if subtopic.child_keys != subtopic_child_keys[parent_title]:
                change = True
                subtopic.update(child_keys=subtopic_child_keys[parent_title])
        
        if topic.child_keys != new_subtopic_keys:    
            change = True
            topic.update(child_keys=new_subtopic_keys)
        
        if change:
            logging.info("finished updating version number %i" % version.number)
        else:
            logging.info("nothing changed")

        return change