コード例 #1
0
    def test_get_evaluations_by_section(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
                           RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS,
                           RESTCLIENTS_IASYSTEM_DAO_CLASS=FDAO_IAS):

            regid = "9136CCB8F66711D5BE060004AC494FFE"
            term = Term()
            term.year = 2013
            term.quarter = "summer"
            section = Section()
            section.summer_term = "A-term"
            section.term = term
            schedule = _get_schedule(regid, term)
            evals = None
            for section in schedule.sections:
                if section.curriculum_abbr == 'ELCBUS':
                    evals = _get_evaluations_by_section_and_student(
                        section, 1443336)
                    break
            self.assertIsNotNone(evals)
            self.assertEqual(evals[0].section_sln, 13833)
            self.assertEqual(
                evals[0].eval_open_date,
                datetime.datetime(2013, 7, 02, 14, 0, tzinfo=pytz.utc))
            self.assertEqual(
コード例 #2
0
ファイル: iasystem.py プロジェクト: mattventura/myuw
    def test_get_evaluations_by_section(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
                           RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS,
                           RESTCLIENTS_IASYSTEM_DAO_CLASS=FDAO_IAS):

            regid = "9136CCB8F66711D5BE060004AC494FFE"
            term = Term()
            term.year = 2013
            term.quarter = "summer"
            section = Section()
            section.summer_term = "A-term"
            section.term = term
            schedule = _get_schedule(regid, term)
            evals = None
            for section in schedule.sections:
                if section.curriculum_abbr == 'ELCBUS':
                    evals = _get_evaluations_by_section_and_student(section,
                                                                    1443336)
                    break
            self.assertIsNotNone(evals)
            self.assertEqual(evals[0].section_sln, 13833)
            self.assertEqual(evals[0].eval_open_date,
                             datetime.datetime(2013, 7, 02,
                                               14, 0,
                                               tzinfo=pytz.utc))
            self.assertEqual(evals[0].eval_close_date,
コード例 #3
0
ファイル: iasystem.py プロジェクト: mattventura/myuw
    def test_summer_term_overlaped(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS):
            term = Term()
            term.year = 2013
            term.quarter = "summer"
            section = Section()
            section.summer_term = "A-term"
            section.term = term

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-07-10"
            self.assertTrue(summer_term_overlaped(now_request, section))
            section.summer_term = "Full-term"
            self.assertFalse(summer_term_overlaped(now_request, section))
            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-08-10"
            self.assertTrue(summer_term_overlaped(now_request, section))

            section.summer_term = "B-term"
            self.assertTrue(summer_term_overlaped(now_request, section))

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-10"
            self.assertTrue(summer_term_overlaped(now_request, 'None'))
            self.assertTrue(summer_term_overlaped(now_request, '-'))
コード例 #4
0
    def test_by_campus(self):
        time_schedule_constructions = [
            TimeScheduleConstruction(campus="Seattle", is_on=False),
            TimeScheduleConstruction(campus="Tacoma", is_on=False),
            TimeScheduleConstruction(campus="Bothell", is_on=True),
        ]
        term = Term(year=2013, quarter="summer")
        term.time_schedule_construction = time_schedule_constructions
        section = Section(term=term)

        for campus in ["Seattle", "Tacoma", "Bothell", "PCE", ""]:
            section.course_campus = campus
            self.assertEquals(
                is_time_schedule_construction(section),
                True if campus == "Bothell" else False,
                "Campus: %s" % section.course_campus,
            )
コード例 #5
0
    def test_summer_term_overlaped(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS):
            term = Term()
            term.year = 2013
            term.quarter = "summer"
            section = Section()
            section.summer_term = "A-term"
            section.term = term

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-07-10"
            self.assertTrue(summer_term_overlaped(now_request, section))
            section.summer_term = "Full-term"
            self.assertFalse(summer_term_overlaped(now_request, section))
            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-08-10"
            self.assertTrue(summer_term_overlaped(now_request, section))

            section.summer_term = "B-term"
            self.assertTrue(summer_term_overlaped(now_request, section))

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-10"
            self.assertTrue(summer_term_overlaped(now_request, 'None'))
            self.assertTrue(summer_term_overlaped(now_request, '-'))
コード例 #6
0
ファイル: client.py プロジェクト: uw-it-aca/canvas-eos-import
    def _eos_section(self):
        section = Section()
        section.is_primary_section = True
        section.is_independent_study = False
        section.linked_section_urls = []
        section.joint_section_urls = []

        section_meeting = SectionMeeting()
        section_meeting.instructors = []
        section.meetings = [section_meeting]

        return section
コード例 #7
0
def _json_to_section(section_data,
                     term=None,
                     include_instructor_not_on_time_schedule=True):
    """
    Returns a section model created from the passed json.
    """
    pws = PWS()
    section = Section()

    if term is not None and (term.year == int(section_data["Course"]["Year"])
                             and term.quarter
                             == section_data["Course"]["Quarter"]):
        section.term = term
    else:
        section.term = get_term_by_year_and_quarter(
            section_data["Course"]["Year"], section_data["Course"]["Quarter"])

    section.curriculum_abbr = section_data["Course"]["CurriculumAbbreviation"]
    section.course_number = section_data["Course"]["CourseNumber"]
    section.course_title = section_data["CourseTitle"]
    section.course_title_long = section_data["CourseTitleLong"]
    section.course_campus = section_data["CourseCampus"]
    section.section_id = section_data["SectionID"]
    section.institute_name = section_data.get("InstituteName", "")
    section.primary_lms = section_data.get("PrimaryLMS", None)
    section.lms_ownership = section_data.get("LMSOwnership", None)
    section.is_independent_start = section_data.get("IsIndependentStart",
                                                    False)

    section.section_type = section_data["SectionType"]
    if "independent study" == section.section_type:
        section.is_independent_study = True
    else:
        section.is_independent_study = False

    section.class_website_url = section_data["ClassWebsiteUrl"]
    section.sln = section_data["SLN"]
    if "SummerTerm" in section_data:
        section.summer_term = section_data["SummerTerm"]
    else:
        section.summer_term = ""

    section.delete_flag = section_data["DeleteFlag"]
    if "withdrawn" == section.delete_flag:
        section.is_withdrawn = True
    else:
        section.is_withdrawn = False

    section.current_enrollment = int(section_data['CurrentEnrollment'])
    section.auditors = int(section_data['Auditors'])
    section.allows_secondary_grading = section_data["SecondaryGradingOption"]

    primary_section = section_data["PrimarySection"]
    if (primary_section is not None
            and primary_section["SectionID"] != section.section_id):
        section.is_primary_section = False
        section.primary_section_href = primary_section["Href"]
        section.primary_section_id = primary_section["SectionID"]
        section.primary_section_curriculum_abbr = primary_section[
            "CurriculumAbbreviation"]
        section.primary_section_course_number = primary_section["CourseNumber"]
    else:
        section.is_primary_section = True

    section.linked_section_urls = []
    for linked_section_type in section_data["LinkedSectionTypes"]:
        for linked_section_data in linked_section_type["LinkedSections"]:
            url = linked_section_data["Section"]["Href"]
            section.linked_section_urls.append(url)

    section.joint_section_urls = []
    for joint_section_data in section_data.get("JointSections", []):
        url = joint_section_data["Href"]
        section.joint_section_urls.append(url)

    section.grade_submission_delegates = []
    for del_data in section_data["GradeSubmissionDelegates"]:
        delegate = GradeSubmissionDelegate(
            person=pws.get_person_by_regid(del_data["Person"]["RegID"]),
            delegate_level=del_data["DelegateLevel"])
        section.grade_submission_delegates.append(delegate)

    section.meetings = []
    for meeting_data in section_data["Meetings"]:
        meeting = SectionMeeting()
        meeting.section = section
        meeting.term = section.term
        meeting.meeting_index = meeting_data["MeetingIndex"]
        meeting.meeting_type = meeting_data["MeetingType"]

        meeting.building = meeting_data["Building"]
        if meeting_data["BuildingToBeArranged"]:
            meeting.building_to_be_arranged = True
        else:
            meeting.building_to_be_arranged = False

        meeting.room_number = meeting_data["RoomNumber"]
        if meeting_data["RoomToBeArranged"]:
            meeting.room_to_be_arranged = True
        else:
            meeting.room_to_be_arranged = False

        if meeting_data["DaysOfWeekToBeArranged"]:
            meeting.days_to_be_arranged = True
        else:
            meeting.days_to_be_arranged = False

        for day_data in meeting_data["DaysOfWeek"]["Days"]:
            attribute = "meets_%s" % day_data["Name"].lower()
            setattr(meeting, attribute, True)

        meeting.start_time = meeting_data["StartTime"]
        meeting.end_time = meeting_data["EndTime"]

        meeting.instructors = []
        for instructor_data in meeting_data["Instructors"]:
            # TSPrint: True
            # Instructor information currently listed on the Time Schedule
            if instructor_data[
                    "TSPrint"] or include_instructor_not_on_time_schedule:
                pdata = instructor_data["Person"]

                if "RegID" in pdata and pdata["RegID"] is not None:
                    try:
                        instructor = pws.get_person_by_regid(pdata["RegID"])
                    except:
                        instructor = Person(uwregid=pdata["RegID"],
                                            display_name=pdata["Name"])
                    instructor.TSPrint = instructor_data["TSPrint"]
                    meeting.instructors.append(instructor)

        section.meetings.append(meeting)

    section.final_exam = None
    if "FinalExam" in section_data and section_data["FinalExam"] is not None:
        if "MeetingStatus" in section_data["FinalExam"]:
            final_exam = FinalExam()
            final_data = section_data["FinalExam"]
            status = final_data["MeetingStatus"]
            final_exam.no_exam_or_nontraditional = False
            final_exam.is_confirmed = False
            if (status == "2") or (status == "3"):
                final_exam.is_confirmed = True
            elif status == "1":
                final_exam.no_exam_or_nontraditional = True

            final_exam.building = final_data["Building"]
            final_exam.room_number = final_data["RoomNumber"]

            final_format = "%Y-%m-%d : %H:%M"

            strptime = datetime.strptime
            if final_data["Date"] and final_data["Date"] != "0000-00-00":
                if final_data["StartTime"]:
                    start_string = "%s : %s" % (final_data["Date"],
                                                final_data["StartTime"])
                    final_exam.start_date = strptime(start_string,
                                                     final_format)

                if final_data["EndTime"]:
                    end_string = "%s : %s" % (final_data["Date"],
                                              final_data["EndTime"])
                    final_exam.end_date = strptime(end_string, final_format)

            final_exam.clean_fields()
            section.final_exam = final_exam

    return section
コード例 #8
0
    def process_events(self, events):
        enrollments = []
        for event in events['Events']:
            section_data = event['Section']
            course_data = section_data['Course']

            section = Section()
            section.term = Term(quarter=course_data['Quarter'],
                                year=course_data['Year'])
            section.curriculum_abbr = course_data['CurriculumAbbreviation']
            section.course_number = course_data['CourseNumber']
            section.section_id = section_data['SectionID']
            section.is_primary_section = True
            section.linked_section_urls = []

            if ('PrimarySection' in event and
                    'Course' in event['PrimarySection']):
                primary_course = event['PrimarySection']['Course']
                if primary_course:
                    section.is_primary_section = False
                    section.primary_section_curriculum_abbr = \
                        primary_course['CurriculumAbbreviation']
                    section.primary_section_course_number = \
                        primary_course['CourseNumber']
                    section.primary_section_id = \
                        event['PrimarySection']['SectionID']

            try:
                data = {
                    'Section': section,
                    'Role': EnrollmentModel.STUDENT_ROLE,
                    'UWRegID': event['Person']['UWRegID'],
                    'Status': self._enrollment_status(event, section),
                    'LastModified': date_parse(event['LastModified']),
                    'InstructorUWRegID': event['Instructor']['UWRegID'] if (
                        'Instructor' in event and event['Instructor'] and
                        'UWRegID' in event['Instructor']) else None
                }

                if 'Auditor' in event and event['Auditor']:
                    data['Role'] = EnrollmentModel.AUDITOR_ROLE

                if 'RequestDate' in event:
                    data['RequestDate'] = date_parse(event['RequestDate'])

                enrollments.append(data)
            except UnhandledActionCodeException:
                self._log.warning("%s UNKNOWN %s for %s at %s" % (
                    log_prefix,
                    event['Action']['Code'],
                    event['Person']['UWRegID'],
                    event['LastModified']))
                pass

        self.load_enrollments(enrollments)
コード例 #9
0
    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)
コード例 #10
0
ファイル: section.py プロジェクト: uw-it-cte/uw-restclients
def _json_to_section(section_data,
                     term=None,
                     include_instructor_not_on_time_schedule=True):
    """
    Returns a section model created from the passed json.
    """
    pws = PWS()
    section = Section()

    if term is not None and (
            term.year == int(section_data["Course"]["Year"]) and
            term.quarter == section_data["Course"]["Quarter"]):
        section.term = term
    else:
        section.term = get_term_by_year_and_quarter(
            section_data["Course"]["Year"],
            section_data["Course"]["Quarter"])

    section.curriculum_abbr = section_data["Course"][
        "CurriculumAbbreviation"]
    section.course_number = section_data["Course"]["CourseNumber"]
    section.course_title = section_data["CourseTitle"]
    section.course_title_long = section_data["CourseTitleLong"]
    section.course_campus = section_data["CourseCampus"]
    section.section_id = section_data["SectionID"]
    section.institute_name = section_data.get("InstituteName", "")
    section.primary_lms = section_data.get("PrimaryLMS", None)
    section.lms_ownership = section_data.get("LMSOwnership", None)
    section.is_independent_start = section_data.get("IsIndependentStart",
                                                    False)

    # Some section data sources have different formats for these dates.
    try:
        date_format = "%Y-%m-%d"
        if section_data.get("StartDate", None):
            str_date = section_data["StartDate"]
            start_date = datetime.strptime(str_date, date_format).date()
            section.start_date = start_date

        if section_data.get("EndDate", None):
            str_date = section_data["EndDate"]
            section.end_date = datetime.strptime(str_date, date_format).date()
    except Exception as ex:
        pass

    section.section_type = section_data["SectionType"]
    if "independent study" == section.section_type:
        section.is_independent_study = True
    else:
        section.is_independent_study = False

    section.class_website_url = section_data["ClassWebsiteUrl"]
    section.sln = section_data["SLN"]
    if "SummerTerm" in section_data:
        section.summer_term = section_data["SummerTerm"]
    else:
        section.summer_term = ""

    section.delete_flag = section_data["DeleteFlag"]
    if "withdrawn" == section.delete_flag:
        section.is_withdrawn = True
    else:
        section.is_withdrawn = False

    section.current_enrollment = int(section_data['CurrentEnrollment'])
    section.auditors = int(section_data['Auditors'])
    section.allows_secondary_grading = section_data["SecondaryGradingOption"]

    primary_section = section_data["PrimarySection"]
    if (primary_section is not None and
            primary_section["SectionID"] != section.section_id):
        section.is_primary_section = False
        section.primary_section_href = primary_section["Href"]
        section.primary_section_id = primary_section["SectionID"]
        section.primary_section_curriculum_abbr = primary_section[
            "CurriculumAbbreviation"]
        section.primary_section_course_number = primary_section[
            "CourseNumber"]
    else:
        section.is_primary_section = True

    section.linked_section_urls = []
    for linked_section_type in section_data["LinkedSectionTypes"]:
        for linked_section_data in linked_section_type["LinkedSections"]:
            url = linked_section_data["Section"]["Href"]
            section.linked_section_urls.append(url)

    section.joint_section_urls = []
    for joint_section_data in section_data.get("JointSections", []):
        url = joint_section_data["Href"]
        section.joint_section_urls.append(url)

    section.grade_submission_delegates = []
    for del_data in section_data["GradeSubmissionDelegates"]:
        delegate = GradeSubmissionDelegate(
            person=pws.get_person_by_regid(del_data["Person"]["RegID"]),
            delegate_level=del_data["DelegateLevel"])
        section.grade_submission_delegates.append(delegate)

    section.meetings = []
    for meeting_data in section_data["Meetings"]:
        meeting = SectionMeeting()
        meeting.section = section
        meeting.term = section.term
        meeting.meeting_index = meeting_data["MeetingIndex"]
        meeting.meeting_type = meeting_data["MeetingType"]

        meeting.building = meeting_data["Building"]
        if meeting_data["BuildingToBeArranged"]:
            meeting.building_to_be_arranged = True
        else:
            meeting.building_to_be_arranged = False

        meeting.room_number = meeting_data["RoomNumber"]
        if meeting_data["RoomToBeArranged"]:
            meeting.room_to_be_arranged = True
        else:
            meeting.room_to_be_arranged = False

        if meeting_data["DaysOfWeekToBeArranged"]:
            meeting.days_to_be_arranged = True
        else:
            meeting.days_to_be_arranged = False

        for day_data in meeting_data["DaysOfWeek"]["Days"]:
            attribute = "meets_%s" % day_data["Name"].lower()
            setattr(meeting, attribute, True)

        meeting.start_time = meeting_data["StartTime"]
        meeting.end_time = meeting_data["EndTime"]

        meeting.instructors = []
        for instructor_data in meeting_data["Instructors"]:
            # TSPrint: True
            # Instructor information currently listed on the Time Schedule
            if (instructor_data["TSPrint"] or
                    include_instructor_not_on_time_schedule):
                pdata = instructor_data["Person"]

                if "RegID" in pdata and pdata["RegID"] is not None:
                    try:
                        instructor = pws.get_person_by_regid(pdata["RegID"])
                    except:
                        instructor = Person(uwregid=pdata["RegID"],
                                            display_name=pdata["Name"])
                    instructor.TSPrint = instructor_data["TSPrint"]
                    meeting.instructors.append(instructor)

        section.meetings.append(meeting)

    section.final_exam = None
    if "FinalExam" in section_data and section_data["FinalExam"] is not None:
        if "MeetingStatus" in section_data["FinalExam"]:
            final_exam = FinalExam()
            final_data = section_data["FinalExam"]
            status = final_data["MeetingStatus"]
            final_exam.no_exam_or_nontraditional = False
            final_exam.is_confirmed = False
            if (status == "2") or (status == "3"):
                final_exam.is_confirmed = True
            elif status == "1":
                final_exam.no_exam_or_nontraditional = True

            final_exam.building = final_data["Building"]
            final_exam.room_number = final_data["RoomNumber"]

            final_format = "%Y-%m-%d : %H:%M"

            strptime = datetime.strptime
            if final_data["Date"] and final_data["Date"] != "0000-00-00":
                if final_data["StartTime"]:
                    start_string = "%s : %s" % (final_data["Date"],
                                                final_data["StartTime"])
                    final_exam.start_date = strptime(start_string,
                                                     final_format)

                if final_data["EndTime"]:
                    end_string = "%s : %s" % (final_data["Date"],
                                              final_data["EndTime"])
                    final_exam.end_date = strptime(end_string, final_format)

            final_exam.clean_fields()
            section.final_exam = final_exam

    return section