From d4a020baf82a08797b0775e6d18a0351f5c5c9e7 Mon Sep 17 00:00:00 2001 From: idugan100 Date: Mon, 8 Jan 2024 22:49:05 -0500 Subject: [PATCH] moving course code regex from linking logic to a Course model class attribute --- home/models.py | 5 +++-- home/views/course.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/home/models.py b/home/models.py index ca0d936..2a82d32 100644 --- a/home/models.py +++ b/home/models.py @@ -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 @@ -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: diff --git a/home/views/course.py b/home/views/course.py index b0a48b5..bde8fbd 100644 --- a/home/views/course.py +++ b/home/views/course.py @@ -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: