Skip to content
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
3 changes: 2 additions & 1 deletion bases/rsptx/admin_server_api/routers/instructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
}

Expand Down
9 changes: 5 additions & 4 deletions bases/rsptx/assignment_server_api/routers/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions bases/rsptx/book_server_api/routers/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions components/rsptx/db/crud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions components/rsptx/db/crud/course_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading