diff --git a/course/page/code.py b/course/page/code.py index cbb34af7c..577b4fb51 100644 --- a/course/page/code.py +++ b/course/page/code.py @@ -544,6 +544,11 @@ class CodeQuestion(PageBaseWithTitle, PageBaseWithValue): example of a local build. The Docker image should already be loaded on the system (RELATE does not pull the image automatically). + .. attribute:: exact_correct_code_okay + Optional. A Boolean that controls whether identical submissions to the + correct_code are allowed for code questions. If set to False, an error + is shown. Setting this to True will silence the error. + * ``data_files``: A dictionary mapping file names from :attr:`data_files` to :class:`bytes` instances with that file's contents. @@ -589,6 +594,9 @@ def __init__(self, vctx, location, page_desc, language_mode): "While you're at it, consider adding " "access_rules/add_permssions/see_correctness.")) + self.exact_correct_code_okay = getattr(page_desc, + "exact_correct_code_okay", False) + def required_attrs(self): return super().required_attrs() + ( ("prompt", "markup"), @@ -609,6 +617,7 @@ def allowed_attrs(self): ("docker_image", str), ("data_files", list), ("single_submission", bool), + ("exact_correct_code_okay", bool), ) def _initial_code(self): @@ -886,7 +895,8 @@ def normalize_code(s): .replace("\t", "")) if (normalize_code(user_code) - == normalize_code(self.page_desc.correct_code)): + == normalize_code(self.page_desc.correct_code) + and not self.exact_correct_code_okay): feedback_bits.append( "
%s
" % _("It looks like you submitted code that is identical to " @@ -1234,6 +1244,11 @@ class PythonCodeQuestion(CodeQuestion): based on its :attr:`access_rules` (not the ones of the flow), a warning is shown. Setting this attribute to True will silence the warning. + .. attribute:: exact_correct_code_okay + Optional. A Boolean that controls whether identical submissions to the + correct_code are allowed for code questions. If set to False, an error + is shown. Setting this to True will silence the error. + The following symbols are available in :attr:`setup_code` and :attr:`test_code`: * ``GradingComplete``: An exception class that can be raised to indicated