Commit e2a35e78 authored by Lincoln Smith's avatar Lincoln Smith
Browse files

Implemented get_courses() methods for CourseFilter derived classes.

parent 7bbed7ec
......@@ -452,7 +452,7 @@ class CourseFilter:
class CourseListFilter(CourseFilter):
"""Return a list of courses identified by a set of course codes"""
"""Store an iterable of course codes"""
def __init__(self, course_codes: Iterable[str]):
self.course_codes = course_codes
......@@ -460,10 +460,13 @@ class CourseListFilter(CourseFilter):
def __repr__(self):
return str(self.course_codes)
return str(self.get_courses())
def get_courses(self) -> Iterable[Course]:
def get_courses(self) -> list:
"""Returns the iterable of course codes stored in this object as a list."""
if isinstance(self.course_codes, list):
return self.course_codes
return list(self.course_codes)
def build_course_regex(area_codes=None, levels=None) -> str:
......@@ -489,7 +492,7 @@ def build_course_regex(area_codes=None, levels=None) -> str:
class CourseRegexFilter(CourseFilter):
"""Return a list of courses identified by a set of course codes"""
"""Return a list of courses identified by a regular expression."""
def __init__(self, course_regex: str):
self.course_regex = course_regex
......@@ -497,8 +500,16 @@ class CourseRegexFilter(CourseFilter):
def __repr__(self):
return self.course_regex
def get_courses(self) -> Iterable[Course]:
def get_courses(self, course_codes=None) -> list:
Filter an iterable of course codes based on this object's course_regex attribute.
:param course_codes: Optional iterable of course codes. Uses COURSE_CODES if not set.
:return: List of course codes that match self.course_regex.
if course_codes is None:
course_codes = COURSE_CODES
return [code for code in course_codes if re.match(self.course_regex, code)]
class ProgramOrder:
......@@ -570,7 +581,13 @@ class ProgramOrder:
def dump_requirements(self):
Example method that recurses through the ProgramOrder tree and builds up a string
describing the program's requirements in a sort-of propositional logic statement format.
if self.children:
join_string = ' {} '.format(self.operator)
return '({})'.format(
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment