Commit cda7fd0d by Braden MacDonald

Clean up display_name hack - fix to Studio submitted upstream

parent 67048650
...@@ -144,17 +144,11 @@ class AnswerBlock(AnswerMixin, StepMixin, StudioEditableXBlockMixin, XBlock): ...@@ -144,17 +144,11 @@ 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 studio_display_name(self): def display_name_with_default(self):
if not self.lonely_step: if not self.lonely_step:
return self._(u"Question {number}").format(number=self.step_number) return self._(u"Question {number}").format(number=self.step_number)
return self._(u"Question") return self._(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):
""" """
......
...@@ -61,19 +61,13 @@ class ChoiceBlock(StudioEditableXBlockMixin, XBlock): ...@@ -61,19 +61,13 @@ class ChoiceBlock(StudioEditableXBlockMixin, XBlock):
return self.runtime.service(self, "i18n").ugettext(text) return self.runtime.service(self, "i18n").ugettext(text)
@property @property
def studio_display_name(self): def display_name_with_default(self):
try: try:
status = self.get_parent().describe_choice_correctness(self.value) status = self.get_parent().describe_choice_correctness(self.value)
except Exception: except Exception:
status = self._(u"Out of Context") # Parent block should implement describe_choice_correctness() status = self._(u"Out of Context") # Parent block should implement describe_choice_correctness()
return self._(u"Choice ({status})").format(status=status) return self._(u"Choice ({status})").format(status=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): def fallback_view(self, view_name, context):
return Fragment(u'<span class="choice-text">{}</span>'.format(self.content)) return Fragment(u'<span class="choice-text">{}</span>'.format(self.content))
......
...@@ -69,7 +69,7 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin): ...@@ -69,7 +69,7 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin):
return Fragment(html) return Fragment(html)
@property @property
def studio_display_name(self): def display_name_with_default(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 self._(u"Message when student reaches max. # of attempts ({limit})").format( return self._(u"Message when student reaches max. # of attempts ({limit})").format(
...@@ -81,12 +81,6 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin): ...@@ -81,12 +81,6 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin):
return self._(u"Message shown when incomplete") return self._(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):
""" """
......
...@@ -114,17 +114,11 @@ class QuestionnaireAbstractBlock(StudioEditableXBlockMixin, StudioContainerXBloc ...@@ -114,17 +114,11 @@ class QuestionnaireAbstractBlock(StudioEditableXBlockMixin, StudioContainerXBloc
return block return block
@property @property
def studio_display_name(self): def display_name_with_default(self):
if not self.lonely_step: if not self.lonely_step:
return self._(u"Question {number}").format(number=self.step_number) return self._(u"Question {number}").format(number=self.step_number)
return self._(u"Question") return self._(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__
......
<div class="xblock-answer" data-completed="{{ self.completed }}"> <div class="xblock-answer" data-completed="{{ self.completed }}">
{% if not hide_header %}<h3 class="question-title">{{ self.display_name }}</h3>{% endif %} {% if not hide_header %}<h3 class="question-title">{{ self.display_name_with_default }}</h3>{% endif %}
<p>{{ self.question }}</p> <p>{{ self.question }}</p>
<textarea <textarea
class="answer editable" cols="50" rows="10" name="input" class="answer editable" cols="50" rows="10" name="input"
......
<fieldset class="choices questionnaire"> <fieldset class="choices questionnaire">
<legend class="question"> <legend class="question">
{% if not hide_header %}<h3 class="question-title">{{ self.display_name }}</h3>{% endif %} {% if not hide_header %}<h3 class="question-title">{{ self.display_name_with_default }}</h3>{% endif %}
<p>{{ self.question }}</p> <p>{{ self.question }}</p>
</legend> </legend>
<div class="choices-list"> <div class="choices-list">
......
<fieldset class="choices questionnaire" data-hide_results="{{self.hide_results}}"> <fieldset class="choices questionnaire" data-hide_results="{{self.hide_results}}">
<legend class="question"> <legend class="question">
{% if not hide_header %}<h3 class="question-title">{{ self.display_name }}</h3>{% endif %} {% if not hide_header %}<h3 class="question-title">{{ self.display_name_with_default }}</h3>{% endif %}
<p>{{ self.question }}</p> <p>{{ self.question }}</p>
</legend> </legend>
<div class="choices-list"> <div class="choices-list">
......
<fieldset class="rating questionnaire"> <fieldset class="rating questionnaire">
<legend class="question"> <legend class="question">
{% if not hide_header %}<h3 class="question-title">{{ self.display_name }}</h3>{% endif %} {% if not hide_header %}<h3 class="question-title">{{ self.display_name_with_default }}</h3>{% endif %}
<p>{{ self.question }}</p> <p>{{ self.question }}</p>
</legend> </legend>
<div class="choices-list"> <div class="choices-list">
......
...@@ -76,7 +76,7 @@ class TipBlock(StudioEditableXBlockMixin, XBlock): ...@@ -76,7 +76,7 @@ class TipBlock(StudioEditableXBlockMixin, XBlock):
return self.runtime.service(self, "i18n").ugettext(text) return self.runtime.service(self, "i18n").ugettext(text)
@property @property
def studio_display_name(self): def display_name_with_default(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:
...@@ -86,12 +86,6 @@ class TipBlock(StudioEditableXBlockMixin, XBlock): ...@@ -86,12 +86,6 @@ class TipBlock(StudioEditableXBlockMixin, XBlock):
values_list.append(display_name) values_list.append(display_name)
return self._(u"Tip for {list_of_choices}").format(list_of_choices=u", ".join(values_list)) return self._(u"Tip for {list_of_choices}").format(list_of_choices=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