Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Course regex in single location #152

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ class Course(Model):
recent = RecentCourseManager()
unfiltered = Manager()

course_code_format = '[A-Za-z]{4}(?:[A-Za-z]|[0-9]){3,6}'

def save(self, *args, **kwargs):
# `name` is essentially a computed field, and will never have a value
# other than CONCAT("department", "course_number"). Ensure that this
Expand Down Expand Up @@ -471,8 +473,7 @@ class Meta:
def get_content_with_course_links(self):
content = escape(self.content)
courses_replaced = []

course_code_format = '[A-Za-z]{4}(?:[A-Za-z]|[0-9]){3,6}'
course_code_format = Course.course_code_format
matches = re.findall(course_code_format,content)

for word in matches:
Expand Down
2 changes: 1 addition & 1 deletion home/views/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get(self, request, name):
course_description = course.description
courses_replaced = []

course_code_format = '[A-Za-z]{4}(?:[A-Za-z]|[0-9]){3,6}'
course_code_format = CourseModel.course_code_format
matches = re.findall(course_code_format,course_description)

for word in matches:
Expand Down