示例#1
0
    def calculate_results(self, submissions):
        score = 0
        results = []
        tips = None

        if not self.hide_results:
            tips = self.get_tips()

        for choice in self.custom_choices:
            choice_completed = True
            choice_tips_html = []
            choice_selected = choice.value in submissions

            if choice.value in self.required_choices:
                if not choice_selected:
                    choice_completed = False
            elif choice_selected and choice.value not in self.ignored_choices:
                choice_completed = False

            if choice_completed:
                score += 1

            choice_result = {
                'value': choice.value,
                'selected': choice_selected,
                'content': choice.content
            }
            # Only include tips/results in returned response if we want to display them
            if not self.hide_results:
                # choice_tips_html list is being set only when 'self.hide_results' is False, to optimize,
                # execute the loop only when 'self.hide_results' is set to False
                for tip in tips:
                    if choice.value in tip.values:
                        choice_tips_html.append(tip.render('mentoring_view').content)
                        break

                loader = ResourceLoader(__name__)
                choice_result['completed'] = choice_completed
                choice_result['tips'] = loader.render_template('templates/html/tip_choice_group.html', {
                    'tips_html': choice_tips_html,
                })

            results.append(choice_result)

        status = 'incorrect' if score <= 0 else 'correct' if score >= len(results) else 'partial'

        if sub_api:
            # Send the answer as a concatenated list to the submissions API
            answer = [choice['content'] for choice in results if choice['selected']]
            sub_api.create_submission(self.student_item_key, ', '.join(answer))

        return {
            'submissions': submissions,
            'status': status,
            'choices': results,
            'message': self.message_formatted,
            'weight': self.weight,
            'score': (float(score) / len(results)) if results else 0,
        }
示例#2
0
    def calculate_results(self, submissions):
        score = 0
        results = []

        for choice in self.custom_choices:
            choice_completed = True
            choice_tips_html = []
            choice_selected = choice.value in submissions

            if choice.value in self.required_choices:
                if not choice_selected:
                    choice_completed = False
            elif choice_selected and choice.value not in self.ignored_choices:
                choice_completed = False
            for tip in self.get_tips():
                if choice.value in tip.values:
                    choice_tips_html.append(
                        tip.render('mentoring_view').content)

            if choice_completed:
                score += 1

            choice_result = {
                'value': choice.value,
                'selected': choice_selected,
                'content': choice.content
            }
            # Only include tips/results in returned response if we want to display them
            if not self.hide_results:
                loader = ResourceLoader(__name__)
                choice_result['completed'] = choice_completed
                choice_result['tips'] = loader.render_template(
                    'templates/html/tip_choice_group.html', {
                        'tips_html': choice_tips_html,
                    })

            results.append(choice_result)

        status = 'incorrect' if score <= 0 else 'correct' if score >= len(
            results) else 'partial'

        if sub_api:
            # Send the answer as a concatenated list to the submissions API
            answer = [
                choice['content'] for choice in results if choice['selected']
            ]
            sub_api.create_submission(self.student_item_key, ', '.join(answer))

        return {
            'submissions': submissions,
            'status': status,
            'choices': results,
            'message': self.message_formatted,
            'weight': self.weight,
            'score': (float(score) / len(results)) if results else 0,
        }
示例#3
0
    def calculate_results(self, submissions):
        score = 0
        results = []

        for choice in self.custom_choices:
            choice_completed = True
            choice_tips_html = []
            choice_selected = choice.value in submissions

            if choice.value in self.required_choices:
                if not choice_selected:
                    choice_completed = False
            elif choice_selected and choice.value not in self.ignored_choices:
                choice_completed = False
            for tip in self.get_tips():
                if choice.value in tip.values:
                    choice_tips_html.append(tip.render('mentoring_view').content)

            if choice_completed:
                score += 1

            choice_result = {
                'value': choice.value,
                'selected': choice_selected,
                }
            # Only include tips/results in returned response if we want to display them
            if not self.hide_results:
                loader = ResourceLoader(__name__)
                choice_result['completed'] = choice_completed
                choice_result['tips'] = loader.render_template('templates/html/tip_choice_group.html', {
                    'tips_html': choice_tips_html,
                    })

            results.append(choice_result)

        status = 'incorrect' if score <= 0 else 'correct' if score >= len(results) else 'partial'

        return {
            'submissions': submissions,
            'status': status,
            'choices': results,
            'message': self.message,
            'weight': self.weight,
            'score': (float(score) / len(results)) if results else 0,
        }
示例#4
0
 def test_render_template(self):
     loader = ResourceLoader(__name__)
     s = loader.render_template("data/simple_django_template.txt", example_context)
     self.assertEquals(s, expected_filled_template)
示例#5
0
 def test_render_template_deprecated(self, mock_warn):
     loader = ResourceLoader(__name__)
     s = loader.render_template("data/simple_django_template.txt",
                                example_context)
     self.assertTrue(mock_warn.called)
     self.assertEqual(s, expected_filled_template)
 def test_render_template_deprecated(self, mock_warn):
     loader = ResourceLoader(__name__)
     s = loader.render_template("data/simple_django_template.txt", example_context)
     self.assertTrue(mock_warn.called)
     self.assertEquals(s, expected_filled_template)
示例#7
0
 def test_render_template(self):
     loader = ResourceLoader(__name__)
     s = loader.render_template("data/simple_django_template.txt",
                                example_context)
     self.assertEquals(s, expected_filled_template)