Exemple #1
0
def get_next_term():
    """
    Returns a restclients.models.sws.Term object,
    for the next term.
    """
    url = "%s/next.json" % term_res_url_prefix
    return _json_to_term_model(get_resource(url))
Exemple #2
0
def get_previous_term():
    """
    Returns a restclients.models.sws.Term object,
    for the previous term.
    """
    url = "%s/previous.json" % term_res_url_prefix
    return _json_to_term_model(get_resource(url))
def _registrations_for_section_with_active_flag(section, is_active,
                                                transcriptable_course=""):
    """
    Returns a list of all restclients.models.sws.Registration objects
    for a section. There can be duplicates for a person.
    If is_active is True, the objects will have is_active set to True.
    Otherwise, is_active is undefined, and out of scope for this method.
    """
    instructor_reg_id = ""
    if (section.is_independent_study and
            section.independent_study_instructor_regid is not None):
        instructor_reg_id = section.independent_study_instructor_regid

    params = {
        "year": section.term.year,
        "quarter": section.term.quarter,
        "curriculum_abbreviation": section.curriculum_abbr,
        "course_number": section.course_number,
        "section_id": section.section_id,
        "instructor_reg_id": instructor_reg_id,
        "is_active": "true" if is_active else "",
        "verbose": "true"
    }

    if transcriptable_course != "":
        params["transcriptable_course"] = transcriptable_course

    url = "%s?%s" % (registration_res_url_prefix, urlencode(params))

    return _json_to_registrations(get_resource(url), section)
def get_grades_by_regid_and_term(regid, term):
    """
    Returns a StudentGrades model for the regid and term.
    """
    url = "%s/%s,%s,%s.json" % (enrollment_res_url_prefix, term.year,
                                term.quarter, regid)
    return _json_to_grades(get_resource(url), regid, term)
Exemple #5
0
def get_term_by_year_and_quarter(year, quarter):
    """
    Returns a restclients.models.sws.Term object,
    for the passed year and quarter.
    """
    url = "%s/%s,%s.json" % (term_res_url_prefix, str(year), quarter.lower())
    return _json_to_term_model(get_resource(url))
def _registrations_for_section_with_active_flag(section, is_active):
    """
    Returns a list of all restclients.models.sws.Registration objects
    for a section. There can be duplicates for a person.
    If is_active is True, the objects will have is_active set to True.
    Otherwise, is_active is undefined, and out of scope for this method.
    """
    instructor_reg_id = ''
    if (section.is_independent_study
            and section.independent_study_instructor_regid is not None):
        instructor_reg_id = section.independent_study_instructor_regid

    activity_flag = ""
    if is_active:
        activity_flag = "true"

    url = "%s?%s" % (registration_res_url_prefix,
                     urlencode({
                         "year": section.term.year,
                         "quarter": section.term.quarter,
                         "curriculum_abbreviation": section.curriculum_abbr,
                         "course_number": section.course_number,
                         "section_id": section.section_id,
                         "instructor_reg_id": instructor_reg_id,
                         "is_active": activity_flag
                     }))

    return _json_to_registrations(get_resource(url), section, is_active)
Exemple #7
0
def get_next_term():
    """
    Returns a restclients.models.sws.Term object,
    for the next term.
    """
    url = "%s/next.json" % term_res_url_prefix
    return _json_to_term_model(get_resource(url))
Exemple #8
0
def get_previous_term():
    """
    Returns a restclients.models.sws.Term object,
    for the previous term.
    """
    url = "%s/previous.json" % term_res_url_prefix
    return _json_to_term_model(get_resource(url))
Exemple #9
0
def get_term_by_year_and_quarter(year, quarter):
    """
    Returns a restclients.models.sws.Term object,
    for the passed year and quarter.
    """
    url = "%s/%s,%s.json" % (term_res_url_prefix, str(year), quarter.lower())
    return _json_to_term_model(get_resource(url))
Exemple #10
0
def get_notices_by_regid(regid):
    """
    Returns a list of restclients.models.sws.Notice objects
    for the passed regid.
    """
    url = notice_res_url_prefix + regid + ".json"

    return _notices_from_json(get_resource(url))
