Beispiel #1
0
def load_all_curriculums_with_unknown_ids(curriculums_base_dir):
    for file_path in curriculum_file_paths(curriculums_base_dir):
        syllabus_frontmatter = frontmatter.load(file_path)
        if DB_ID in syllabus_frontmatter:
            # this one already has an id. Skip it
            continue
        defaults = get_creation_args_from_curricum_frontmatter(
            syllabus_frontmatter)

        curriculum = Curriculum.objects.create(
            id=Curriculum.get_next_available_id(), **defaults)
        syllabus_frontmatter[DB_ID] = curriculum.id
        with open(file_path, "wb") as f:
            frontmatter.dump(syllabus_frontmatter, f)

        set_up_single_curriculum_from_file(curriculum, file_path)
Beispiel #2
0
def load_all_curriculums_with_known_ids(curriculums_base_dir):
    seen_ids = {}

    for file_path in curriculum_file_paths(curriculums_base_dir):
        syllabus_frontmatter = frontmatter.load(file_path)
        if DB_ID not in syllabus_frontmatter:
            # this one doesn't have a known id. So skip it
            continue
        db_id = syllabus_frontmatter[DB_ID]

        assert (
            db_id not in seen_ids
        ), f"Same ID on two content items!!\n\tid={db_id}\n\t{seen_ids[db_id]}\n\t{file_path}"
        seen_ids[db_id] = file_path

        defaults = get_creation_args_from_curricum_frontmatter(
            syllabus_frontmatter)

        curriculum, _ = Curriculum.get_or_create_or_update(id=db_id,
                                                           defaults=defaults,
                                                           overrides=defaults)
        set_up_single_curriculum_from_file(curriculum, file_path)
    def save_all_curriculums_with_unknown_ids(self):
        content_paths = self.recurse_get_all_content_index_file_paths()
        for file_path in content_paths:
            front = frontmatter.load(file_path)
            if DB_ID in front:
                continue

            if front[CONTENT_TYPE] != COURSE:
                continue

            defaults = {
                "name": front["title"],
                "url": self.get_page_url(file_path)
            }

            curriculum = Curriculum.objects.create(
                id=Curriculum.get_next_available_id(), **defaults)

            front[DB_ID] = curriculum.id
            with open(file_path, "wb") as f:
                frontmatter.dump(front, f)

            self.set_up_single_curriculum_from_file(curriculum, file_path)