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, repo, commit_sha, flow_session, in_sandbox=False, page_uri=None)¶
course¶
repo¶
commit_sha¶
flow_session¶

May be None.

page_uri¶

Note that this is different from course.utils.FlowPageContext, which is used internally by the flow views.

class course.page.base.PageBehavior(show_correctness, show_answer, may_change_answer)¶
show_correctness¶
show_answer¶
may_change_answer¶
class course.page.base.AnswerFeedback(correctness, feedback=None, bulk_feedback=None)¶
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¶
exception course.page.base.InvalidPageData¶
class course.page.base.PageBase(vctx, location, page_desc)¶

The abstract interface of a flow page.

location¶

A string ‘location’ for reporting errors.

id¶

The page identifier.

required_attrs()¶

Required attributes, as accepted by course.validation.validate_struct(). Subclasses should only add to, not remove entries from this.

allowed_attrs()¶

Allowed attributes, as accepted by course.validation.validate_struct(). Subclasses should only add to, not remove entries from this.

get_modified_permissions_for_page(permissions)¶
initialize_page_data(page_context)¶

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.

title(page_context, page_data)¶

Return the (non-HTML) title of this page.

body(page_context, page_data)¶

Return the (HTML) body of the page.

expects_answer()¶
Returns

a bool indicating whether this page lets the user provide an answer of some type.

is_answer_gradable()¶
Returns

a bool indicating whether answers on this can have grade() called on them.

True by default.

max_points(page_data)¶
Returns

a int or float indicating how many points are achievable on this page.

Student Input

answer_data(page_context, page_data, form, files_data)¶

Return a JSON-persistable object reflecting the user’s answer on the form. This will be passed to methods below as answer_data.

make_form(page_context, page_data, answer_data, page_behavior)¶
Parameters
Returns

a django.forms.Form instance with answer_data prepopulated. If page_behavior.may_change_answer is False, the form should be read-only.

process_form_post(page_context, page_data, post_data, files_data, page_behavior)¶

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. If page_behavior.may_change_answer is False, the form should be read-only.

form_to_html(request, page_context, form, answer_data)¶

Returns an HTML rendering of form.

Grader Input

make_grading_form(page_context, page_data, grade_data)¶
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.

post_grading_form(page_context, page_data, grade_data, post_data, files_data)¶

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, page_context, page_data, grade_data, grading_form, files_data)¶

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, page_context, grading_form, grade_data)¶

Returns an HTML rendering of grading_form.

Grading/Feedback

grade(page_context, page_data, answer_data, grade_data)¶

Grade the answer contained in answer_data.

Parameters
Returns

a AnswerFeedback instanstance, or None if the grade is not yet available.

correct_answer(page_context, page_data, answer_data, grade_data)¶

The correct answer to this page’s interaction, formatted as HTML, or None.

analytic_view_body(page_context, page_data)¶

Return the (HTML) body of the page, which is shown in page analytic view.

normalized_answer(page_context, page_data, answer_data)¶

An HTML-formatted answer to be used for summarization and display in analytics.

normalized_bytes_answer(page_context, page_data, answer_data)¶

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 (inlcuding the leading period, if applicable). May also return None.

One use case of this function is to work as input for a plagiarism checker.

Validation¶

class course.validation.ValidationContext(repo, commit_sha, course=None)¶
repo¶
commit_sha¶
course¶

A course.models.Course instance, or None, if no database is currently available.

course.validation.validate_struct(vctx, location, obj, required_attrs, allowed_attrs)¶
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¶

Canonicalization of Django Names¶

class django.forms.forms.Form¶

See django.forms.Form.

class django.http.request.HttpRequest¶

See django.http.HttpRequest.

Stub Docs¶

class course.models.Course¶
class course.models.FlowSession¶
class relate.utils.SubdirRepoWrapper¶
class course.utils.FlowPageContext¶