From 2c2522d947a1fe1ccfe269040014b23acf3edecd Mon Sep 17 00:00:00 2001 From: Tan Jia Qing Date: Sat, 16 Nov 2024 09:23:13 +0000 Subject: [PATCH] Support displaying external resources in flow page --- course/content.py | 14 ++++++++++++++ course/flow.py | 2 +- course/templates/course/flow-page.html | 21 +++++++++++++++++++++ course/validation.py | 1 + 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/course/content.py b/course/content.py index a429a661e..bedfdde4b 100644 --- a/course/content.py +++ b/course/content.py @@ -527,6 +527,14 @@ class FlowRulesDesc(Struct): # {{{ mypy: flow +class ExternalResourcesDesc(Struct): + def __init__(self, title: str, url: str) -> None: + self.title = title + self.url = url + + title: str + url: str + class FlowPageDesc(Struct): id: str type: str @@ -594,6 +602,11 @@ class FlowDesc(Struct): A list of :ref:`pages `. If you specify this, a single :class:`FlowPageGroupDesc` will be implicitly created. Exactly one of :attr:`groups` or :class:`pages` must be given. + + .. attribute:: external_resources + + A list of :class:`ExternalResourcesDesc`. These are links to external + resources that are displayed on the bottom of the flow page. """ title: str @@ -601,6 +614,7 @@ class FlowDesc(Struct): rules: FlowRulesDesc pages: list[FlowPageDesc] groups: list[FlowPageGroupDesc] + external_resources: list[ExternalResourcesDesc] notify_on_submit: list[str] | None # }}} diff --git a/course/flow.py b/course/flow.py index cbc3a8eeb..f4d4943ac 100644 --- a/course/flow.py +++ b/course/flow.py @@ -56,7 +56,7 @@ is_expiration_mode_allowed, participation_permission as pperm, ) -from course.content import FlowPageDesc +from course.content import FlowPageDesc, ExternalResourcesDesc from course.exam import get_login_exam_ticket from course.models import ( Course, diff --git a/course/templates/course/flow-page.html b/course/templates/course/flow-page.html index 819cfb159..fc31055a6 100644 --- a/course/templates/course/flow-page.html +++ b/course/templates/course/flow-page.html @@ -371,6 +371,27 @@ {# }}} #} + {# {{{ external resources #} + + {# if flow_desc.external_resources > #} +

+ {% for resource_desc in flow_desc.external_resources %} + + {% endfor %} +

+ + {% for resource_desc in flow_desc.external_resources %} +
+
+ +
+
+ {% endfor %} + + {# }}} #} {# {{{ feedback #} {% if show_correctness and feedback %} diff --git a/course/validation.py b/course/validation.py index 39f659f77..8dac76f53 100644 --- a/course/validation.py +++ b/course/validation.py @@ -1022,6 +1022,7 @@ def validate_flow_desc(vctx, location, flow_desc): ("groups", list), ("pages", list), ("notify_on_submit", list), + ("external_resources", list), # deprecated (moved to grading rule) ("max_points", (int, float)),