Exemple #11
0
def get_notices_by_regid(regid):
    """
    Returns a list of restclients.models.sws.Notice objects
    for the passed regid.
    """
    url = notice_res_url_prefix + regid + ".json"

    return _notices_from_json(get_resource(url))
Exemple #12
0
def get_departments_by_college(college):
    """
    Returns a list of restclients.Department models, for the passed
    College model.
    """
    url = "%s?%s" % (dept_search_url_prefix,
                     urlencode({"college_abbreviation": college.label}))
    return _json_to_departments(get_resource(url), college)
def get_grades_by_regid_and_term(regid, term):
    """
    Returns a StudentGrades model for the regid and term.
    """
    url = "%s/%s,%s,%s.json" % (enrollment_res_url_prefix,
                                term.year,
                                term.quarter,
                                regid)
    return _json_to_grades(get_resource(url), regid, term)
def get_departments_by_college(college):
    """
    Returns a list of restclients.Department models, for the passed
    College model.
    """
    url = "%s?%s" % (
        dept_search_url_prefix,
        urlencode({"college_abbreviation": college.label}))
    return _json_to_departments(get_resource(url), college)
Exemple #15
0
def get_sections_by_curriculum_and_term(curriculum, term):
    """
    Returns a list of restclients.models.sws.SectionReference objects
    for the passed curriculum and term.
    """
    url = "%s?%s" % (section_res_url_prefix,
                     urlencode({"year": term.year,
                                "quarter": term.quarter.lower(),
                                "curriculum_abbreviation": curriculum.label}))
    return _json_to_sectionref(get_resource(url), term)
Exemple #16
0
def get_curricula_by_term(term):
    """
    Returns a list of restclients.Curriculum models, for the passed
    Term model.
    """
    url = "%s?%s" % (
        curriculum_search_url_prefix,
        urlencode({"year": term.year,
                   "quarter": term.quarter.lower()}))
    return _json_to_curricula(get_resource(url))
def get_credits_by_reg_url(url):
    """
    Returns a decimal value of the course credits
    """
    reg_data = get_resource(url)

    try:
        return Decimal(reg_data['Credits'].strip())
    except InvalidOperation:
        pass
def get_credits_by_reg_url(url):
    """
    Returns a decimal value of the course credits
    """
    reg_data = get_resource(url)

    try:
        return Decimal(reg_data['Credits'].strip())
    except InvalidOperation:
        pass
def get_section_status_by_label(label):
    if not section_label_pattern.match(label):
        raise InvalidSectionID(label)

    url = "%s/%s/status.json" % (course_res_url_prefix,
                                 encode_section_label(label))

    return _json_to_sectionstatus(get_resource(url))

    pass
Exemple #20
0
def get_section_by_url(url, include_instructor_not_on_time_schedule=True):
    """
    Returns a restclients.models.sws.Section object
    for the passed section url.
    """
    if not course_url_pattern.match(url):
        raise InvalidSectionURL(url)

    return _json_to_section(get_resource(url),
                            include_instructor_not_on_time_schedule=
                            include_instructor_not_on_time_schedule)
Exemple #21
0
def get_sections_by_curriculum_and_term(curriculum, term):
    """
    Returns a list of restclients.models.sws.SectionReference objects
    for the passed curriculum and term.
    """
    url = "%s?%s" % (section_res_url_prefix,
                     urlencode({
                         "year": term.year,
                         "quarter": term.quarter.lower(),
                         "curriculum_abbreviation": curriculum.label
                     }))
    return _json_to_sectionref(get_resource(url), term)
def get_section_by_url(url,
                       include_instructor_not_on_time_schedule=True):
    """
    Returns a restclients.models.sws.Section object
    for the passed section url.
    """
    if not course_url_pattern.match(url):
        raise InvalidSectionURL(url)

    return _json_to_section(
        get_resource(url),
        include_instructor_not_on_time_schedule=include_instructor_not_on_time_schedule)
