Internals¶
Flow Page Interface¶
This describes the programming interface between Relate and a page in a flow.
Stub Docs of Internals¶
- class course.page.base.Repo_ish¶
See
relate.utils.Repo_ish
.
- class course.page.base.Course¶
See
course.models.Course
.
- class course.page.base.FlowSession¶
See
course.models.FlowSession
.
Page Interface¶
- class course.page.base.PageContext(course: Course, repo: Repo_ish, commit_sha: bytes, flow_session: FlowSession, in_sandbox: bool = False, page_uri: str | None = None, request: django.http.HttpRequest | None = None)[source]¶
- course¶
- repo¶
- commit_sha¶
- flow_session¶
May be None.
- page_uri¶
- request¶
Note that this is different from
course.utils.FlowPageContext
, which is used internally by the flow views.
- class course.page.base.PageBehavior(show_correctness: bool, show_answer: bool, may_change_answer: bool)[source]¶
- show_correctness¶
- show_answer¶
- may_change_answer¶
- class course.page.base.AnswerFeedback(correctness: float | None, feedback: str | None = None, bulk_feedback: str | None = None)[source]¶
- correctness¶
A
float
between 0 and 1 (inclusive), indicating the degree of correctness of the answer. May be None.
- feedback¶
Text (at least as a full sentence, or even multi-paragraph HTML) providing feedback to the student about the provided answer. Should not reveal the correct answer.
May be None, in which case generic feedback is generated from
correctness
.
- bulk_feedback¶
Base Classes For Pages¶
- class course.page.base.PageBase(vctx: ValidationContext | None, location: str, page_desc: Any)[source]¶
The abstract interface of a flow page.
- location¶
A string ‘location’ for reporting errors.
- id¶
The page identifier.
- required_attrs() Sequence[tuple[str, type | tuple[type, ...] | Literal['markup']]] [source]¶
Required attributes, as accepted by
course.validation.validate_struct()
. Subclasses should only add to, not remove entries from this.
- allowed_attrs() Sequence[tuple[str, type | tuple[type, ...] | Literal['markup']]] [source]¶
Allowed attributes, as accepted by
course.validation.validate_struct()
. Subclasses should only add to, not remove entries from this.
- initialize_page_data(page_context: PageContext) dict [source]¶
Return (possibly randomly generated) data that is used to generate the content on this page. This is passed to methods below as the page_data argument. One possible use for this argument would be a random permutation of choices that is generated once (at flow setup) and then used whenever this page is shown.
- abstract title(page_context: PageContext, page_data: dict) str [source]¶
Return the (non-HTML) title of this page.
- abstract body(page_context: PageContext, page_data: dict) str [source]¶
Return the (HTML) body of the page.
- abstract expects_answer() bool [source]¶
- Returns:
a
bool
indicating whether this page lets the user provide an answer of some type.
Student Input
- abstract answer_data(page_context: PageContext, page_data: Any, form: Form, files_data: Any) Any [source]¶
Return a JSON-persistable object reflecting the user’s answer on the form. This will be passed to methods below as answer_data.
- abstract make_form(page_context: PageContext, page_data: Any, answer_data: Any, page_behavior: Any) StyledForm [source]¶
- Parameters:
answer_data – value returned by
answer_data()
. May be None.page_behavior – an instance of
PageBehavior
- Returns:
a
django.forms.Form
instance with answer_data prepopulated. Ifpage_behavior.may_change_answer
is False, the form should be read-only.
- abstract process_form_post(page_context: PageContext, page_data: Any, post_data: Any, files_data: Any, page_behavior: PageBehavior) StyledForm [source]¶
Return a form with the POST response from post_data and files_data filled in.
- Parameters:
page_behavior – an instance of
PageBehavior
- Returns:
a
django.forms.Form
instance with answer_data prepopulated. Ifpage_behavior.may_change_answer
is False, the form should be read-only.
- form_to_html(request: HttpRequest, page_context: PageContext, form: StyledForm, answer_data: Any)[source]¶
Returns an HTML rendering of form.
Grader Input
- abstract make_grading_form(page_context: PageContext, page_data: Any, grade_data: Any) StyledForm | None [source]¶
- Parameters:
grade_data – value returned by
update_grade_data_from_grading_form_v2()
. May be None.- Returns:
a
django.forms.Form
instance with grade_data prepopulated.
- abstract post_grading_form(page_context: PageContext, page_data: Any, grade_data: Any, post_data: Any, files_data: Any) StyledForm [source]¶
Return a form with the POST response from post_data and files_data filled in.
- Returns:
a
django.forms.Form
instance with grade_data prepopulated.
- update_grade_data_from_grading_form_v2(request: HttpRequest, page_context: PageContext, page_data: Any, grade_data: Any, grading_form: Any, files_data: Any)[source]¶
Return an updated version of grade_data, which is a JSON-persistable object reflecting data on grading of this response. This will be passed to other methods as grade_data.
- grading_form_to_html(request: HttpRequest, page_context: PageContext, grading_form: Any, grade_data: Any) str [source]¶
Returns an HTML rendering of grading_form.
Grading/Feedback
- abstract grade(page_context: PageContext, page_data: Any, answer_data: Any, grade_data: Any) AnswerFeedback | None [source]¶
Grade the answer contained in answer_data.
- Parameters:
answer_data – value returned by
answer_data()
, or None, which means that no answer was supplied.grade_data – value updated by
update_grade_data_from_grading_form_v2()
- Returns:
a
AnswerFeedback
instanstance, or None if the grade is not yet available.
- abstract correct_answer(page_context: PageContext, page_data: Any, answer_data: Any, grade_data: Any) str | None [source]¶
The correct answer to this page’s interaction, formatted as HTML, or None.
- analytic_view_body(page_context: PageContext, page_data: dict) str [source]¶
Return the (HTML) body of the page, which is shown in page analytic view.
- abstract normalized_answer(page_context: PageContext, page_data: Any, answer_data: Any) str | None [source]¶
An HTML-formatted answer to be used for summarization and display in analytics. Since this may include user input, it is expected to be sanitized.
- abstract normalized_bytes_answer(page_context: PageContext, page_data: Any, answer_data: Any) tuple[str, bytes] | None [source]¶
An answer to be used for batch download, given as a batch of bytes to be stuffed in a zip file.
- Returns:
a tuple of
(file_ext, data)
where file_ext is a suggested file extension (including the leading period, if applicable). May also return None.
One use case of this function is to work as input for a plagiarism checker.
- class course.page.base.PageBaseWithTitle(vctx: ValidationContext | None, location: str, page_desc: Any)[source]¶
- class course.page.base.PageBaseWithHumanTextFeedback(vctx: ValidationContext | None, location: str, page_desc: Any)[source]¶
- human_feedback_point_value(page_context: PageContext, page_data: Any) float | None [source]¶
Subclasses can override this to make the point value of the human feedback known, which will enable grade entry in points.
Supports automatic computation of point values from textual feedback. See Automatic point computation from textual feedback.
Automatic Feedback¶
Validation¶
- class course.validation.ValidationContext(repo: Repo_ish, commit_sha: bytes, course: Course | None = None)[source]¶
- repo¶
- commit_sha¶
- course¶
A
course.models.Course
instance, or None, if no database is currently available.
- course.validation.validate_struct(vctx: ValidationContext, location: str, obj: Any, required_attrs: Sequence[tuple[str, type | tuple[type, ...] | Literal['markup']]], allowed_attrs: Sequence[tuple[str, type | tuple[type, ...] | Literal['markup']]]) None [source]¶
- Parameters:
required_attrs – an attribute validation list (see below)
allowed_attrs – an attribute validation list (see below)
An attribute validation list is a list of elements, where each element is either a string (the name of the attribute), in which case the type of each attribute is not checked, or a tuple (name, type), where type is valid as a second argument to
isinstance()
.
Stub Docs¶
- class course.validation.Course¶
- class course.validation.Repo_ish¶
Stub Docs¶
Canonicalization of Django Names¶
- class django.forms.forms.Form[source]¶
See
django.forms.Form
.