def process_events(self, event): self._previous_instructors = self._instructors_from_section_json( event['Previous']) self._current_instructors = self._instructors_from_section_json( event['Current']) self._last_modified = date_parse(event['EventDate']) section_data = event['Current'] if not section_data: section_data = event['Previous'] course_data = section_data['Course'] try: term = get_term_by_year_and_quarter( section_data['Term']['Year'], section_data['Term']['Quarter']) active_terms = get_all_active_terms(datetime.now()) except DataFailureException as err: self._log.info('%s ERROR get term: %s' % (log_prefix, err)) return if term not in active_terms: self._log.info( '%s IGNORE inactive section %s-%s-%s-%s' % ( log_prefix, term.canvas_sis_id(), course_data['CurriculumAbbreviation'], course_data['CourseNumber'], section_data['SectionID'])) return section = Section( term=term, course_campus=section_data['CourseCampus'], curriculum_abbr=course_data['CurriculumAbbreviation'], course_number=course_data['CourseNumber'], section_id=section_data['SectionID'], is_independent_study=section_data['IndependentStudy']) if is_time_schedule_construction(section): self._log_tsc_ignore(section.canvas_section_sis_id()) return sections = [] primary_section = section_data["PrimarySection"] if (primary_section is not None and primary_section["SectionID"] != section.section_id): section.is_primary_section = False self._set_primary_section(section, primary_section) sections.append(section) else: if len(section_data["LinkedSectionTypes"]): for linked_section_type in section_data["LinkedSectionTypes"]: for linked_section_data in \ linked_section_type["LinkedSections"]: lsd_data = linked_section_data['Section'] section = Section( term=term, curriculum_abbr=lsd_data['CurriculumAbbreviation'], course_number=lsd_data['CourseNumber'], section_id=lsd_data['SectionID'], is_primary_section=False, is_independent_study=section_data[ 'IndependentStudy']) self._set_primary_section(section, primary_section) sections.append(section) else: section.is_primary_section = True sections.append(section) for section in sections: self.load_instructors(section)
def add_all_courses_for_term(self, term): term_id = term.canvas_sis_id() existing_course_ids = dict((c, p) for c, p in ( super(CourseManager, self).get_queryset().filter( term_id=term_id, course_type=Course.SDB_TYPE ).values_list('course_id', 'priority'))) last_search_date = datetime.utcnow().replace(tzinfo=utc) try: delta = Term.objects.get(term_id=term_id) except Term.DoesNotExist: delta = Term(term_id=term_id) if delta.last_course_search_date is None: delta.courses_changed_since_date = datetime.fromtimestamp(0, utc) else: delta.courses_changed_since_date = delta.last_course_search_date new_courses = [] for section_ref in get_sections_by_term( localtime(delta.courses_changed_since_date).date(), term): course_id = '-'.join([section_ref.term.canvas_sis_id(), section_ref.curriculum_abbr.upper(), section_ref.course_number, section_ref.section_id.upper()]) if course_id in existing_course_ids: if existing_course_ids[course_id] == PRIORITY_NONE: super(CourseManager, self).get_queryset().filter( course_id=course_id).update(priority=PRIORITY_HIGH) continue try: label = section_ref.section_label() section = get_section_by_label(label) if is_time_schedule_construction(section): logger.info('Course: SKIP %s, TSC on' % label) continue except DataFailureException as err: logger.info('Course: SKIP %s, %s' % (label, err)) continue except ValueError as err: logger.info('Course: SKIP, %s' % err) continue primary_id = None if section.is_independent_study: for instructor in section.get_instructors(): ind_course_id = '-'.join([course_id, instructor.uwregid]) if ind_course_id not in existing_course_ids: course = Course(course_id=ind_course_id, course_type=Course.SDB_TYPE, term_id=term_id, primary_id=primary_id, priority=PRIORITY_HIGH) new_courses.append(course) else: if not section.is_primary_section: primary_id = section.canvas_course_sis_id() course = Course(course_id=course_id, course_type=Course.SDB_TYPE, term_id=term_id, primary_id=primary_id, priority=PRIORITY_HIGH) new_courses.append(course) Course.objects.bulk_create(new_courses) delta.last_course_search_date = last_search_date delta.save()
def process_message_body(self, json_data): self._previous_instructors = self._instructors_from_section_json( json_data['Previous']) self._current_instructors = self._instructors_from_section_json( json_data['Current']) self._last_modified = date_parse(json_data['EventDate']) section_data = json_data['Current'] if not section_data: section_data = json_data['Previous'] course_data = section_data['Course'] try: term = get_term_by_year_and_quarter( section_data['Term']['Year'], section_data['Term']['Quarter']) except DataFailureException as err: self.logger.info('{} ERROR get term: {}'.format(log_prefix, err)) return if not is_active_term(term): self.logger.info('{} IGNORE Inactive section {}-{}-{}-{}'.format( log_prefix, term.canvas_sis_id(), course_data['CurriculumAbbreviation'], course_data['CourseNumber'], section_data['SectionID'])) return section = Section( term=term, course_campus=section_data['CourseCampus'], curriculum_abbr=course_data['CurriculumAbbreviation'], course_number=course_data['CourseNumber'], section_id=section_data['SectionID'], is_independent_study=section_data['IndependentStudy']) if is_time_schedule_construction(section): self._log_tsc_ignore(section.canvas_section_sis_id()) return sections = [] primary_section = section_data["PrimarySection"] if (primary_section is not None and primary_section["SectionID"] != section.section_id): section.is_primary_section = False self._set_primary_section(section, primary_section) sections.append(section) else: if len(section_data["LinkedSectionTypes"]): for linked_section_type in section_data["LinkedSectionTypes"]: for linked_section_data in ( linked_section_type["LinkedSections"]): lsd_data = linked_section_data['Section'] section = Section( term=term, curriculum_abbr=lsd_data['CurriculumAbbreviation'], course_number=lsd_data['CourseNumber'], section_id=lsd_data['SectionID'], is_primary_section=False, is_independent_study=section_data[ 'IndependentStudy']) self._set_primary_section(section, primary_section) sections.append(section) else: section.is_primary_section = True sections.append(section) for section in sections: self.load_instructors(section)