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): ...@@ -137,9 +137,15 @@ class AnswerBlock(AnswerMixin, StepMixin, StudioEditableXBlockMixin, XBlock):
editable_fields = ('question', 'name', 'min_characters', 'weight', 'default_from') editable_fields = ('question', 'name', 'min_characters', 'weight', 'default_from')
@property @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" 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 @lazy
def student_input(self): def student_input(self):
""" """
......
...@@ -53,16 +53,18 @@ class ChoiceBlock(StudioEditableXBlockMixin, XBlock): ...@@ -53,16 +53,18 @@ class ChoiceBlock(StudioEditableXBlockMixin, XBlock):
) )
editable_fields = ('content', ) editable_fields = ('content', )
@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): def __getattribute__(self, name):
""" """ Provide a read-only display name without adding a display_name field to the class. """
Provide a read-only display name without adding a display_name field to the class.
"""
if name == "display_name": if name == "display_name":
try: return self.studio_display_name
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)
return super(ChoiceBlock, self).__getattribute__(name) return super(ChoiceBlock, self).__getattribute__(name)
def fallback_view(self, view_name, context): def fallback_view(self, view_name, context):
......
...@@ -62,7 +62,7 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin): ...@@ -62,7 +62,7 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin):
return Fragment(html) return Fragment(html)
@property @property
def display_name(self): def studio_display_name(self):
if self.type == 'max_attempts_reached': if self.type == 'max_attempts_reached':
max_attempts = self.get_parent().max_attempts max_attempts = self.get_parent().max_attempts
return u"Message when student reaches max. # of attempts ({current_limit})".format( return u"Message when student reaches max. # of attempts ({current_limit})".format(
...@@ -74,6 +74,12 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin): ...@@ -74,6 +74,12 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin):
return u"Message shown when incomplete" return u"Message shown when incomplete"
return u"INVALID MESSAGE" 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 @classmethod
def get_template(cls, template_id): def get_template(cls, template_id):
""" """
......
...@@ -43,15 +43,6 @@ loader = ResourceLoader(__name__) ...@@ -43,15 +43,6 @@ loader = ResourceLoader(__name__)
# Classes ########################################################### # 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): class QuestionnaireAbstractBlock(StudioEditableXBlockMixin, StudioContainerXBlockMixin, StepMixin, XBlock):
""" """
An abstract class used for MCQ/MRQ blocks An abstract class used for MCQ/MRQ blocks
...@@ -114,10 +105,16 @@ class QuestionnaireAbstractBlock(StudioEditableXBlockMixin, StudioContainerXBloc ...@@ -114,10 +105,16 @@ class QuestionnaireAbstractBlock(StudioEditableXBlockMixin, StudioContainerXBloc
return block return block
@property_with_default @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" 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): def student_view(self, context=None):
name = getattr(self, "unmixed_class", self.__class__).__name__ name = getattr(self, "unmixed_class", self.__class__).__name__
......
...@@ -54,7 +54,7 @@ class TipBlock(StudioEditableXBlockMixin, XBlock): ...@@ -54,7 +54,7 @@ class TipBlock(StudioEditableXBlockMixin, XBlock):
editable_fields = ('values', 'content', 'width', 'height') editable_fields = ('values', 'content', 'width', 'height')
@property @property
def display_name(self): def studio_display_name(self):
values_list = [] values_list = []
for entry in self.get_parent().human_readable_choices: for entry in self.get_parent().human_readable_choices:
if entry["value"] in self.values: if entry["value"] in self.values:
...@@ -64,6 +64,12 @@ class TipBlock(StudioEditableXBlockMixin, XBlock): ...@@ -64,6 +64,12 @@ class TipBlock(StudioEditableXBlockMixin, XBlock):
values_list.append(display_name) values_list.append(display_name)
return u"Tip for {}".format(u", ".join(values_list)) 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): def fallback_view(self, view_name, context):
html = ResourceLoader(__name__).render_template("templates/html/tip.html", { html = ResourceLoader(__name__).render_template("templates/html/tip.html", {
'content': self.content, '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