def get_section_status_by_label(label):
    import warnings
    warnings.warn("Totally untested against live resources!  Don't count on get_section_status_by_label in v5!")

    if not section_label_pattern.match(label):
        raise InvalidSectionID(label)

    url = "%s/%s/status.json" % (course_res_url_prefix,
                                 encode_section_label(label))

    return _json_to_sectionstatus(get_resource(url))

    pass
Exemple #24
0
def get_curricula_by_department(department, future_terms=0):
    """
    Returns a list of restclients.Curriculum models, for the passed
    Department model.
    """
    if future_terms < 0 or future_terms > 2:
        raise ValueError(future_terms)

    url = "%s?%s" % (
        curriculum_search_url_prefix,
        urlencode({"department_abbreviation": department.label,
                   "future_terms": future_terms}))
    return _json_to_curricula(get_resource(url))
def get_schedule_by_regid_and_term(regid,
                                   term,
                                   include_instructor_not_on_time_schedule=True
                                   ):
    """
    Returns a restclients.models.sws.ClassSchedule object
    for the regid and term passed in.
    """
    url = "%s?%s" % (registration_res_url_prefix,
                     urlencode([('reg_id', regid), ('quarter', term.quarter),
                                ('is_active', 'true'), ('year', term.year)]))

    return _json_to_schedule(get_resource(url), term, regid,
                             include_instructor_not_on_time_schedule)
def _add_credits_grade_to_section(url, section):
    """
    Given the registration url passed in,
    add credits, grade, grade date in the section object
    """
    section_reg_data = get_resource(url)
    if section_reg_data is not None:
        section.student_grade = section_reg_data['Grade']
        section.is_auditor = section_reg_data['Auditor']
        if len(section_reg_data['GradeDate']) > 0:
            section.grade_date = parse_sws_date(section_reg_data['GradeDate']).date()
        try:
            section.student_credits = Decimal(section_reg_data['Credits'].strip())
        except InvalidOperation:
            pass
Exemple #27
0
def get_current_term():
    """
    Returns a restclients.models.sws.Term object,
    for the current term.
    """
    url = "%s/current.json" % term_res_url_prefix
    term = _json_to_term_model(get_resource(url))

    # A term doesn't become "current" until 2 days before the start of
    # classes.  That's too late to be useful, so if we're after the last
    # day of grade submission window, use the next term resource.
    if datetime.now() > term.grade_submission_deadline:
        return get_next_term()

    return term
def get_section_status_by_label(label):
    import warnings
    warnings.warn(
        "Totally untested against live resources!  Don't count on get_section_status_by_label in v5!"
    )

    if not section_label_pattern.match(label):
        raise InvalidSectionID(label)

    url = "%s/%s/status.json" % (course_res_url_prefix,
                                 encode_section_label(label))

    return _json_to_sectionstatus(get_resource(url))

    pass
Exemple #29
0
def get_current_term():
    """
    Returns a restclients.models.sws.Term object,
    for the current term.
    """
    url = "%s/current.json" % term_res_url_prefix
    term = _json_to_term_model(get_resource(url))

    # A term doesn't become "current" until 2 days before the start of
    # classes.  That's too late to be useful, so if we're after the last
    # day of grade submission window, use the next term resource.
    if datetime.now() > term.grade_submission_deadline:
        return get_next_term()

    return term
def get_schedule_by_regid_and_term(regid, term,
                                   include_instructor_not_on_time_schedule=True):
    """
    Returns a restclients.models.sws.ClassSchedule object
    for the regid and term passed in.
    """
    url = "%s?%s" % (
        registration_res_url_prefix,
        urlencode([('reg_id', regid),
                   ('quarter', term.quarter),
                   ('is_active', 'true'),
                   ('year', term.year)
                   ]))

    return _json_to_schedule(get_resource(url), term, regid,
                             include_instructor_not_on_time_schedule)
