From 1e615de8c0703a86ac536e11f9902c2b0bb230e2 Mon Sep 17 00:00:00 2001 From: sahilkamboj3 Date: Sun, 31 Jan 2021 00:10:35 -0800 Subject: [PATCH 1/2] identical code option added --- course/page/code.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/course/page/code.py b/course/page/code.py index cbb34af7c..7819ffc32 100644 --- a/course/page/code.py +++ b/course/page/code.py @@ -589,6 +589,8 @@ def __init__(self, vctx, location, page_desc, language_mode): "While you're at it, consider adding " "access_rules/add_permssions/see_correctness.")) + self.identical_okay = getattr(page_desc, "identical_okay", False) + def required_attrs(self): return super().required_attrs() + ( ("prompt", "markup"), @@ -609,6 +611,7 @@ def allowed_attrs(self): ("docker_image", str), ("data_files", list), ("single_submission", bool), + ("identical_okay", bool), ) def _initial_code(self): @@ -886,7 +889,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.identical_okay): feedback_bits.append( "

%s

" % _("It looks like you submitted code that is identical to " From 1b1a5c10fc11602ba783896c43e39b6f49bad983 Mon Sep 17 00:00:00 2001 From: sahilkamboj3 Date: Wed, 3 Feb 2021 23:12:06 -0800 Subject: [PATCH 2/2] documentation added to and exact_correct_code_okay boolean added --- course/page/code.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/course/page/code.py b/course/page/code.py index 7819ffc32..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,7 +594,8 @@ def __init__(self, vctx, location, page_desc, language_mode): "While you're at it, consider adding " "access_rules/add_permssions/see_correctness.")) - self.identical_okay = getattr(page_desc, "identical_okay", False) + self.exact_correct_code_okay = getattr(page_desc, + "exact_correct_code_okay", False) def required_attrs(self): return super().required_attrs() + ( @@ -611,7 +617,7 @@ def allowed_attrs(self): ("docker_image", str), ("data_files", list), ("single_submission", bool), - ("identical_okay", bool), + ("exact_correct_code_okay", bool), ) def _initial_code(self): @@ -890,7 +896,7 @@ def normalize_code(s): if (normalize_code(user_code) == normalize_code(self.page_desc.correct_code) - and not self.identical_okay): + and not self.exact_correct_code_okay): feedback_bits.append( "

%s

" % _("It looks like you submitted code that is identical to " @@ -1238,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