Skip to content

Commit

Permalink
Merge pull request #16 from uw-it-aca/feature/off-term-pce
Browse files Browse the repository at this point in the history
Feature/off term pce
  • Loading branch information
fanglinfang committed Apr 20, 2017
2 parents 84f77b0 + e311c84 commit 794afdc
Show file tree
Hide file tree
Showing 8 changed files with 777 additions and 45 deletions.
58 changes: 54 additions & 4 deletions uw_sws/enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
Interfacing with the Student Web Service, Enrollment resource.
"""
import logging
import re
from uw_pws import PWS
from uw_sws.models import (Term, StudentGrades, StudentCourseGrade, Enrollment,
Major, Minor)
from uw_sws import get_resource
Major, Minor, SectionReference,
IndependentStartSectionReference)
from uw_sws import get_resource, parse_sws_date
from uw_sws.section import get_section_by_url


Expand Down Expand Up @@ -49,14 +51,24 @@ def get_enrollment_by_regid_and_term(regid, term):
term.year,
term.quarter,
regid)
return _json_to_enrollment(get_resource(url))
return _json_to_enrollment(get_resource(url), term)


def _json_to_enrollment(json_data):
def _json_to_enrollment(json_data, term):
enrollment = Enrollment()
enrollment.regid = json_data['RegID']
enrollment.class_level = json_data['ClassLevel']
enrollment.is_honors = json_data['HonorsProgram']
enrollment.is_enroll_src_pce = is_reg_src_pce(json_data,
ENROLLMENT_SOURCE_PCE)

enrollment.independent_start_sections = []
if json_data.get('Registrations') is not None and\
len(json_data['Registrations']) > 0:
for registration in json_data['Registrations']:
if registration.get('IsIndependentStart'):
enrollment.independent_start_sections.append(
_json_to_independent_start_section(registration, term))

enrollment.majors = []
if json_data.get('Majors') is not None and len(json_data['Majors']) > 0:
Expand All @@ -70,6 +82,31 @@ def _json_to_enrollment(json_data):
return enrollment


def _json_to_independent_start_section(json_data, aterm):
is_section = IndependentStartSectionReference()
is_section.section_ref = SectionReference(
term=aterm,
curriculum_abbr=json_data['Section']['CurriculumAbbreviation'],
course_number=json_data['Section']['CourseNumber'],
section_id=json_data['Section']['SectionID'],
url=json_data['Section']['Href']
)
is_section.feebase_type = json_data['FeeBaseType']
try:
is_section.end_date = parse_sws_date(json_data['EndDate'])
except Exception:
is_section.end_date = ""

try:
is_section.start_date = parse_sws_date(json_data['StartDate'])
except Exception:
is_section.start_date = ""

is_section.is_reg_src_pce = is_reg_src_pce(json_data,
REGISTRATION_SOURCE_PCE)
return is_section


def _json_to_major(json_data):
major = Major()
major.degree_abbr = json_data['Abbreviation']
Expand All @@ -89,3 +126,16 @@ def _json_to_minor(json_data):
minor.full_name = json_data['FullName']
minor.short_name = json_data['ShortName']
return minor


ENROLLMENT_SOURCE_PCE = re.compile('^EnrollmentSourceLocation=SDB_EOS;',
re.I)
REGISTRATION_SOURCE_PCE = re.compile('^RegistrationSourceLocation=SDB_EOS;',
re.I)


def is_reg_src_pce(json_data, pattern):
try:
return re.match(pattern, json_data['Metadata']) is not None
except KeyError:
return False
60 changes: 58 additions & 2 deletions uw_sws/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ def json_data(self):


class Section(models.Model):
INSTITUTE_NAME_PCE = "UW PROFESSIONAL AND CONTINUING EDUCATION"
EARLY_FALL_START = "EARLY FALL START"
SUMMER_A_TERM = "a-term"
SUMMER_B_TERM = "b-term"
SUMMER_FULL_TERM = "full-term"
Expand Down Expand Up @@ -469,6 +471,12 @@ def is_campus_tacoma(self):
return self.course_campus is not None and\
self.course_campus.lower() == 'tacoma'

def is_inst_pce(self):
return self.institute_name == Section.INSTITUTE_NAME_PCE

def is_early_fall_start(self):
return self.institute_name == Section.EARLY_FALL_START

def section_label(self):
return "%s,%s,%s,%s/%s" % (
self.term.year,
Expand Down Expand Up @@ -599,8 +607,8 @@ def json_data(self):
'class_website_url': self.class_website_url,
'sln': self.sln,
'summer_term': self.summer_term,
'start_date': '',
'end_date': '',
'start_date': str(self.start_date),
'end_date': str(self.end_date),
'current_enrollment': self.current_enrollment,
'limit_estimate_enrollment': self.limit_estimate_enrollment,
'limit_estimate_enrollment_indicator':
Expand Down Expand Up @@ -638,6 +646,15 @@ def section_label(self):
self.term.quarter, self.curriculum_abbr,
self.course_number, self.section_id)

def json_data(self):
return {'year': self.term.year,
'quarter': self.term.quarter,
'curriculum_abbr': self.curriculum_abbr,
'course_number': self.course_number,
'section_id': self.section_id,
'url': self.url,
'section_label': self.section_label()}


class SectionStatus(models.Model):
add_code_required = models.NullBooleanField()
Expand Down Expand Up @@ -944,12 +961,26 @@ def __str__(self):
self.tuition_accbalance, self.pce_accbalance)


NON_MATRIC = "non_matric"


class Enrollment(models.Model):
is_honors = models.NullBooleanField()
class_level = models.CharField(max_length=100)
regid = models.CharField(max_length=32,
db_index=True,
unique=True)
is_enroll_src_pce = models.NullBooleanField()

def is_non_matric(self):
return self.class_level.lower() == NON_MATRIC

def has_independent_start_course(self):
try:
return (self.independent_start_sections and
len(self.independent_start_sections) > 0)
except AttributeError:
return False


class Major(models.Model):
Expand Down Expand Up @@ -984,3 +1015,28 @@ def json_data(self):
'full_name': self.full_name,
'short_name': self.short_name
}


FEEBASED = "fee based course"


class IndependentStartSectionReference(models.Model):
section_ref = models.ForeignKey(SectionReference,
on_delete=models.PROTECT)
end_date = models.DateField(null=True, blank=True)
start_date = models.DateField(null=True, blank=True)
feebase_type = models.CharField(max_length=64)
is_reg_src_pce = models.NullBooleanField()

def is_fee_based(self):
return self.feebase_type.lower() == FEEBASED

def json_data(self, include_section_ref=False):
data = {'start_date': str(self.start_date),
'end_date': str(self.end_date),
'feebase_type': self.feebase_type,
'is_reg_src_pce': self.is_reg_src_pce
}
if include_section_ref:
data['section_ref'] = self.section_ref.json_data()
return data
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"AddCodeRequired": false,
"Auditors": 0,
"ClassWebsiteUrl": "",
"Course": {
"CourseNumber": "101",
"CurriculumAbbreviation": "EFS_FAILT",
"Href": "/student/v5/course/2013,spring,EFS_FAILT,101.json",
"Quarter": "spring",
"Year": 2013
},
"CourseCampus": "Seattle",
"CourseDescription": "Builds writing confidence through frequent informal writing, and introductions to key learning strategies. Includes user-friendly orientation to library and research documents, revision skills, and peer review work central to 100- and 200-level college writing assignments. Offered: A.",
"CourseHasVariableContent": false,
"CourseTitle": "WRITING READY",
"CourseTitleLong": "WRITING READY: PREPARING FOR COLLEGE WRITING",
"CreditControl": "fixed credit",
"CurrentEnrollment": 16,
"Curriculum": {
"CollegeName": "ARTS & SCI",
"DepartmentAbbreviation": "EFS_FAILT",
"TimeScheduleLinkAbbreviation": "98engl"
},
"DeleteFlag": "active",
"DistanceLearning": false,
"DuplicateEnrollmentAllowed": false,
"EndDate": "2013-09-18",
"EnrollmentRestrictions": false,
"FeeAmount": "",
"FeeBudget": "",
"FeeType": "",
"FinalExam": {
"Building": "*",
"Date": "0000-00-00",
"EndTime": "00:00",
"MeetingStatus": "1",
"RoomNumber": "*",
"StartTime": "00:00"
},
"FinancialAidEligible": true,
"FinancialAidEligibleDisplay": "",
"GeneralEducationRequirements": {
"Diversity": false,
"EnglishComposition": false,
"IndividualsAndSocieties": false,
"NaturalWorld": false,
"QuantitativeAndSymbolicReasoning": false,
"VisualLiteraryAndPerformingArts": false,
"Writing": false
},
"GradeSubmissionDelegates": [
{
"DelegateLevel": "department",
"Person": {
"Href": "/student/v5/person/260A0DEC95CB11D78BAA000629C31437.json",
"Name": "BUSCH,CAROLYN J",
"RegID": "260A0DEC95CB11D78BAA000629C31437"
}
},
{
"DelegateLevel": "curriculum",
"Person": {
"Href": "/student/v5/person/260A0DEC95CB11D78BAA000629C31437.json",
"Name": "BUSCH,CAROLYN J",
"RegID": "260A0DEC95CB11D78BAA000629C31437"
}
}
],
"GradingSystem": "standard",
"HonorsCourse": false,
"IndependentStudy": false,
"InstituteName": "EARLY FALL START",
"JointSections": [],
"LimitEstimateEnrollment": 18,
"LimitEstimateEnrollmentIndicator": "limit",
"LinkedSectionTypes": [],
"MaximumCredit": "",
"MaximumTermCredit": "",
"Meetings": [
{
"Building": "SAV",
"BuildingToBeArranged": false,
"DaysOfWeek": {
"Days": [
{
"Name": "Monday"
},
{
"Name": "Tuesday"
},
{
"Name": "Wednesday"
},
{
"Name": "Thursday"
},
{
"Name": "Friday"
}
],
"Text": "MTWTF"
},
"DaysOfWeekToBeArranged": false,
"EndTime": "12:00",
"Instructors": [
{
"FacultySequenceNumber": "",
"GradeRoster": {
"Href": "/student/v5/graderoster/2013,spring,EFS_FAILT,101,H,9F94490E82B111DA9767000629C31437"
},
"Person": {
"Href": "/student/v5/person/260A0DEC95CB11D78BAA000629C31437.json",
"Name": "ROMPOGREN,JUSTINA C",
"RegID": "260A0DEC95CB11D78BAA000629C31437"
},
"TSPrint": true
}
],
"MeetingIndex": "1",
"MeetingType": "lecture",
"RoomNumber": "137",
"RoomToBeArranged": false,
"StartTime": "09:30"
}
],
"MinimumTermCredit": "5.0",
"PrimarySection": {
"CourseNumber": "101",
"CurriculumAbbreviation": "EFS_FAILT",
"Href": "/student/v5/course/2013,spring,EFS_FAILT,101/H.json",
"Quarter": "spring",
"SectionID": "AQ",
"Year": 2013
},
"Registrations": {
"CourseNumber": "101",
"CurriculumAbbreviation": "EFS_FAILT",
"Href": "/student/v5/registration.json?year=2013&quarter=spring&curriculum_abbreviation=EFS_FAILT&course_number=101&section_id=AQ&reg_id=&is_active=True&instructor_reg_id=&verbose=False",
"InstructorRegID": null,
"IsActive": true,
"PageSize": null,
"PageStart": null,
"Quarter": "spring",
"RegID": null,
"SectionID": "AQ",
"Verbose": false,
"Year": 2013
},
"ResearchCredit": false,
"RoomCapacity": 30,
"SLN": "13870",
"SameVariableContentAs": [],
"SecondaryGradingOption": false,
"SectionID": "AQ",
"SectionType": "lecture",
"SelfRegistrationAllowed": false,
"ServiceLearning": false,
"StartDate": "2013-08-24",
"StudentCreditHours": " 80.0",
"SummerTerm": "",
"Term": {
"Href": "/student/v5/term/2013,spring.json",
"Quarter": "spring",
"Year": 2013
},
"TimeScheduleComments": {
"CollegeComments": {
"Lines": []
},
"CourseComments": {
"Lines": []
},
"CurriculumComments": {
"Lines": []
},
"DepartmentComments": {
"Lines": []
},
"InstituteComments": {
"Lines": []
},
"SectionComments": {
"Lines": []
},
"TimeScheduleGeneratedComments": {
"Lines": []
}
}
}
Loading

0 comments on commit 794afdc

Please sign in to comment.