Commit 349b58bb by Braden MacDonald

Fix errors caused by abuse of display_name

parent 323d03b8
......@@ -137,9 +137,15 @@ class AnswerBlock(AnswerMixin, StepMixin, StudioEditableXBlockMixin, XBlock):
editable_fields = ('question', 'name', 'min_characters', 'weight', 'default_from')
@property
def display_name(self):
def studio_display_name(self):
return u"Question {}".format(self.step_number) if not self.lonely_step else u"Question"
def __getattribute__(self, name):
""" Provide a read-only display name without adding a display_name field to the class. """
if name == "display_name":
return self.studio_display_name
return super(AnswerBlock, self).__getattribute__(name)
@lazy
def student_input(self):
"""
......
......@@ -53,16 +53,18 @@ class ChoiceBlock(StudioEditableXBlockMixin, XBlock):
)
editable_fields = ('content', )
def __getattribute__(self, name):
"""
Provide a read-only display name without adding a display_name field to the class.
"""
if name == "display_name":
@property
def studio_display_name(self):
try:
status = self.get_parent().describe_choice_correctness(self.value)
except Exception:
status = u"Out of Context" # Parent block should implement describe_choice_correctness()
return u"Choice ({})".format(status)
def __getattribute__(self, name):
""" Provide a read-only display name without adding a display_name field to the class. """
if name == "display_name":
return self.studio_display_name
return super(ChoiceBlock, self).__getattribute__(name)
def fallback_view(self, view_name, context):
......
......@@ -62,7 +62,7 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin):
return Fragment(html)
@property
def display_name(self):
def studio_display_name(self):
if self.type == 'max_attempts_reached':
max_attempts = self.get_parent().max_attempts
return u"Message when student reaches max. # of attempts ({current_limit})".format(
......@@ -74,6 +74,12 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin):
return u"Message shown when incomplete"
return u"INVALID MESSAGE"
def __getattribute__(self, name):
""" Provide a read-only display name without adding a display_name field to the class. """
if name == "display_name":
return self.studio_display_name
return super(MentoringMessageBlock, self).__getattribute__(name)
@classmethod
def get_template(cls, template_id):
"""
......
......@@ -43,15 +43,6 @@ loader = ResourceLoader(__name__)
# Classes ###########################################################
class property_with_default(property):
"""
Decorator for creating a dynamic display_name property that looks like an XBlock field. This
is needed for Studio container page blocks as studio will try to read
BlockClass.display_name.default
"""
default = u"Question"
class QuestionnaireAbstractBlock(StudioEditableXBlockMixin, StudioContainerXBlockMixin, StepMixin, XBlock):
"""
An abstract class used for MCQ/MRQ blocks
......@@ -114,10 +105,16 @@ class QuestionnaireAbstractBlock(StudioEditableXBlockMixin, StudioContainerXBloc
return block
@property_with_default
def display_name(self):
@property
def studio_display_name(self):
return u"Question {}".format(self.step_number) if not self.lonely_step else u"Question"
def __getattribute__(self, name):
""" Provide a read-only display name without adding a display_name field to the class. """
if name == "display_name":
return self.studio_display_name
return super(QuestionnaireAbstractBlock, self).__getattribute__(name)
def student_view(self, context=None):
name = getattr(self, "unmixed_class", self.__class__).__name__
......
......@@ -54,7 +54,7 @@ class TipBlock(StudioEditableXBlockMixin, XBlock):
editable_fields = ('values', 'content', 'width', 'height')
@property
def display_name(self):
def studio_display_name(self):
values_list = []
for entry in self.get_parent().human_readable_choices:
if entry["value"] in self.values:
......@@ -64,6 +64,12 @@ class TipBlock(StudioEditableXBlockMixin, XBlock):
values_list.append(display_name)
return u"Tip for {}".format(u", ".join(values_list))
def __getattribute__(self, name):
""" Provide a read-only display name without adding a display_name field to the class. """
if name == "display_name":
return self.studio_display_name
return super(TipBlock, self).__getattribute__(name)
def fallback_view(self, view_name, context):
html = ResourceLoader(__name__).render_template("templates/html/tip.html", {
'content': self.content,
......
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