def handle(self, *args, **options): term_sis_id = options.get('term-sis-id') if term_sis_id: (year, quarter) = term_sis_id.split('-') term = get_term_by_year_and_quarter(year, quarter) else: term = get_current_active_term() term_sis_id = term.canvas_sis_id() csv_path = UnusedCourseBuilder().build(term_sis_id=term_sis_id) if not settings.SIS_IMPORT_CSV_DEBUG: print(csv_path)
def update_override_dates(self): for term in super(TermManager, self).get_queryset().filter( updated_overrides_date__isnull=True): (year, quarter) = term.term_id.split('-') try: sws_term = get_term_by_year_and_quarter(year, quarter) update_term_overrides(term.term_id, term_date_overrides(sws_term)) term.updated_overrides_date = datetime.utcnow().replace( tzinfo=utc) term.save() except DataFailureException as ex: logger.info('Unable to set term overrides: {}'.format(ex))
def handle(self, *args, **options): term_sis_id = options.get('term-sis-id') if term_sis_id: (year, quarter) = term_sis_id.split('-') target_term = get_term_by_year_and_quarter(year, quarter) else: curr_term = get_current_active_term() if datetime.now().date() < curr_term.census_day: self.update_job() return target_term = get_term_before(get_term_before(curr_term)) term_sis_id = target_term.canvas_sis_id() try: imp = Term.objects.queue_unused_courses(term_sis_id) except EmptyQueueException: self.update_job() return try: imp.csv_path = UnusedCourseBuilder().build(term_sis_id=term_sis_id) except Exception: imp.csv_errors = traceback.format_exc() imp.save() try: imp.import_csv() except MissingImportPathException as ex: if not imp.csv_errors: imp.delete() self.update_job()
def GET(self, request, **kwargs): json_rep = { 'courses': [] } filt_kwargs = None if 'queue_id' in request.GET: queue_id = request.GET.get('queue_id', '').strip() if re.match(r'^[0-9]+$', str(queue_id)): filt_kwargs = {'queue_id': queue_id} else: err = 'invalid queue_id: %s' % queue_id self._log.error(err) return self.json_response('{"error":"%s"}' % err, status=400) else: provisioned_error = request.GET.get('provisioned_error') if provisioned_error: filt_kwargs = { 'provisioned_error': self._is_true(provisioned_error), 'queue_id__isnull': True } if filt_kwargs: try: filt_kwargs['priority__gt'] = PRIORITY_NONE course_list = list(Course.objects.filter( **filt_kwargs).order_by('course_id')) include_sws_url = can_view_source_data() for course in course_list: json_data = course.json_data(include_sws_url) json_rep['courses'].append(json_data) return self.json_response(json.dumps(json_rep)) except Exception as err: self._log.error('course kwargs search fail: %s' + err) return self.json_response('{"error":"%s"}' % err, status=400) net_id = None reg_id = None try: if 'net_id' in request.GET: net_id = netid_from_request(request.GET) elif 'reg_id' in request.GET: reg_id = regid_from_request(request.GET) else: self._criteria[2]['required'] = True filter_terms = self._validCourseFilter(request) filter_prefix = '-'.join(filter_terms) course_list = list(Course.objects.filter( course_id__startswith=filter_prefix).order_by('course_id')) except CourseInvalidException as err: return self.json_response('{"error":"%s"}' % err, status=400) except Exception as err: self._log.error('course filter fail: %s' % err) return self.json_response('{"error":"%s"}' % err, status=400) if (net_id is not None or reg_id is not None) and len(course_list): try: if net_id is not None: instructor = get_person_by_netid(net_id) else: instructor = get_person_by_regid(reg_id) year = request.GET.get('year') quarter = request.GET.get('quarter') term = get_term_by_year_and_quarter(year, quarter) white_list = [] for section in get_sections_by_instructor_and_term( instructor, term): white_list.append('-'.join([ section.term.canvas_sis_id(), section.curriculum_abbr.upper(), section.course_number, section.section_id.upper()])) except Exception as err: self._log.error('section search fail: %s' % err) return self.json_response('{"error":"%s"}' % err, status=400) include_sws_url = can_view_source_data() for course in course_list: if 'white_list' in locals() and course.course_id not in white_list: continue json_data = course.json_data(include_sws_url) json_rep['courses'].append(json_data) return self.json_response(json.dumps(json_rep))
def get(self, request, *args, **kwargs): json_rep = {'courses': []} filt_kwargs = None if 'queue_id' in request.GET: queue_id = request.GET.get('queue_id', '').strip() if re.match(r'^[0-9]+$', str(queue_id)): filt_kwargs = {'queue_id': queue_id} else: err = 'invalid queue_id: {}'.format(queue_id) logger.error(err) return self.error_response(400, err) else: provisioned_error = request.GET.get('provisioned_error') if provisioned_error: filt_kwargs = { 'provisioned_error': self._is_true(provisioned_error), 'queue_id__isnull': True } if filt_kwargs: try: filt_kwargs['priority__gt'] = Course.PRIORITY_NONE course_list = list( Course.objects.filter(**filt_kwargs).order_by('course_id')) include_sws_url = self.can_view_source_data(request) for course in course_list: json_data = course.json_data(include_sws_url) json_rep['courses'].append(json_data) return self.json_response(json_rep) except Exception as err: logger.error('Course search fail: {}'.format(err)) return self.error_response(400, err) net_id = None reg_id = None try: if 'net_id' in request.GET: net_id = self.netid_from_request(request.GET) elif 'reg_id' in request.GET: reg_id = self.regid_from_request(request.GET) else: self._criteria[2]['required'] = True filter_terms = self._valid_course_filter(request) filter_prefix = '-'.join(filter_terms) course_list = list( Course.objects.filter( course_id__startswith=filter_prefix).order_by('course_id')) except CourseInvalidException as err: return self.error_response(400, err) except Exception as err: logger.error('Course filter fail: {}'.format(err)) return self.error_response(400, err) if (net_id is not None or reg_id is not None) and len(course_list): try: if net_id is not None: instructor = get_person_by_netid(net_id) else: instructor = get_person_by_regid(reg_id) year = request.GET.get('year') quarter = request.GET.get('quarter') term = get_term_by_year_and_quarter(year, quarter) valid = [] for section in get_sections_by_instructor_and_term( instructor, term): valid.append('-'.join([ section.term.canvas_sis_id(), section.curriculum_abbr.upper(), section.course_number, section.section_id.upper() ])) except Exception as err: logger.error('Section search fail: {}'.format(err)) return self.error_response(400, err) include_sws_url = self.can_view_source_data(request) for course in course_list: if 'valid' in locals() and course.course_id not in valid: continue json_data = course.json_data(include_sws_url) json_rep['courses'].append(json_data) return self.json_response(json_rep)
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 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)