Commit d2577cd2 by Xavier Antoviaque

Use lazy attribute instead of unsupported __init__() on answer block

parent 972015f8
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import logging import logging
from lazy import lazy
from xblock.core import XBlock from xblock.core import XBlock
from xblock.fields import Boolean, Scope, String from xblock.fields import Boolean, Scope, String
from xblock.fragment import Fragment from xblock.fragment import Fragment
...@@ -27,22 +29,28 @@ class AnswerBlock(XBlock): ...@@ -27,22 +29,28 @@ class AnswerBlock(XBlock):
Must be included as a child of a mentoring block. Answers are persisted as django model instances Must be included as a child of a mentoring block. Answers are persisted as django model instances
to make them searchable and referenceable across xblocks. to make them searchable and referenceable across xblocks.
""" """
student_input = String(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_from = String(help="If specified, the name of the answer to get the default value from",
default=None, scope=Scope.content) default=None, scope=Scope.content)
def __init__(self, *args, **kwargs): @lazy
super(AnswerBlock, self).__init__(*args, **kwargs) def student_input(self):
"""
Use lazy property instead of XBlock field, as __init__() doesn't support
overwriting field values
"""
student_input = ''
# Only attempt to locate a model object for this block when the answer has a name # 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 student_input = self.get_model_object().student_input
# Default value can be set from another answer's current value # Default value can be set from another answer's current value
if not self.student_input and self.default_from: if not student_input and self.default_from:
self.student_input = self.get_model_object(name=self.default_from).student_input student_input = self.get_model_object(name=self.default_from).student_input
return 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."""
return Fragment(u"<p>I can only appear inside mentoring blocks.</p>") return Fragment(u"<p>I can only appear inside mentoring blocks.</p>")
......
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