当前位置: 首页>>代码示例>>Python>>正文


Python Topic.insert方法代码示例

本文整理汇总了Python中models.Topic.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Topic.insert方法的具体用法?Python Topic.insert怎么用?Python Topic.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Topic的用法示例。


在下文中一共展示了Topic.insert方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: recursive_copy_topic_list_structure

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import insert [as 别名]
def recursive_copy_topic_list_structure(parent, topic_list_part):
    delete_topics = {}
    for topic_dict in topic_list_part:
        logging.info(topic_dict["name"])
        if "playlist" in topic_dict:
            topic = Topic.get_by_title_and_parent(topic_dict["name"], parent)
            if topic:
                logging.info(topic_dict["name"] + " is already created")
            else:
                version = TopicVersion.get_edit_version()
                root = Topic.get_root(version)
                topic = Topic.get_by_title_and_parent(topic_dict["playlist"], root)
                if topic:
                    delete_topics[topic.key()] = topic
                    logging.info("copying %s to parent %s" %
                                (topic_dict["name"], parent.title))
                    topic.copy(title=topic_dict["name"], parent=parent,
                               standalone_title=topic.title)
                else:
                    logging.error("Topic not found! %s" % (topic_dict["playlist"]))
        else:
            topic = Topic.get_by_title_and_parent(topic_dict["name"], parent)
            if topic:
                logging.info(topic_dict["name"] + " is already created")
            else:
                logging.info("adding %s to parent %s" %
                             (topic_dict["name"], parent.title))
                topic = Topic.insert(title=topic_dict["name"], parent=parent)

        if "items" in topic_dict:
            delete_topics.update(
                recursive_copy_topic_list_structure(topic,
                                                    topic_dict["items"]))

    return delete_topics
开发者ID:di445,项目名称:server,代码行数:37,代码来源:topics.py

示例2: load_videos

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import insert [as 别名]
def load_videos(version, title=None):
    root = Topic.get_by_id("root", version)
                    
    if title is None:
        playlist = Playlist.all().order('title').get()
    else:
        playlist = Playlist.all().filter('title = ', title).get()
    
    title = playlist.title
    
    nextplaylist = Playlist.all().filter('title >', title).order('title').get()
    if nextplaylist:
        next_title = nextplaylist.title

    playlists = [playlist]
    # playlists = Playlist.all().order('title').fetch(100000)
    for i, p in enumerate(playlists):
        videos = p.get_videos()
        content_keys = [v.key() for v in videos]
        added = 0
        for i, v in enumerate(videos):
            for e in v.related_exercises():
                if e.key() not in content_keys:
                    content_keys.insert(i + added, e.key())
                    added += 1

        topic = Topic.insert(title=p.title,
                     parent=root,
                     description=p.description,
                     tags=p.tags,
                     child_keys=content_keys)
    
    logging.info("loading " + title)
    
    if nextplaylist:
        deferred.defer(load_videos, version, next_title)
    else:
        deferred.defer(hide_topics, version)
开发者ID:di445,项目名称:server,代码行数:40,代码来源:topics.py

示例3: create_root

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import insert [as 别名]
def create_root(version):
    root = Topic.insert(title="The Root of All Knowledge",
            description="All concepts fit into the root of all knowledge",
            id="root",
            version=version)
开发者ID:di445,项目名称:server,代码行数:7,代码来源:topics.py

示例4: importIntoVersion

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import insert [as 别名]
    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)
        hrefs = [url.url for url in urls]
        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"]

            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 href not in hrefs:
                logging.info("adding %i %s %s to %s" % (i, href, title, parent_title))
                models.VersionContentChange.add_new_content(
                    models.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
开发者ID:johnfelipe,项目名称:server,代码行数:90,代码来源:topics.py


注:本文中的models.Topic.insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。