diff --git a/bases/rsptx/admin_server_api/routers/instructor.py b/bases/rsptx/admin_server_api/routers/instructor.py index 2f615b0b8..7859c86d1 100644 --- a/bases/rsptx/admin_server_api/routers/instructor.py +++ b/bases/rsptx/admin_server_api/routers/instructor.py @@ -25,6 +25,7 @@ create_assignment, create_course_instructor, create_course, + course_attr_is_true, create_course_attribute, create_instructor_course_entry, create_invoice_request, @@ -426,7 +427,7 @@ async def get_course_settings( "groupsize": course_attrs.get("groupsize", "3"), "enable_async_llm_modes": course_attrs.get("enable_async_llm_modes", "false"), "use_pretext_student_pages": str( - course_attrs.get("use_pretext_student_pages", "false") + course_attr_is_true(course_attrs, "use_pretext_student_pages", default=True) ).lower(), } diff --git a/bases/rsptx/assignment_server_api/routers/student.py b/bases/rsptx/assignment_server_api/routers/student.py index e2f8ff896..20c91b9e2 100644 --- a/bases/rsptx/assignment_server_api/routers/student.py +++ b/bases/rsptx/assignment_server_api/routers/student.py @@ -38,6 +38,7 @@ from rsptx.logging import rslogger from rsptx.db.crud import ( create_useinfo_entry, + course_attr_is_true, fetch_assignments, fetch_all_assignment_stats, fetch_all_grades_for_assignment, @@ -173,8 +174,8 @@ def sort_key(assignment): for a in assignments: visibility_map[a.id] = is_assignment_visible_to_students(a) - use_pretext_student_pages = ( - str(course_attrs.get("use_pretext_student_pages", "false")).lower() == "true" + use_pretext_student_pages = course_attr_is_true( + course_attrs, "use_pretext_student_pages", default=True ) if use_pretext_student_pages: book_path = safe_join( @@ -942,8 +943,8 @@ async def doAssignment( if timestamp > deadline: overdue = True - use_pretext_student_pages = ( - str(course_attrs.get("use_pretext_student_pages", "false")).lower() == "true" + use_pretext_student_pages = course_attr_is_true( + course_attrs, "use_pretext_student_pages", default=True ) if use_pretext_student_pages: book_path = safe_join( diff --git a/bases/rsptx/book_server_api/routers/course.py b/bases/rsptx/book_server_api/routers/course.py index 2b17be06c..78f136005 100644 --- a/bases/rsptx/book_server_api/routers/course.py +++ b/bases/rsptx/book_server_api/routers/course.py @@ -25,6 +25,7 @@ from rsptx.db.crud import ( fetch_assignments, fetch_all_assignment_stats, + course_attr_is_true, fetch_course, fetch_all_course_attributes, fetch_courses_for_user, @@ -147,8 +148,8 @@ def sort_key(assignment): for a in assignments: visibility_map[a.id] = is_assignment_visible_to_students(a) - use_pretext_student_pages = ( - str(attrs.get("use_pretext_student_pages", "false")).lower() == "true" + use_pretext_student_pages = course_attr_is_true( + attrs, "use_pretext_student_pages", default=True ) if use_pretext_student_pages: book_path = safe_join( diff --git a/components/rsptx/db/crud/__init__.py b/components/rsptx/db/crud/__init__.py index 990e4fb88..d63a82dba 100644 --- a/components/rsptx/db/crud/__init__.py +++ b/components/rsptx/db/crud/__init__.py @@ -83,6 +83,7 @@ from .course_attrs import ( copy_course_attributes, create_course_attribute, + course_attr_is_true, fetch_all_course_attributes, fetch_one_course_attribute, get_course_origin, @@ -420,6 +421,7 @@ __all__ += [ "copy_course_attributes", "create_course_attribute", + "course_attr_is_true", "fetch_all_course_attributes", "fetch_one_course_attribute", "get_course_origin", diff --git a/components/rsptx/db/crud/course_attrs.py b/components/rsptx/db/crud/course_attrs.py index 6dba6d26c..94976470d 100644 --- a/components/rsptx/db/crud/course_attrs.py +++ b/components/rsptx/db/crud/course_attrs.py @@ -19,6 +19,17 @@ async def fetch_all_course_attributes(course_id: int) -> dict: return {row.attr: row.value for row in res.scalars().fetchall()} +def course_attr_is_true(course_attrs: dict, attr: str, default: bool = False) -> bool: + """Return ``True`` when a course attribute is set to the string ``true``. + + :param course_attrs: Dictionary of course attributes. + :param attr: Attribute name to inspect. + :param default: Default value when the attribute is missing. + :return: ``True`` when the attribute value evaluates to the string ``true``. + """ + return str(course_attrs.get(attr, str(default))).lower() == "true" + + async def fetch_one_course_attribute(): """ Fetch a single course attribute (not implemented)