Commit 238beb41 by Xavier Antoviaque

Add <answer default_from="answer_name"> feature & load page 3

parent 6437809f
......@@ -6,7 +6,7 @@
import logging
from xblock.core import XBlock
from xblock.fields import Any, Boolean, Scope
from xblock.fields import Any, Boolean, Scope, String
from xblock.fragment import Fragment
from .models import Answer
......@@ -29,12 +29,19 @@ class AnswerBlock(XBlock):
"""
student_input = Any(help="Last input submitted by the student", default="", scope=Scope.user_state)
read_only = Boolean(help="Display as a read-only field", default=False, scope=Scope.content)
default_from = String(help="If specified, the name of the answer to get the default value from", default=None, scope=Scope.content)
def __init__(self, *args, **kwargs):
super(AnswerBlock, self).__init__(*args, **kwargs)
# Only attempt to locate a model object for this block when the answer has a name
if self.name:
self.student_input = self.get_model_object().student_input
# Default value can be set from another answer's current value
if not self.student_input and self.default_from:
self.student_input = self.get_model_object(name=self.default_from).student_input
def student_view(self, context=None): # pylint: disable=W0613
"""Returns default student view."""
return Fragment(u"<p>I can only appear inside problems.</p>")
......@@ -69,8 +76,15 @@ class AnswerBlock(XBlock):
answer_data.student_input = self.student_input
answer_data.save()
def get_model_object(self):
if not self.name:
def get_model_object(self, name=None):
"""
Fetches the Answer model object for the answer named `name`
"""
# By default, get the model object for the current answer's name
if not name:
name = self.name
# Consistency check - we should have a name by now
if not name:
raise ValueError, 'AnswerBlock.name field need to be set to a non-null/empty value'
# TODO Use a random user id
......@@ -78,6 +92,6 @@ class AnswerBlock(XBlock):
answer_data, created = Answer.objects.get_or_create(
student_id=student_id,
name=self.name
name=name
)
return answer_data
......@@ -106,6 +106,10 @@ class MentoringBlock(XBlock):
Sample scenarios which will be displayed in the workbench
"""
return [
("Mentoring: Pre-Goal Brainstom", load_resource('templates/001_pre_goal_brainstorm.xml')),
("Mentoring: Getting Feedback", load_resource('templates/002_getting_feedback.xml')),
("Mentoring - Page 1, Pre-goal brainstom",
load_resource('templates/001_pre_goal_brainstorm.xml')),
("Mentoring - Page 2, Getting feedback",
load_resource('templates/002_getting_feedback.xml')),
("Mentoring - Page 3, Reflecting on your feedback",
load_resource('templates/003_reflecting_on_feedback.xml')),
]
......@@ -7,6 +7,6 @@ class Answer(models.Model):
name = models.CharField(max_length=20, db_index=True)
student_id = models.CharField(max_length=20, db_index=True)
student_input = models.CharField(max_length=10000)
student_input = models.CharField(max_length=10000, blank=True, default='')
created_on = models.DateTimeField('created on', auto_now_add=True)
modified_on = models.DateTimeField('modified on', auto_now=True)
......@@ -5,6 +5,6 @@
<p>Now that you have received feedback from others, would you like to revise your brainstorm list? Which goals are the most interesting to you now? Which goals are you most considering pursuing?</p>
</html>
<answer name="brainstorm_goals2" default-from="brainstorm_goals" />
<answer name="brainstorm_goals2" default_from="brainstorm_goals" />
</mentoring>
</vertical>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment