Example #1
0
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
Example #2
0
def recreate_topic_list_structure():
    import topics_list
    logging.info("recreating topic_list structure")

    version = TopicVersion.get_edit_version()
    root = Topic.get_by_id("root", version)
    delete_topics = recursive_copy_topic_list_structure(root, topics_list.PLAYLIST_STRUCTURE)
    for topic in delete_topics.values():
        topic.delete_tree()
Example #3
0
def recreate_topic_list_structure():
    import topics_list
    logging.info("recreating topic_list structure")

    version = TopicVersion.get_edit_version()
    root = Topic.get_by_id("root", version)
    delete_topics = recursive_copy_topic_list_structure(
        root, topics_list.PLAYLIST_STRUCTURE)
    for topic in delete_topics.values():
        topic.delete_tree()
    deferred.defer(importSmartHistory)
Example #4
0
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