Beispiel #1
0
    def from_version(version=None):
        if version == None:
            version = topic_models.TopicVersion.get_edit_version()

        root = topic_models.Topic.get_root(version)
        tree = jsonify.dumps(root.make_tree(["Topics"]))
        #XXX invi: hardcoded math topic for NL version
        # it's needed an option to select the subtopic to create a Map Layout
        subtopics = tree['children'][0]['children']

        #TODO check positions for collitions
        layout_topics = {}
        for topic in subtopics:
            data = {
                    "icon_url" : topic['icon_url'],
                    "id" : topic['id'],
                    "x" :  str(topic['h_position']),
                    "y" :  str(topic['v_position']),
                    "standalone_title" : topic['standalone_title']
            }
            layout_topics[topic['standalone_title']] = data

        layout = {"polylines": [], "topics": layout_topics}
        return layout
Beispiel #2
0
def get_videoless_exercises():
    version = topic_models.TopicVersion.get_latest_version()
    root = topic_models.Topic.get_root(version).make_tree([], False)
    exercises = exercise_models.Exercise.all().fetch(1000)

    def children_recursive(current, ex_list=None, topics=[]):
        current['topics'] = topics[1:]
        if current['kind'] == "Topic":
            topics.append(current['title'])
            for node in current['children']:
                children_recursive(node, ex_list, list(topics))
        elif current['kind'] == "Exercise":
            try:
                exercise = next(i for i in exercises if i.name == current['name'])
                current['video_requests_count'] = exercise.video_requests_count
                if len(current['related_video_readable_ids']) == 0:
                    ex_list.append(current)
            except StopIteration:
                logging.info("Exercise from topic tree '%s' couldn't be found" % current['name'])
                pass

        return ex_list

    return children_recursive(jsonify.dumps(root), [], [])