コード例 #1
0
def explanation_role(name, rawtext, text, lineno, inliner, options={},
                     content=[]):
    """
    Function executed with the role :expl: is parsed
    """
    # Unused parameters
    del name, rawtext, lineno, content

    # This role has only effect when in HTML mode.
    if inliner.document.settings.env.app.builder.format != 'html':
        return

    # Get the question type (if none, raise an exception).
    config = inliner.document.settings.env.config
    question_type = config.config_values.get('eqt-question-type')
    if question_type is None:
        raise ValueError(
            'Role :expl: must appear inside an embedded question.')

    # Get the relative path to the static directory
    p_to_static = common.get_relative_path_to_static(inliner.document)

    return [
        Explanation(args=options, content=text, p_to_static=p_to_static)
    ], []
コード例 #2
0
def eqt_answer(name, rawtext, text, lineno, inliner, options={}, content=[]):
    """
    Function executed with the role :eqt:`???` is parsed
    """

    # This role has only effect when in HTML mode.
    if inliner.document.settings.env.app.builder.format != 'html':
        return

    # Get the question type (if none, raise an exception).
    config = inliner.document.settings.env.config
    question_type = config.config_values.get('eqt-question-type')
    if question_type == None:
        raise ValueError('Role :eqt: must appear inside an embedded question.')

    # Single answer MCQ
    if question_type == 'eqt':
        # The value of the role can only be C or I (correct or incorrect)
        if text != 'C' and text != 'I':
            raise ValueError('Role text must be "C" or "I"')

    # Get the relative path to the static directory
    p_to_static = common.get_relative_path_to_static(inliner.document)

    return [
        eqt_answer_type(args=options,
                        type=question_type,
                        content=text,
                        p_to_static=p_to_static)
    ], []
コード例 #3
0
ファイル: eqt.py プロジェクト: victerryso/flip_the_mrs
def eqt_answer(name, rawtext, text, lineno, inliner,
                      options={}, content=[]):

    """
    Function executed with the role :eqt:`???` is parsed
    """

    # This role has only effect when in HTML mode.
    if inliner.document.settings.env.app.builder.format != 'html':
        return

    # Get the question type (if none, raise an exception).
    config = inliner.document.settings.env.config
    question_type = config.config_values.get('eqt-question-type')
    if question_type == None:
        raise ValueError('Role :eqt: must appear inside an embedded question.')

    # Single answer MCQ
    if question_type == 'eqt':
        # The value of the role can only be C or I (correct or incorrect)
        if text != 'C' and text != 'I':
            raise ValueError('Role text must be "C" or "I"')

    # Get the relative path to the static directory
    p_to_static = common.get_relative_path_to_static(inliner.document)

    return [eqt_answer_type(args = options,
                                   type = question_type,
                                   content = text,
                                   p_to_static = p_to_static)], []
コード例 #4
0
    def run(self):
        config = self.state.document.settings.env.config

        # Get the labels
        title = common.get_parameter_value(config, self.options, 'title',
                                           "xy_click_title", False)
        top_label = common.get_parameter_value(config, self.options, 'top',
                                               "xy_click_top_label", False)
        bottom_label = common.get_parameter_value(config, self.options,
                                                  'bottom',
                                                  "xy_click_bottom_label",
                                                  False)
        left_label = common.get_parameter_value(config, self.options, 'left',
                                                "xy_click_left_label", False)
        right_label = common.get_parameter_value(config, self.options, 'right',
                                                 "xy_click_right_label", False)

        # Get the size
        grid_size = common.get_parameter_value(config, self.options, 'size',
                                               "xy_click_grid_size", False)

        # Get the path to the static directory containing the images
        p_to_static = common.get_relative_path_to_static(self.state.document)

        return [
            XyClickNode(args=self.arguments,
                        title=title,
                        top_label=top_label,
                        bottom_label=bottom_label,
                        left_label=left_label,
                        right_label=right_label,
                        size=grid_size,
                        p_to_static=p_to_static)
        ]
