Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

More config values for Runcstone components #867

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ build_info

# IDEs
.vscode/
.vs/
**/sphinx-enki-info.txt
# Mac stuff
.DS_Store
6 changes: 5 additions & 1 deletion runestone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ def runestone_extensions():
if os.path.exists("{}/__init__.py".format(os.path.join(basedir, x)))
]
# Place ``runestone.common`` first, so it can run init code needed by all other modules. This assumes that the first module in the list is run first. An alternative to this to guarantee this ordering is to call ``app.setup_extension('runestone.common')`` in every extension.
modules.insert(0, modules.pop(modules.index("runestone.common")))
modules.insert(0, modules.pop(modules.index('runestone.common')))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated -- see line 78.

# ``runestone.updateConfig`` is reserved for testing and will only be included if ``test`` is the second to last element of tha path
if 'test' != os.path.split(os.getcwd())[-1]:
modules.remove('runestone.updateConfig')

return modules


Expand Down
2 changes: 1 addition & 1 deletion runestone/assess/assess.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def setup(app):
app.add_directive("timed", TimedDirective)

app.add_config_value("mchoice_div_class", "runestone alert alert-warning", "html")

app.add_config_value("mchoice_compare_button_show", True, "html")
app.add_autoversioned_javascript("mchoice.js")
app.add_autoversioned_javascript("timedmc.js")
app.add_autoversioned_javascript("timed.js")
Expand Down
3 changes: 2 additions & 1 deletion runestone/assess/js/mchoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ MultipleChoice.prototype.init = function (opts) {
this.multipleanswers = false;
this.divid = orig.id;
this.caption = 'Multiple Choice'
this.showcomparebutton = $(orig).data('showcomparebutton');

if ($(this.origElem).data("multipleanswers") === true) {
this.multipleanswers = true;
Expand Down Expand Up @@ -233,7 +234,7 @@ MultipleChoice.prototype.renderMCFormButtons = function () {
this.optsForm.appendChild(this.submitButton);

// Create compare button
if (this.useRunestoneServices) {
if (this.useRunestoneServices && this.showcomparebutton) {
this.compareButton = document.createElement("button");
$(this.compareButton).attr({
"class": "btn btn-default",
Expand Down
13 changes: 10 additions & 3 deletions runestone/assess/multiplechoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class MChoice(Assessment):
config values (conf.py):

- mchoice_div_class - custom CSS class of the component's outermost div
- mchoice_compare_button_show - if False, hide the 'Compare me' button (default True)
"""

required_arguments = 1
Expand Down Expand Up @@ -184,10 +185,16 @@ def run(self):

super(MChoice, self).run()

TEMPLATE_START = """
env = self.state.document.settings.env
if env.config.mchoice_compare_button_show:
self.options['showcomparebutton'] = 'data-showcomparebutton=true'
else:
self.options['showcomparebutton'] = 'data-showcomparebutton=false'

TEMPLATE_START = '''
<div class="%(divclass)s">
<ul data-component="multiplechoice" data-multipleanswers="%(multipleAnswers)s" %(random)s id="%(divid)s">
"""
<ul data-component="multiplechoice" data-multipleanswers="%(multipleAnswers)s" %(random)s %(showcomparebutton)s id="%(divid)s">
'''

OPTION = """
<li data-component="answer" %(is_correct)s id="%(divid)s_opt_%(alabel)s">%(atext)s</li><li data-component="feedback">%(feedtext)s</li>
Expand Down
4 changes: 4 additions & 0 deletions runestone/common/project_template/conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,7 @@ htmlhelp_basename = 'PythonCoursewareProjectdoc'
#shortanswer_optional_div_class = 'journal alert alert-success'
#showeval_div_class = 'runestone explainer alert alert-warning'
#tabbed_div_class = 'alert alert-warning'
#mchoice_compare_button_show - if False, hide the 'Compare me' button (default True)
#mchoice_compare_button_show = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a brief description of what this option controls for both of these.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fitb.py and multiplechoice.py there are these two comments:

  • mchoice_compare_button_show - if False, hide the 'Compare me' button (default True)
  • fitb_compare_button_show - if False, hide the 'Compare me' button (default True)

Should I add these to conf.tmpl as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly.

#fitb_compare_button_show - if False, hide the 'Compare me' button (default True)
#fitb_compare_button_show = True
10 changes: 9 additions & 1 deletion runestone/fitb/fitb.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def setup(app):
FITBFeedbackNode, html=(visit_fitb_feedback_node, depart_fitb_feedback_node)
)
app.add_config_value("fitb_div_class", "runestone", "html")
app.add_config_value("fitb_compare_button_show", True, "html")


class FITBNode(nodes.General, nodes.Element, RunestoneNode):
Expand Down Expand Up @@ -126,6 +127,7 @@ class FillInTheBlank(RunestoneIdDirective):
config values (conf.py):

- fitb_div_class - custom CSS class of the component's outermost div
- fitb_compare_button_show - if False, hide the 'Compare me' button (default True)
"""

required_arguments = 1
Expand All @@ -150,9 +152,15 @@ def run(self):

super(FillInTheBlank, self).run()

env = self.state.document.settings.env
if env.config.fitb_compare_button_show:
self.options['showcomparebutton'] = 'data-showcomparebutton=true'
else:
self.options['showcomparebutton'] = 'data-showcomparebutton=false'

TEMPLATE_START = """
<div class="%(divclass)s">
<div data-component="fillintheblank" id="%(divid)s">
<div data-component="fillintheblank" id="%(divid)s" %(showcomparebutton)s>
"""

TEMPLATE_END = """
Expand Down
3 changes: 2 additions & 1 deletion runestone/fitb/js/fitb.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ FITB.prototype.init = function (opts) {
this.origElem = orig;
this.divid = orig.id;
this.correct = null;
this.showcomparebutton = $(orig).data('showcomparebutton');
// See comments in fitb.py for the format of ``feedbackArray`` (which is identical in both files).
//
// Find the script tag containing JSON and parse it. See `SO <https://stackoverflow.com/questions/9320427/best-practice-for-embedding-arbitrary-json-in-the-dom>`_. If this parses to ``false``, then no feedback is available; server-side grading will be performed.
Expand Down Expand Up @@ -97,7 +98,7 @@ FITB.prototype.renderFITBButtons = function () {
this.containerDiv.appendChild(document.createElement("br"));
this.containerDiv.appendChild(document.createElement("br"));
this.containerDiv.appendChild(this.submitButton);
if (this.useRunestoneServices) {
if (this.useRunestoneServices && this.showcomparebutton) {
this.compareButton = document.createElement("button");
$(this.compareButton).attr({
"class": "btn btn-default",
Expand Down
2 changes: 1 addition & 1 deletion runestone/unittest_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def setUpModule(self):
options = Options()
options.add_argument("--window-size=1200,800")
options.add_argument("--no-sandbox")
self.driver = webdriver.Chrome(chrome_options=options) # good for development.
self.driver = webdriver.Chrome(options=options) # good for development.

# Make this accessible
global mf
Expand Down
2 changes: 2 additions & 0 deletions runestone/updateConfig/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

from .update import *
119 changes: 119 additions & 0 deletions runestone/updateConfig/test/_sources/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
==============================
Testing update-config direcive
==============================


Multiple Choice
---------------

.. mchoice:: question1
:multiple_answers:
:correct: a,b,d
:answer_a: red
:answer_b: yellow
:answer_c: black
:answer_d: green
:feedback_a: Red is a definitely on of the colors.
:feedback_b: Yes, yellow is correct.
:feedback_c: Remember the acronym...ROY G BIV. B stands for blue.
:feedback_d: Yes, green is one of the colors.

Which colors might be found in a rainbow? (choose all that are correct)





Fill in the Blank
-----------------
.. fillintheblank:: fill1

Fill in the blanks to make the following sentence: "The red car drove away."

The |blank| car drove |blank|.

- :red: Correct.
:x: Incorrect. Try 'red'.
- :away: Correct.
:x: Incorrect. Try 'away'.




.. update-config::
:set_config_option: mchoice_compare_button_show False
.. update-config::
:set_config_option: fitb_compare_button_show False


Multiple Choice
---------------

.. mchoice:: question2
:multiple_answers:
:correct: a,b,d
:answer_a: red
:answer_b: yellow
:answer_c: black
:answer_d: green
:feedback_a: Red is a definitely on of the colors.
:feedback_b: Yes, yellow is correct.
:feedback_c: Remember the acronym...ROY G BIV. B stands for blue.
:feedback_d: Yes, green is one of the colors.

Which colors might be found in a rainbow? (choose all that are correct)



Fill in the Blank
-----------------
.. fillintheblank:: fill2

Fill in the blanks to make the following sentence: "The red car drove away."

The |blank| car drove |blank|.

- :red: Correct.
:x: Incorrect. Try 'red'.
- :away: Correct.
:x: Incorrect. Try 'away'.


.. update-config::
:set_config_option: mchoice_compare_button_show True


Multiple Choice
---------------

.. mchoice:: question3
:multiple_answers:
:correct: a,b,d
:answer_a: red
:answer_b: yellow
:answer_c: black
:answer_d: green
:feedback_a: Red is a definitely on of the colors.
:feedback_b: Yes, yellow is correct.
:feedback_c: Remember the acronym...ROY G BIV. B stands for blue.
:feedback_d: Yes, green is one of the colors.


.. update-config::
:set_config_option: fitb_compare_button_show True

Fill in the Blank
-----------------
.. fillintheblank:: fill3

Fill in the blanks to make the following sentence: "The red car drove away."

The |blank| car drove |blank|.

- :red: Correct.
:x: Incorrect. Try 'red'.
- :away: Correct.
:x: Incorrect. Try 'away'.



Loading