def handle(self, *args, **kwargs):

        MALFORMED_IDS = []

        video_slugs = set(video_dict_by_video_id().keys())
        exercise_slugs = set(get_flat_topic_tree()["Exercise"].keys())

        all_playlists = json.load(open(os.path.join(settings.PROJECT_PATH, 'playlist/playlists.json')))

        # for pl in Playlist.all():
        for pl in all_playlists:
            # entries = pl.entries
            entries = pl.get("entries")

            # Find video ids in the playlists that are not in the topic tree
            video_entry_slugs = [enforce_and_strip_slug(pl.get("id"), e['entity_id']) for e in entries if e['entity_kind'] == 'Video']
            nonexistent_video_slugs = set(filter(None, video_entry_slugs)) - video_slugs

            # Find exercise ids in the playlists that are not in the topic tree
            ex_entry_slugs = [enforce_and_strip_slug(pl.get("id"), e['entity_id']) for e in entries if e['entity_kind'] == 'Exercise']
            nonexistent_ex_slugs = set(filter(None, ex_entry_slugs)) - exercise_slugs

            # Print malformed videos
            for slug in nonexistent_video_slugs:
                errormsg = "Video slug in playlist {0} not found in videos: {1}"
                # print errormsg.format(pl.id, slug)
                print errormsg.format(pl.get("id"), slug)

            # Print malformed exercises
            for slug in nonexistent_ex_slugs:
                errormsg = "Exercise slug in playlist {0} not found in exercises: {1}"
                # print errormsg.format(pl.id, slug)
                print errormsg.format(pl.get("id"), slug)

            # Print misspelled ids
            for m in MALFORMED_IDS:
                errormsg = "Malformed slug in playlist {0}. Please investigate: {1}"
                # print errormsg.format(pl.id, slug)
                print errormsg.format(pl.get("id"), m)
            MALFORMED_IDS = []
Example #2
0
    def add_full_title_from_topic_tree(entry, video_title_dict):
        # TODO (aron): Add i18n by varying the language of the topic tree here
        topictree = get_flat_topic_tree(alldata=True)

        entry_kind = entry["entity_kind"]
        entry_name = entry["entity_id"]

        try:
            if entry_kind == "Exercise":
                nodedict = topictree["Exercise"]
            elif entry_kind == "Video":
                # TODO-blocker: move use of video_dict_by_id to slug2id_map
                nodedict = video_title_dict
            else:
                nodedict = {}

            entry["title"] = nodedict[entry_name]["title"]
            entry["description"] = nodedict[entry_name].get("description", "")
        except KeyError:
            # TODO: edit once we get the properly labeled entity ids from Nalanda
            entry["title"] = entry["description"] = entry["entity_id"]

        return entry
Example #3
0
    def add_full_title_from_topic_tree(entry, video_title_dict):
        # TODO (aron): Add i18n by varying the language of the topic tree here
        topictree = get_flat_topic_tree(alldata=True)

        entry_kind = entry['entity_kind']
        entry_name = entry['entity_id']

        try:
            if entry_kind == 'Exercise':
                nodedict = topictree['Exercise']
            elif entry_kind == 'Video':
                # TODO-blocker: move use of video_dict_by_id to slug2id_map
                nodedict = video_title_dict
            else:
                nodedict = {}

            entry['title'] = nodedict[entry_name]['title']
            entry['description'] = nodedict[entry_name].get('description', '')
        except KeyError:
            # TODO: edit once we get the properly labeled entity ids from Nalanda
            entry['title'] = entry['description'] = entry['entity_id']

        return entry
Example #4
0
def flat_topic_tree(request, lang_code):
    return JsonResponse(get_flat_topic_tree(lang_code=lang_code))
Example #5
0
def flat_topic_tree(request, lang_code):
    return JsonResponse(get_flat_topic_tree(lang_code=lang_code))