Beispiel #1
0
def import_course_and_section(full_course_code, semester, course_title,
                              primary_section_code, stat):
    """
    Given course and section info, update/create objects.
    """
    primary_listing = None
    if primary_section_code:
        try:
            dept, ccode, _ = separate_course_code(primary_section_code)
        except ValueError:
            stat("invalid_primary_section_id")
            return
        primary_listing, _ = get_or_create_course(dept, ccode, semester)

    try:
        course, section, _, _ = get_or_create_course_and_section(
            full_course_code,
            semester,
            course_defaults={
                "primary_listing": primary_listing,
                "title": course_title or ""
            },
        )
    except ValueError:
        stat("invalid_section_id")
        return None, None

    # Update course title if one isn't already set.
    if course_title and not course.title:
        course.title = course_title
        course.save()
        stat("courses_updated")

    return course, section
Beispiel #2
0
def import_description_rows(num_rows,
                            rows,
                            semesters=None,
                            show_progress_bar=True):
    """
    Imports description rows given an iterator rows and total number of rows num_rows.
    Optionally filter courses for which to update descriptions by semester with the
    given semesters list.
    """
    descriptions = dict()

    for row in tqdm(rows, total=num_rows, disable=(not show_progress_bar)):
        course_code = row.get("COURSE_ID")
        paragraph_num = row.get("PARAGRAPH_NUMBER")
        description_paragraph = row.get("COURSE_DESCRIPTION")

        desc = descriptions.get(course_code, dict())
        desc[int(paragraph_num)] = description_paragraph
        descriptions[course_code] = desc

    for course_id, paragraphs in tqdm(descriptions.items(),
                                      disable=(not show_progress_bar)):
        dept_code, course_code, _ = separate_course_code(course_id,
                                                         allow_partial=True)
        if course_code is None:
            continue
        # Don't replace descriptions which are already present (from registrar import, most likely).
        courses = Course.objects.filter(department__code=dept_code,
                                        code=course_code,
                                        description="")

        if semesters is not None:
            courses = courses.filter(semester__in=semesters)

        paragraphs = list(paragraphs.items())
        paragraphs.sort(key=lambda x: x[0])
        description = "\n".join([p for _, p in paragraphs])
        courses.update(description=description)
Beispiel #3
0
 def test_invalid_course(self):
     with self.assertRaises(ValueError):
         separate_course_code("BLAH BLAH BLAH")
Beispiel #4
0
 def test_course_code_3_chars(self):
     self.assertEqual(("INTL", "BUL", "001"),
                      separate_course_code("INTLBUL001"))
Beispiel #5
0
 def test_course_code_ends_in_character(self):
     self.assertEqual(("CRIM", "6004A", "301"),
                      separate_course_code("CRIM6004A301"))
Beispiel #6
0
 def test_section_characters(self):
     self.assertEqual(("INTL", "2980", "BKC"),
                      separate_course_code("INTL2980BKC"))
Beispiel #7
0
 def test_two_letter_with_dashes(self):
     self.assertEqual(("WH", "110", "001"),
                      separate_course_code("WH  -110-001"))
Beispiel #8
0
 def test_three_letter_with_dashes(self):
     self.assertEqual(("CIS", "110", "001"),
                      separate_course_code("CIS -110-001"))
Beispiel #9
0
 def test_four_letter_with_dashes(self):
     self.assertEqual(("PSCI", "110", "001"),
                      separate_course_code("PSCI-110-001"))
Beispiel #10
0
 def test_two_letter_dept_code(self):
     self.assertEqual(("WH", "1100", "001"),
                      separate_course_code("WH  1100001"))
Beispiel #11
0
 def test_three_letter_dept_code(self):
     self.assertEqual(("CIS", "1200", "001"),
                      separate_course_code("CIS 1200001"))
Beispiel #12
0
 def test_four_letter_dept_code(self):
     self.assertEqual(("ANTH", "3610", "401"),
                      separate_course_code("ANTH3610401"))