Exemple #1
0
def text_sections(_, text_uid):
    """
    Observe all section of text

    :param _: request
    :param text_uid: uid of text to observe
    :return: JsonResponse in form {text_uid, sections: [{id, parent}, ]}
    """
    log.debug(f'start, text_uid={text_uid}')
    parts = Section.build_json(Section.of_text(text_uid))
    log.debug(f'done, text_uid={text_uid}')
    return JsonResponse({'text_uid': text_uid, 'sections': parts}, status=200)
Exemple #2
0
def sub_sections(_, section_uid):
    """
    Observe sub-sections of given part

    :param _: request
    :param section_uid: id of part to observe
    :return: JsonResponse in form {section_id, sections: [{id, parent}, ]}
    """
    log.debug(f'start, part_id={section_uid}')
    parts = Section.build_json(Section.of_section(section_uid))
    log.debug(f'done, part_id={section_uid}')
    return JsonResponse({
        'section_id': section_uid,
        'sections': parts
    },
                        status=200)
Exemple #3
0
def addsection(section, data, si, program):
    if "type" in data:
        section_type, was_created = SectionType.objects.get_or_create(name=data['type'])
    else:
        section_type = SectionType.objects.get(name="tekst")

    s = Section(name=data['head'], parent=section, type=section_type, order=si, program=program)
    s.save()

    i = 1
    if "body" in data:
         for p in data['body']:
             Paragraph(text=p, section_id=s.id, order=i).save()
             i = i + 1

    si = 1
    if "sub" in data:    
         for subdata in data['sub']:
              addsection(s, subdata, si, program)
              si = si + 1
	def update_sections(self, term):

		sections = self._get_with_session(
			term,
			"searchResults/searchResults?txt_term={term}&pageOffset={offset}&pageMaxSize=500",
			"section(s)"
		)

		self.log(f'[{term}] Updating database')

		for s in sections:

			# We can't use update_or_create() here b/c it calls save() before mandatory fields are set
			crn = s["courseReferenceNumber"]
			try:
				section = Section.objects.get(term=term, crn=crn)
			except Section.DoesNotExist:
				section = Section(term=term, crn=crn)

			try:
				course = Course.objects.get(
					subject__short_title=s["subject"], number=s["courseNumber"]
				)
			except Course.DoesNotExist:
				self.log(f"[crn={crn}] New courses found, please run update courses")
				continue

			section.course = course
			section.section_num = s["sequenceNumber"]
			section.section_title = s["courseTitle"]

			if (credit_hours := s["creditHours"]) is None:
				section.credit_hours = s["creditHourLow"]
			else:
				section.credit_hours = credit_hours

			if faculty := s["faculty"]:
				professor = faculty[0]
				professor_name = professor["displayName"].split(", ")

				section.professor, _ = Professor.objects.update_or_create(
					email=professor["emailAddress"],
					defaults={
						"firstname": professor_name[1],
						"lastname": professor_name[0]
					}
				)
Exemple #5
0
    def generate(self) -> Schedule:
        classes = []

        for C in self.schedule_param.courses:
            assigned_instructors = self._get_assigned_Instructors_for(
                C, )

            for sec_i in range(C.num_of_sections):
                instructor, timeslot, room = self._get_unique_Instr_Timeslot_Room(
                    assigned_instructors, C, classes, )

                section = Section(C, sec_i+1)
                classes.append(Class(section, instructor, room, timeslot))

        return Schedule(classes)
Exemple #6
0
            id=user_id,
            user=user,
            biography=get_field(old_user, "bio", "(no biography)"),
            position=get_field(old_user, "position", "(no position)"),
            graduation_year=2000 + int(get_field(old_user, "gradyear", -2001)))
        profile.save()

if ask_reimport("categories"):
    Section.objects.all().delete()
    categories = read_table("category")

    for old_category in categories:
        parent_id = int(get_field(old_category, "pid"))
        section = Section(id=get_field(old_category, "id"),
                          parent=(Section.objects.get(
                              id=parent_id) if parent_id > 0 else None),
                          name=get_field(old_category, "url_name"),
                          title=get_field(old_category, "name"))
        section.save()

if ask_reimport("pictures"):
    Image.objects.all().delete()

    reimport_files = ask_reimport("image files")

    for old_pic in read_table("picture"):
        try:
            pic_id = get_field(old_pic, "id")
            date = read_date(get_field(old_pic, "date"))
            pic = Image(id=get_field(old_pic, "id"),
                        title=get_field(old_pic, "title", "(no title)"),