Exemple #31
0
def _get_sections_by_person_and_term(person, term, course_role,
                                     include_secondaries="on"):
    """
    Returns a list of restclients.models.sws.SectionReference object
    for the passed course_role and term (including secondaries).
    """
    url = "%s?%s" % (
        section_res_url_prefix,
        urlencode({"year": term.year,
                   "quarter": term.quarter.lower(),
                   "reg_id": person.uwregid,
                   "search_by": course_role,
                   "include_secondaries": include_secondaries
                   }))

    return _json_to_sectionref(get_resource(url), term)
Exemple #32
0
def get_changed_sections_by_term(changed_since_date, term, **kwargs):
    kwargs.update({"year": term.year,
                   "quarter": term.quarter.lower(),
                   "changed_since_date": changed_since_date,
                   "page_size": 1000})
    url = "%s?%s" % (section_res_url_prefix, urlencode(kwargs))

    sections = []
    while url is not None:
        data = get_resource(url)
        sections.extend(_json_to_sectionref(data, term))

        url = None
        if data.get("Next") is not None:
            url = data.get("Next").get("Href", None)

    return sections
def _add_credits_grade_to_section(url, section):
    """
    Given the registration url passed in,
    add credits, grade, grade date in the section object
    """
    section_reg_data = get_resource(url)
    if section_reg_data is not None:
        section.student_grade = section_reg_data['Grade']
        section.is_auditor = section_reg_data['Auditor']
        if len(section_reg_data['GradeDate']) > 0:
            section.grade_date = parse_sws_date(
                section_reg_data['GradeDate']).date()
        try:
            section.student_credits = Decimal(
                section_reg_data['Credits'].strip())
        except InvalidOperation:
            pass
Exemple #34
0
def _get_sections_by_person_and_term(person,
                                     term,
                                     course_role,
                                     include_secondaries="on"):
    """
    Returns a list of restclients.models.sws.SectionReference object
    for the passed course_role and term (including secondaries).
    """
    url = "%s?%s" % (section_res_url_prefix,
                     urlencode({
                         "year": term.year,
                         "quarter": term.quarter.lower(),
                         "reg_id": person.uwregid,
                         "search_by": course_role,
                         "include_secondaries": include_secondaries
                     }))

    return _json_to_sectionref(get_resource(url), term)
def get_credits_by_section_and_regid(section, regid):
    """
    Returns a restclients.models.sws.Registration object
    for the section and regid passed in.
    """
    deprecation("Use get_credits_by_reg_url")
    #note trailing comma in URL, it's required for the optional dup_code param
    url = "%s%s,%s,%s,%s,%s,%s,.json" % (
        reg_credits_url_prefix, section.term.year, section.term.quarter,
        re.sub(' ', '%20', section.curriculum_abbr), section.course_number,
        section.section_id, regid)

    reg_data = get_resource(url)

    try:
        return Decimal(reg_data['Credits'].strip())
    except InvalidOperation:
        pass
Exemple #36
0
def get_changed_sections_by_term(changed_since_date, term):
    url = "%s?%s" % (section_res_url_prefix,
                     urlencode({
                         "year": term.year,
                         "quarter": term.quarter.lower(),
                         "changed_since_date": changed_since_date,
                         "page_size": 1000
                     }))

    sections = []
    while url is not None:
        data = get_resource(url)
        sections.extend(_json_to_sectionref(data, term))

        url = None
        if data.get("Next") is not None:
            url = data.get("Next").get("Href", None)

    return sections
def get_credits_by_section_and_regid(section, regid):
    """
    Returns a restclients.models.sws.Registration object
    for the section and regid passed in.
    """
    deprecation("Use get_credits_by_reg_url")
    # note trailing comma in URL, it's required for the optional dup_code param
    url = "%s%s,%s,%s,%s,%s,%s,.json" % (
        reg_credits_url_prefix,
        section.term.year,
        section.term.quarter,
        re.sub(' ', '%20', section.curriculum_abbr),
        section.course_number,
        section.section_id,
        regid
    )

    reg_data = get_resource(url)

    try:
        return Decimal(reg_data['Credits'].strip())
    except InvalidOperation:
        pass
Exemple #38
0
def get_all_campuses():
    """
    Returns a list of restclients.Campus models, representing all
    campuses.
    """
    return _json_to_campuses(get_resource(campus_search_url))