コード例 #5
0
    def run(self):
        config = self.state.document.settings.env.config

        # Phrase to prefix the value
        phrase = common.get_parameter_value(config, self.options, 'phrase',
                                            "activity_duration_phrase", False)

        # Get the path to the static directory containing the images
        p_to_static = common.get_relative_path_to_static(self.state.document)

        return [activity_duration(args = self.arguments,
                                  phrase = phrase,
                                  p_to_static = p_to_static)]
コード例 #6
0
    def run(self):
        # Raise an error if the directive does not have contents.
        self.assert_has_content()

        config = self.state.document.settings.env.config

        if config.config_values.get('eqt_question_type') is not None:
            raise ValueError("Embedded questions cannot be nested.")

        # Store the type of question in an additional attribute in the
        # environment.
        config.config_values['eqt-question-type'] = self.name

        p_to_static = common.get_relative_path_to_static(self.state.document)
        result = Eqt(args=self.arguments,
                     name=self.name,
                     p_to_static=p_to_static)

        # Parse the nested content
        self.state.nested_parse(self.content, self.content_offset, result)

        # Remove the question type from the environment
        del config.config_values['eqt-question-type']

        # If the question is a single MCQ, check that there is an enumerated
        # list and perform some additional tasks.
        if self.name == "eqt" or self.name == "eqt-mc":
            # Loop over the question children to detect which one corresponds to
            # the list of answers and add some additional attributes
            answer_list_node = None
            for question_child in result.children:
                if question_child.__class__.__name__ != 'enumerated_list':
                    continue

                # Try ot obtain the eqt_answer_type. If it fails, we are
                # processing a regular node so we keep processing children
                name = question_child.children[0].children[0].children[
                    0].__class__.__name__
                if name == 'EqtAnswerType':
                    answer_list_node = question_child
                    break

            if answer_list_node is not None:
                answer_list_node['enumtype'] = answer_list_node['enumtype'] +\
                    ' eqt-answer-list'
            else:
                raise ValueError('No answer list found in e-question.')

        return [result]
コード例 #7
0
    def run(self):
        config = self.state.document.settings.env.config

        # Phrase to prefix the value
        phrase = common.get_parameter_value(config, self.options, 'phrase',
                                            "activity_duration_phrase", False)

        # Get the path to the static directory containing the images
        p_to_static = common.get_relative_path_to_static(self.state.document)

        return [
            activity_duration(args=self.arguments,
                              phrase=phrase,
                              p_to_static=p_to_static)
        ]
コード例 #8
0
ファイル: eqt.py プロジェクト: victerryso/flip_the_mrs
    def run(self):
        # Raise an error if the directive does not have contents.
        self.assert_has_content()

        config = self.state.document.settings.env.config

        if config.config_values.get('eqt_question_type') != None:
            raise ValueError("Embedded questions cannot be nested.")

        # Store the type of question in an additional attribute in the
        # environment.
        config.config_values['eqt-question-type'] = self.name

        result = eqt(args = self.arguments, name = self.name,
                     p_to_static =
                     common.get_relative_path_to_static(self.state.document))

        # Parse the nested content
        self.state.nested_parse(self.content, self.content_offset, result)

        # Remove the question type from the environment
        del config.config_values['eqt-question-type']

        # If the question is a single MCQ, check that there is an enumerated
        # list and perform some additional tasks.
        if self.name == "eqt" or self.name == "eqt-mc":
            # Loop over the question children to detect which one corresponds to
            # the list of answers and add some additional attributes
            answer_list_node = None
            for question_child in result.children:
                if question_child.__class__.__name__ != 'enumerated_list':
                    continue

                # Try ot obtain the eqt_answer_type. If it fails, we are
                # processing a regular node so we keep processing children
                name = question_child.children[0].children[0].children[0].__class__.__name__
                if name == 'eqt_answer_type':
                    answer_list_node = question_child
                    break

            if answer_list_node != None:
                answer_list_node['enumtype'] = answer_list_node['enumtype'] + \
                                               ' eqt-answer-list'
            else:
                raise ValueError('No answer list found in e-question.')

        return [result]
コード例 #9
0
ファイル: html_form.py プロジェクト: victerryso/flip_the_mrs
    def run(self):
        config = self.state.document.settings.env.config

        # Submit button text
        button_name = common.get_parameter_value(
            config, self.options, "button_name", "html_form_submit_button_name", False
        )

        # Get the path to the static directory containing the images
        p_to_static = common.get_relative_path_to_static(self.state.document)

        new_node = html_form(args=self.arguments, button_name=button_name, p_to_static=p_to_static)

        # Parse the nested content
        self.state.nested_parse(self.content, self.content_offset, new_node)

        return [new_node]
コード例 #10
0
    def run(self):
        config = self.state.document.settings.env.config

        # Submit button text
        button_name = \
            common.get_parameter_value(config,
                                       self.options,
                                       'button_name',
                                       "instructor_feedback_submit_button_name",
                                       False)

        # Number of rows and columns in the text area
        rows = common.get_parameter_value(config, self.options, 'rows',
                                          "instructor_feedback_rows", False)

        columns = common.get_parameter_value(config, self.options, 'columns',
                                             "instructor_feedback_columns",
                                             False)

        # Get the path to the static directory containing the images
        p_to_static = common.get_relative_path_to_static(self.state.document)

        # Text to include in the form
        text = common.get_parameter_value(config, self.options, 'text',
                                          "instructor_feedback_text", False)

        # Create the form node
        result = html_form.html_form(args=self.arguments,
                                     button_name=button_name,
                                     p_to_static=p_to_static)

        # Add an input field containing the event-name
        result += html_form.html_input(args=['event-name'],
                                       el_type='hidden',
                                       checked='',
                                       maxlength='',
                                       value='instructor-session-feedback')

        # And the default text.
        result += html_form.html_textarea(args=["msg"],
                                          rows=rows,
                                          columns=columns,
                                          text=text)
        return [result]
コード例 #11
0
    def run(self):
        config = self.state.document.settings.env.config

        # Submit button text
        button_name = \
            common.get_parameter_value(config, 
                                       self.options, 
                                       'button_name',
                                       "instructor_feedback_submit_button_name",
                                       False)

        # Number of rows and columns in the text area
        rows = common.get_parameter_value(config, self.options, 'rows',
                                   "instructor_feedback_rows", False)

        columns = common.get_parameter_value(config, self.options, 'columns',
                                   "instructor_feedback_columns", False)
        
        # Get the path to the static directory containing the images
        p_to_static = common.get_relative_path_to_static(self.state.document)

        # Text to include in the form
        text = common.get_parameter_value(config, self.options, 'text', 
                                   "instructor_feedback_text", False)
        
        # Create the form node
        result = html_form.html_form(args = self.arguments, 
                                     button_name = button_name,
                                     p_to_static = p_to_static)
        
        # Add an input field containing the event-name
        result += html_form.html_input(args = ['event-name'], 
                                       el_type = 'hidden', 
                                       checked = '',
                                       maxlength = '',
                                       value = 'instructor-session-feedback')

        # And the default text.
        result += html_form.html_textarea(args = ["msg"], 
                                          rows = rows, 
                                          columns = columns, text = text)
        return [result]
コード例 #12
0
    def run(self):
        rows = self.options.get('rows', 25)
        columns = self.options.get('columns', 80)
        options = self.options.get('options', '')
        other_params = self.options.get('other_params', '')

        # Get the path to the static directory containing the images
        p_to_static = common.get_relative_path_to_static(self.state.document)

        result = Question(args=self.arguments,
                          name=self.name,
                          rows=rows,
                          columns=columns,
                          options=[x for x in options.split(',') if x != ''],
                          other_params=other_params,
                          p_to_static=p_to_static)
 
        # Parse the nested content
        self.state.nested_parse(self.content, self.content_offset, result)

        return [result]
コード例 #13
0
    def run(self):
        config = self.state.document.settings.env.config

        # Submit button text
        button_name = \
            common.get_parameter_value(config,
                                       self.options,
                                       'button_name',
                                       "html_form_submit_button_name",
                                       False)

        # Get the path to the static directory containing the images
        p_to_static = common.get_relative_path_to_static(self.state.document)

        new_node = html_form(args=self.arguments,
                             button_name=button_name,
                             p_to_static=p_to_static)

        # Parse the nested content
        self.state.nested_parse(self.content, self.content_offset, new_node)

        return [new_node]