Commit 238beb41 by Xavier Antoviaque

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

parent 6437809f
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import logging import logging
from xblock.core import XBlock 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 xblock.fragment import Fragment
from .models import Answer from .models import Answer
...@@ -29,11 +29,18 @@ class AnswerBlock(XBlock): ...@@ -29,11 +29,18 @@ class AnswerBlock(XBlock):
""" """
student_input = Any(help="Last input submitted by the student", default="", scope=Scope.user_state) 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) 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): def __init__(self, *args, **kwargs):
super(AnswerBlock, self).__init__(*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: if self.name:
self.student_input = self.get_model_object().student_input 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 def student_view(self, context=None): # pylint: disable=W0613
"""Returns default student view.""" """Returns default student view."""
...@@ -69,8 +76,15 @@ class AnswerBlock(XBlock): ...@@ -69,8 +76,15 @@ class AnswerBlock(XBlock):
answer_data.student_input = self.student_input answer_data.student_input = self.student_input
answer_data.save() answer_data.save()
def get_model_object(self): def get_model_object(self, name=None):
if not self.name: """
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' raise ValueError, 'AnswerBlock.name field need to be set to a non-null/empty value'
# TODO Use a random user id # TODO Use a random user id
...@@ -78,6 +92,6 @@ class AnswerBlock(XBlock): ...@@ -78,6 +92,6 @@ class AnswerBlock(XBlock):
answer_data, created = Answer.objects.get_or_create( answer_data, created = Answer.objects.get_or_create(
student_id=student_id, student_id=student_id,
name=self.name name=name
) )
return answer_data return answer_data
...@@ -106,6 +106,10 @@ class MentoringBlock(XBlock): ...@@ -106,6 +106,10 @@ class MentoringBlock(XBlock):
Sample scenarios which will be displayed in the workbench Sample scenarios which will be displayed in the workbench
""" """
return [ return [
("Mentoring: Pre-Goal Brainstom", load_resource('templates/001_pre_goal_brainstorm.xml')), ("Mentoring - Page 1, Pre-goal brainstom",
("Mentoring: Getting Feedback", load_resource('templates/002_getting_feedback.xml')), 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): ...@@ -7,6 +7,6 @@ class Answer(models.Model):
name = models.CharField(max_length=20, db_index=True) name = models.CharField(max_length=20, db_index=True)
student_id = 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) created_on = models.DateTimeField('created on', auto_now_add=True)
modified_on = models.DateTimeField('modified on', auto_now=True) modified_on = models.DateTimeField('modified on', auto_now=True)
...@@ -5,6 +5,6 @@ ...@@ -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> <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> </html>
<answer name="brainstorm_goals2" default-from="brainstorm_goals" /> <answer name="brainstorm_goals2" default_from="brainstorm_goals" />
</mentoring> </mentoring>
</vertical> </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