def editor_context(self): """ Update the XBlock's XML. Args: data (dict): Data from the request; should have a value for the key 'xml' containing the XML for this XBlock. Keyword Arguments: suffix (str): Not used Returns: dict with keys 'rubric' (unicode), 'prompt' (unicode), 'title' (unicode), 'submission_start' (unicode), 'submission_due' (unicode), 'assessments (dict) """ # In the authoring GUI, date and time fields should never be null. # Therefore, we need to resolve all "default" dates to datetime objects # before displaying them in the editor. __, __, date_ranges = resolve_dates( self.start, self.due, [(self.submission_start, self.submission_due)] + [(asmnt.get('start'), asmnt.get('due')) for asmnt in self.valid_assessments], self._ ) submission_start, submission_due = date_ranges[0] assessments = self._assessments_editor_context(date_ranges[1:]) editor_assessments_order = self._editor_assessments_order_context() # Every rubric requires one criterion. If there is no criteria # configured for the XBlock, return one empty default criterion, with # an empty default option. criteria = copy.deepcopy(self.rubric_criteria_with_labels) if not criteria: criteria = self.DEFAULT_CRITERIA return { 'prompt': self.prompt, 'title': self.title, 'submission_due': submission_due, 'submission_start': submission_start, 'assessments': assessments, 'criteria': criteria, 'feedbackprompt': self.rubric_feedback_prompt, 'allow_file_upload': self.allow_file_upload, 'leaderboard_show': self.leaderboard_show, 'editor_assessments_order': [ make_django_template_key(asmnt) for asmnt in editor_assessments_order ], }
def editor_context(self): """ Update the XBlock's XML. Args: data (dict): Data from the request; should have a value for the key 'xml' containing the XML for this XBlock. Keyword Arguments: suffix (str): Not used Returns: dict with keys 'rubric' (unicode), 'prompt' (unicode), 'title' (unicode), 'submission_start' (unicode), 'submission_due' (unicode), 'assessments (dict) """ # In the authoring GUI, date and time fields should never be null. # Therefore, we need to resolve all "default" dates to datetime objects # before displaying them in the editor. __, __, date_ranges = resolve_dates( self.start, self.due, [(self.submission_start, self.submission_due)] + [(asmnt.get('start'), asmnt.get('due')) for asmnt in self.valid_assessments], self._) submission_start, submission_due = date_ranges[0] assessments = self._assessments_editor_context(date_ranges[1:]) self.editor_assessments_order = self._editor_assessments_order_context( ) # Every rubric requires one criterion. If there is no criteria # configured for the XBlock, return one empty default criterion, with # an empty default option. criteria = copy.deepcopy(self.rubric_criteria_with_labels) if not criteria: criteria = self.DEFAULT_CRITERIA # To maintain backwards compatibility, if there is no # feedback_default_text configured for the xblock, use the default text feedback_default_text = copy.deepcopy( self.rubric_feedback_default_text) if not feedback_default_text: feedback_default_text = DEFAULT_RUBRIC_FEEDBACK_TEXT course_id = self.location.course_key if hasattr(self, 'location') else None return { 'prompts': self.prompts, 'prompts_type': self.prompts_type, 'title': self.title, 'submission_due': submission_due, 'submission_start': submission_start, 'assessments': assessments, 'criteria': criteria, 'feedbackprompt': self.rubric_feedback_prompt, 'feedback_default_text': feedback_default_text, 'text_response': self.text_response if self.text_response else '', 'file_upload_response': self.file_upload_response if self.file_upload_response else '', 'necessity_options': self.NECESSITY_OPTIONS, 'file_upload_type': self.file_upload_type, 'white_listed_file_types': self.white_listed_file_types_string, 'allow_latex': self.allow_latex, 'leaderboard_show': self.leaderboard_show, 'editor_assessments_order': [ make_django_template_key(asmnt) for asmnt in self.editor_assessments_order ], 'base_asset_url': self._get_base_url_path_for_course_assets(course_id), 'is_released': self.is_released(), }
def _assessments_editor_context(self, assessment_dates): """ Transform the rubric assessments list into the context we will pass to the Django template. Args: assessment_dates: List of assessment date ranges (tuples of start/end datetimes). Returns: dict """ assessments = {} for asmnt, date_range in zip(self.rubric_assessments, assessment_dates): # Django Templates cannot handle dict keys with dashes, so we'll convert # the dashes to underscores. template_name = make_django_template_key(asmnt['name']) assessments[template_name] = copy.deepcopy(asmnt) assessments[template_name]['start'] = date_range[0] assessments[template_name]['due'] = date_range[1] # In addition to the data in the student training assessment, we need to include two additional # pieces of information: a blank context to render the empty template with, and the criteria # for each example (so we don't have any complicated logic within the template). Though this # could be accomplished within the template, we are opting to remove logic from the template. student_training_module = self.get_assessment_module( 'student-training') student_training_template = { 'answer': { 'parts': [{ 'text': '' } for prompt in self.prompts] } } criteria_list = copy.deepcopy(self.rubric_criteria_with_labels) for criterion in criteria_list: criterion['option_selected'] = "" student_training_template['criteria'] = criteria_list if student_training_module: student_training_module = update_assessments_format( [student_training_module])[0] example_list = [] # Adds each example to a modified version of the student training module dictionary. for example in student_training_module['examples']: criteria_list = copy.deepcopy(self.rubric_criteria_with_labels) # Equivalent to a Join Query, this adds the selected option to the Criterion's dictionary, so that # it can be easily referenced in the template without searching through the selected options. for criterion in criteria_list: for option_selected in example['options_selected']: if option_selected['criterion'] == criterion['name']: criterion['option_selected'] = option_selected[ 'option'] example_list.append({ 'answer': example['answer'], 'criteria': criteria_list, }) assessments['training'] = { 'examples': example_list, 'template': student_training_template } # If we don't have student training enabled, we still need to render a single (empty, or default) example else: assessments['training'] = { 'examples': [student_training_template], 'template': student_training_template } return assessments
def editor_context(self): """ Update the XBlock's XML. Returns: dict with keys 'rubric' (unicode), 'prompt' (unicode), 'title' (unicode), 'submission_start' (unicode), 'submission_due' (unicode), 'assessments (dict) """ # In the authoring GUI, date and time fields should never be null. # Therefore, we need to resolve all "default" dates to datetime objects # before displaying them in the editor. __, __, date_ranges = resolve_dates( # pylint: disable=redeclared-assigned-name self.start, self.due, [(self.submission_start, self.submission_due)] + [(asmnt.get('start'), asmnt.get('due')) for asmnt in self.valid_assessments], self._) submission_start, submission_due = date_ranges[0] assessments = self._assessments_editor_context(date_ranges[1:]) self.editor_assessments_order = self._editor_assessments_order_context( ) # Every rubric requires one criterion. If there is no criteria # configured for the XBlock, return one empty default criterion, with # an empty default option. criteria = copy.deepcopy(self.rubric_criteria_with_labels) if not criteria: criteria = self.DEFAULT_CRITERIA # To maintain backwards compatibility, if there is no # feedback_default_text configured for the xblock, use the default text feedback_default_text = copy.deepcopy( self.rubric_feedback_default_text) if not feedback_default_text: feedback_default_text = DEFAULT_RUBRIC_FEEDBACK_TEXT course_id = self.location.course_key if hasattr(self, 'location') else None # If allowed file types haven't been explicitly set, load from a preset white_listed_file_types = self.get_allowed_file_types_or_preset() white_listed_file_types_string = ','.join( white_listed_file_types) if white_listed_file_types else '' return { 'prompts': self.prompts, 'prompts_type': self.prompts_type, 'title': self.title, 'submission_due': submission_due, 'submission_start': submission_start, 'assessments': assessments, 'criteria': criteria, 'feedbackprompt': self.rubric_feedback_prompt, 'feedback_default_text': feedback_default_text, 'text_response': self.text_response if self.text_response else '', 'text_response_editor': self.text_response_editor if self.text_response_editor else 'text', 'file_upload_response': self.file_upload_response if self.file_upload_response else '', 'necessity_options': self.NECESSITY_OPTIONS, 'available_editor_options': self.AVAILABLE_EDITOR_OPTIONS, 'file_upload_type': self.file_upload_type, 'allow_multiple_files': self.allow_multiple_files, 'white_listed_file_types': white_listed_file_types_string, 'allow_latex': self.allow_latex, 'leaderboard_show': self.leaderboard_show, 'editor_assessments_order': [ make_django_template_key(asmnt) for asmnt in self.editor_assessments_order ], 'teams_feature_enabled': self.team_submissions_enabled, 'teams_enabled': self.teams_enabled, 'base_asset_url': self._get_base_url_path_for_course_assets(course_id), 'is_released': self.is_released(), 'teamsets': self.get_teamsets(course_id), 'selected_teamset_id': self.selected_teamset_id, 'show_rubric_during_response': self.show_rubric_during_response }
def editor_context(self): """ Update the XBlock's XML. Args: data (dict): Data from the request; should have a value for the key 'xml' containing the XML for this XBlock. Keyword Arguments: suffix (str): Not used Returns: dict with keys 'rubric' (unicode), 'prompt' (unicode), 'title' (unicode), 'submission_start' (unicode), 'submission_due' (unicode), 'assessments (dict) """ # In the authoring GUI, date and time fields should never be null. # Therefore, we need to resolve all "default" dates to datetime objects # before displaying them in the editor. __, __, date_ranges = resolve_dates( self.start, self.due, [(self.submission_start, self.submission_due)] + [(asmnt.get('start'), asmnt.get('due')) for asmnt in self.valid_assessments], self._ ) submission_start, submission_due = date_ranges[0] assessments = self._assessments_editor_context(date_ranges[1:]) self.editor_assessments_order = self._editor_assessments_order_context() # Every rubric requires one criterion. If there is no criteria # configured for the XBlock, return one empty default criterion, with # an empty default option. criteria = copy.deepcopy(self.rubric_criteria_with_labels) if not criteria: criteria = self.DEFAULT_CRITERIA # To maintain backwards compatibility, if there is no # feedback_default_text configured for the xblock, use the default text feedback_default_text = copy.deepcopy(self.rubric_feedback_default_text) if not feedback_default_text: feedback_default_text = DEFAULT_RUBRIC_FEEDBACK_TEXT course_id = self.location.course_key if hasattr(self, 'location') else None return { 'prompts': self.prompts, 'prompts_type': self.prompts_type, 'title': self.title, 'submission_due': submission_due, 'submission_start': submission_start, 'assessments': assessments, 'criteria': criteria, 'feedbackprompt': self.rubric_feedback_prompt, 'feedback_default_text': feedback_default_text, 'text_response': self.text_response if self.text_response else '', 'file_upload_response': self.file_upload_response if self.file_upload_response else '', 'necessity_options': self.NECESSITY_OPTIONS, 'file_upload_type': self.file_upload_type, 'white_listed_file_types': self.white_listed_file_types_string, 'allow_latex': self.allow_latex, 'leaderboard_show': self.leaderboard_show, 'editor_assessments_order': [ make_django_template_key(asmnt) for asmnt in self.editor_assessments_order ], 'base_asset_url': self._get_base_url_path_for_course_assets(course_id), 'is_released': self.is_released(), }
def _assessments_editor_context(self, assessment_dates): """ Transform the rubric assessments list into the context we will pass to the Django template. Args: assessment_dates: List of assessment date ranges (tuples of start/end datetimes). Returns: dict """ assessments = {} for asmnt, date_range in zip(self.rubric_assessments, assessment_dates): # Django Templates cannot handle dict keys with dashes, so we'll convert # the dashes to underscores. template_name = make_django_template_key(asmnt['name']) assessments[template_name] = copy.deepcopy(asmnt) assessments[template_name]['start'] = date_range[0] assessments[template_name]['due'] = date_range[1] # In addition to the data in the student training assessment, we need to include two additional # pieces of information: a blank context to render the empty template with, and the criteria # for each example (so we don't have any complicated logic within the template). Though this # could be accomplished within the template, we are opting to remove logic from the template. student_training_module = self.get_assessment_module('student-training') student_training_template = { 'answer': { 'parts': [ {'text': ''} for prompt in self.prompts ] } } criteria_list = copy.deepcopy(self.rubric_criteria_with_labels) for criterion in criteria_list: criterion['option_selected'] = "" student_training_template['criteria'] = criteria_list if student_training_module: student_training_module = update_assessments_format([student_training_module])[0] example_list = [] # Adds each example to a modified version of the student training module dictionary. for example in student_training_module['examples']: criteria_list = copy.deepcopy(self.rubric_criteria_with_labels) # Equivalent to a Join Query, this adds the selected option to the Criterion's dictionary, so that # it can be easily referenced in the template without searching through the selected options. for criterion in criteria_list: for option_selected in example['options_selected']: if option_selected['criterion'] == criterion['name']: criterion['option_selected'] = option_selected['option'] example_list.append({ 'answer': example['answer'], 'criteria': criteria_list, }) assessments['training'] = {'examples': example_list, 'template': student_training_template} # If we don't have student training enabled, we still need to render a single (empty, or default) example else: assessments['training'] = {'examples': [student_training_template], 'template': student_training_template} return assessments
def editor_context(self): """ Update the XBlock's XML. Args: data (dict): Data from the request; should have a value for the key 'xml' containing the XML for this XBlock. Keyword Arguments: suffix (str): Not used Returns: dict with keys 'rubric' (unicode), 'prompt' (unicode), 'title' (unicode), 'submission_start' (unicode), 'submission_due' (unicode), 'assessments (dict) """ # In the authoring GUI, date and time fields should never be null. # Therefore, we need to resolve all "default" dates to datetime objects # before displaying them in the editor. __, __, date_ranges = resolve_dates( self.start, self.due, [(self.submission_start, self.submission_due)] + [(asmnt.get('start'), asmnt.get('due')) for asmnt in self.valid_assessments], self._) submission_start, submission_due = date_ranges[0] assessments = self._assessments_editor_context(date_ranges[1:]) editor_assessments_order = self._editor_assessments_order_context() # Every rubric requires one criterion. If there is no criteria # configured for the XBlock, return one empty default criterion, with # an empty default option. criteria = copy.deepcopy(self.rubric_criteria_with_labels) if not criteria: criteria = self.DEFAULT_CRITERIA return { 'prompt': self.prompt, 'title': self.title, 'submission_due': submission_due, 'submission_start': submission_start, 'assessments': assessments, 'criteria': criteria, 'feedbackprompt': self.rubric_feedback_prompt, 'allow_file_upload': self.allow_file_upload, 'leaderboard_show': self.leaderboard_show, 'editor_assessments_order': [ make_django_template_key(asmnt) for asmnt in editor_assessments_order ], }