Exemple #39
0
def get_person_by_regid(regid):
    """
    Returns a restclients.models.sws.SwsPerson object
    """
    url = sws_url_prefix + regid + sws_url_suffix
    return _process_json_data(get_resource(url))
Exemple #40
0
def get_person_by_regid(regid):
    """
    Returns a restclients.models.sws.SwsPerson object
    """
    url = sws_url_prefix + regid + sws_url_suffix
    return _process_json_data(get_resource(url))
Exemple #41
0
 def test_get_resource(self):
     self.assertEquals(
         get_resource('/student/v5/campus.json'),
         "{u'PageSize': u'10', u'Campuses': [{u'CampusShortName': u'BOTHELL', u'Href': u'/student/v5/campus/BOTHELL.json', u'CampusName': u'UW Bothell', u'CampusFullName': u'UNIVERSITY OF WASHINGTON BOTHELL'}, {u'CampusShortName': u'SEATTLE', u'Href': u'/student/v5/campus/SEATTLE.json', u'CampusName': u'UW Seattle', u'CampusFullName': u'UNIVERSITY OF WASHINGTON SEATTLE'}, {u'CampusShortName': u'TACOMA', u'Href': u'/student/v5/campus/TACOMA.json', u'CampusName': u'UW Tacoma', u'CampusFullName': u'UNIVERSITY OF WASHINGTON TACOMA'}], u'Next': None, u'Current': {u'Href': u'/student/v5/campus.json&page_start=1&page_size=10'}, u'TotalCount': 3, u'PageStart': u'1', u'Previous': None}"
     )
def get_enrollment_by_regid_and_term(regid, term):
    url = "%s/%s,%s,%s.json" % (enrollment_res_url_prefix,
                                term.year,
                                term.quarter,
                                regid)
    return _json_to_enrollment(get_resource(url))
Exemple #43
0
def get_enrollment_by_regid_and_term(regid, term):
    url = "%s/%s,%s,%s.json" % (enrollment_res_url_prefix, term.year,
                                term.quarter, regid)
    return _json_to_enrollment(get_resource(url))
Exemple #44
0
def get_all_colleges():
    """
    Returns a list of restclients.College models, representing all
    colleges.
    """
    return _json_to_colleges(get_resource(college_search_url))
Exemple #45
0
def get_all_campuses():
    """
    Returns a list of restclients.Campus models, representing all
    campuses.
    """
    return _json_to_campuses(get_resource(campus_search_url))
Exemple #46
0
def get_account_balances_by_regid(regid):
    """
    Returns a restclients.models.sws.Finance object
    """
    url = sws_url_prefix + regid + sws_url_suffix
    return _process_json_data(get_resource(url))
 def test_get_resource(self):
     self.assertEquals(get_resource('/student/v5/campus.json'),
                       "{u'PageSize': u'10', u'Campuses': [{u'CampusShortName': u'BOTHELL', u'Href': u'/student/v5/campus/BOTHELL.json', u'CampusName': u'UW Bothell', u'CampusFullName': u'UNIVERSITY OF WASHINGTON BOTHELL'}, {u'CampusShortName': u'SEATTLE', u'Href': u'/student/v5/campus/SEATTLE.json', u'CampusName': u'UW Seattle', u'CampusFullName': u'UNIVERSITY OF WASHINGTON SEATTLE'}, {u'CampusShortName': u'TACOMA', u'Href': u'/student/v5/campus/TACOMA.json', u'CampusName': u'UW Tacoma', u'CampusFullName': u'UNIVERSITY OF WASHINGTON TACOMA'}], u'Next': None, u'Current': {u'Href': u'/student/v5/campus.json&page_start=1&page_size=10'}, u'TotalCount': 3, u'PageStart': u'1', u'Previous': None}")
def get_account_balances_by_regid(regid):
    """
    Returns a restclients.models.sws.Finance object
    """
    url = sws_url_prefix + regid + sws_url_suffix
    return _process_json_data(get_resource(url))