|
| 1 | +# ********************************* |
| 2 | +# |docname| - An Group Submissions |
| 3 | +# ********************************* |
| 4 | +# |
| 5 | +# This directive lets you specify a question by random selection |
| 6 | +# Given a list of question ids, it will randomly select one of those ids |
| 7 | +# to present to the student. |
| 8 | +# given a competency it will select a random question from all questions that |
| 9 | +# test for that competency. |
| 10 | + |
| 11 | +# Copyright (C) 2021 Runestone Interactive LLC |
| 12 | +# |
| 13 | +# This program is free software: you can redistribute it and/or modify |
| 14 | +# it under the terms of the GNU General Public License as published by |
| 15 | +# the Free Software Foundation, either version 3 of the License, or |
| 16 | +# (at your option) any later version. |
| 17 | +# |
| 18 | +# This program is distributed in the hope that it will be useful, |
| 19 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | +# GNU General Public License for more details. |
| 22 | +# |
| 23 | +# You should have received a copy of the GNU General Public License |
| 24 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 25 | +# |
| 26 | + |
| 27 | +__author__ = "bmiller" |
| 28 | + |
| 29 | +# Imports from standard libarary |
| 30 | +# ------------------------------ |
| 31 | + |
| 32 | +# Imports from third party libraries |
| 33 | +# ---------------------------------- |
| 34 | +from docutils import nodes |
| 35 | +from docutils.parsers.rst import directives |
| 36 | + |
| 37 | +# local imports |
| 38 | +# ------------- |
| 39 | +from runestone.server.componentdb import ( |
| 40 | + addQuestionToDB, |
| 41 | + addHTMLToDB, |
| 42 | + maybeAddToAssignment, |
| 43 | +) |
| 44 | +from runestone.common.runestonedirective import ( |
| 45 | + RunestoneDirective, |
| 46 | +) |
| 47 | + |
| 48 | + |
| 49 | +TEMPLATE = """ |
| 50 | +<div class="runestone alert alert-warning sqcontainer"> |
| 51 | + <div data-component="groupsub" id={component_id} {size_limit}> |
| 52 | + <div class="col-sm-3"> |
| 53 | + <select id="assignment_group" multiple class="assignment_partner_select" style="width: 100%"> |
| 54 | + </select> |
| 55 | + </div> |
| 56 | + </div> |
| 57 | +</div> |
| 58 | +""" |
| 59 | + |
| 60 | + |
| 61 | +def setup(app): |
| 62 | + app.add_directive("groupsub", GroupSubmission) |
| 63 | + |
| 64 | + |
| 65 | +class GroupSubmission(RunestoneDirective): |
| 66 | + """ |
| 67 | + .. groupsub:: uniqueid |
| 68 | + :limit: int |
| 69 | + :question_list: |
| 70 | +
|
| 71 | + For a POGIL or groupwork page to allow one partner to submit answers |
| 72 | + to all questions on the page for everyone in the group. |
| 73 | + Question list is an anticipated extension that will allow the author |
| 74 | + to specify a list of questions rather than assuming all. |
| 75 | + """ |
| 76 | + |
| 77 | + required_arguments = 1 |
| 78 | + optional_arguments = 1 |
| 79 | + has_content = False |
| 80 | + option_spec = RunestoneDirective.option_spec.copy() |
| 81 | + option_spec.update( |
| 82 | + { |
| 83 | + "limit": directives.unchanged, |
| 84 | + } |
| 85 | + ) |
| 86 | + |
| 87 | + def __init__(self, *args, **kwargs): |
| 88 | + super().__init__(*args, **kwargs) |
| 89 | + |
| 90 | + def run(self): |
| 91 | + |
| 92 | + self.options["component_id"] = self.arguments[0].strip() |
| 93 | + |
| 94 | + if "limit" in self.options: |
| 95 | + self.options["size_limit"] = f"size_limit={self.options['limit']}" |
| 96 | + else: |
| 97 | + self.options["size_limit"] = f"size_limit=4" |
| 98 | + |
| 99 | + res = TEMPLATE.format(**self.options) |
| 100 | + |
| 101 | + return [nodes.raw(self.block_text, res, format="html")] |
0 commit comments