diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index f66abf9134..13627ae0f6 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -62,7 +62,47 @@ log = logging.getLogger(__name__) ######################################################################### -registry = TagRegistry() +registry = TagRegistry() # pylint: disable=C0103 + + +class Status(object): + """ + Problem status + attributes: classname, display_name + """ + css_classes = { + # status: css class + 'unsubmitted': 'unanswered', + 'incomplete': 'incorrect', + 'queued': 'processing', + } + __slots__ = ('classname', '_status', 'display_name') + + def __init__(self, status, gettext_func=unicode): + self.classname = self.css_classes.get(status, status) + _ = gettext_func + names = { + 'correct': _('correct'), + 'incorrect': _('incorrect'), + 'incomplete': _('incomplete'), + 'unanswered': _('unanswered'), + 'unsubmitted': _('unanswered'), + 'queued': _('processing'), + } + self.display_name = names.get(status, unicode(status)) + self._status = status or '' + + def __str__(self): + return self._status + + def __unicode__(self): + return self._status.decode('utf8') + + def __repr__(self): + return 'Status(%r)' % self._status + + def __eq__(self, other): + return self._status == str(other) class Attribute(object): @@ -261,9 +301,7 @@ class InputTypeBase(object): context = { 'id': self.input_id, 'value': self.value, - 'status': self.status, - 'status_class': self.status_class, - 'status_display': self.status_display, + 'status': Status(self.status, self.capa_system.i18n.ugettext), 'msg': self.msg, 'STATIC_URL': self.capa_system.STATIC_URL, } @@ -273,34 +311,6 @@ class InputTypeBase(object): context.update(self._extra_context()) return context - @property - def status_class(self): - """ - Return the CSS class for the associated status. - """ - statuses = { - 'unsubmitted': 'unanswered', - 'incomplete': 'incorrect', - 'queued': 'processing', - } - return statuses.get(self.status, self.status) - - @property - def status_display(self): - """ - Return the human-readable and translated word for the associated status. - """ - _ = self.capa_system.i18n.ugettext - statuses = { - 'correct': _('correct'), - 'incorrect': _('incorrect'), - 'incomplete': _('incomplete'), - 'unanswered': _('unanswered'), - 'unsubmitted': _('unanswered'), - 'queued': _('queued'), - } - return statuses.get(self.status, self.status) - def _extra_context(self): """ Subclasses can override this to return extra context that should be passed to their templates for rendering. diff --git a/common/lib/capa/capa/templates/annotationinput.html b/common/lib/capa/capa/templates/annotationinput.html index 145a7c2cad..3502f9ff25 100644 --- a/common/lib/capa/capa/templates/annotationinput.html +++ b/common/lib/capa/capa/templates/annotationinput.html @@ -52,13 +52,7 @@ % endif - % if status == 'unsubmitted': - Status: Unanswered - % elif status == 'incomplete': - Status: Incorrect - % elif status == 'incorrect' and not has_options_value: - Status: Incorrect - % endif + ${status.display_name}

diff --git a/common/lib/capa/capa/templates/chemicalequationinput.html b/common/lib/capa/capa/templates/chemicalequationinput.html index d6a2e36a9a..2ae29406b6 100644 --- a/common/lib/capa/capa/templates/chemicalequationinput.html +++ b/common/lib/capa/capa/templates/chemicalequationinput.html @@ -1,7 +1,7 @@
-
+
${value|h} - - ${status_display} + ${status.display_name}

diff --git a/common/lib/capa/capa/templates/choicegroup.html b/common/lib/capa/capa/templates/choicegroup.html index 60145c3a68..814fae6594 100644 --- a/common/lib/capa/capa/templates/choicegroup.html +++ b/common/lib/capa/capa/templates/choicegroup.html @@ -1,7 +1,7 @@
% if input_type == 'checkbox' or not value: - @@ -11,7 +11,7 @@ %endif %endfor - - ${status_display} + ${status.display_name} % endif @@ -51,7 +51,7 @@ % if input_type == 'radio' and ( (isinstance(value, basestring) and (choice_id == value)) or (not isinstance(value, basestring) and choice_id in value) ): % if status in ('correct', 'incorrect') and not show_correctness=='never': - ${choice_description|h} - ${status_display} + ${choice_description|h} - ${status.display_name} % endif % endif diff --git a/common/lib/capa/capa/templates/choicetext.html b/common/lib/capa/capa/templates/choicetext.html index 2efde27088..6991ede721 100644 --- a/common/lib/capa/capa/templates/choicetext.html +++ b/common/lib/capa/capa/templates/choicetext.html @@ -10,7 +10,7 @@
% if input_type == 'checkbox' or not element_checked: - + % endif
diff --git a/common/lib/capa/capa/templates/codeinput.html b/common/lib/capa/capa/templates/codeinput.html index f213099e6b..dda2d6b97b 100644 --- a/common/lib/capa/capa/templates/codeinput.html +++ b/common/lib/capa/capa/templates/codeinput.html @@ -17,10 +17,10 @@
- ${status_display} + ${status.display_name} % if status == 'queued': @@ -30,7 +30,7 @@
% endif -

${status_display}

+

${status.display_name}

diff --git a/common/lib/capa/capa/templates/crystallography.html b/common/lib/capa/capa/templates/crystallography.html index 97dbba4f0a..df2129344c 100644 --- a/common/lib/capa/capa/templates/crystallography.html +++ b/common/lib/capa/capa/templates/crystallography.html @@ -9,29 +9,14 @@
- % if status == 'unsubmitted': -
- % elif status == 'correct': -
- % elif status == 'incorrect': -
- % elif status == 'incomplete': -
- % endif + % if status in ['unsubmitted', 'correct', 'incorrect', 'incomplete']: +

- % if status == 'unsubmitted': - unanswered - % elif status == 'correct': - correct - % elif status == 'incorrect': - incorrect - % elif status == 'incomplete': - incomplete - % endif + ${status.display_name}

diff --git a/common/lib/capa/capa/templates/designprotein2dinput.html b/common/lib/capa/capa/templates/designprotein2dinput.html index d44d853661..066d796db3 100644 --- a/common/lib/capa/capa/templates/designprotein2dinput.html +++ b/common/lib/capa/capa/templates/designprotein2dinput.html @@ -2,14 +2,8 @@
- % if status == 'unsubmitted': -
- % elif status == 'correct': -
- % elif status == 'incorrect': -
- % elif status == 'incomplete': -
+ % if status in ['unsubmitted', 'correct', 'incorrect', 'incomplete']: +
% endif
@@ -17,15 +11,7 @@

- % if status == 'unsubmitted': - unanswered - % elif status == 'correct': - correct - % elif status == 'incorrect': - incorrect - % elif status == 'incomplete': - incomplete - % endif + ${status.display_name}

diff --git a/common/lib/capa/capa/templates/drag_and_drop_input.html b/common/lib/capa/capa/templates/drag_and_drop_input.html index 8b8feb993c..589f9c4f57 100644 --- a/common/lib/capa/capa/templates/drag_and_drop_input.html +++ b/common/lib/capa/capa/templates/drag_and_drop_input.html @@ -8,14 +8,8 @@
- % if status == 'unsubmitted': -
- % elif status == 'correct': -
- % elif status == 'incorrect': -
- % elif status == 'incomplete': -
+ % if status in ['unsubmitted', 'correct', 'incorrect', 'incomplete']: +
% endif @@ -23,15 +17,7 @@ style="display:none;"/>

- % if status == 'unsubmitted': - unanswered - % elif status == 'correct': - correct - % elif status == 'incorrect': - incorrect - % elif status == 'incomplete': - incomplete - % endif + ${status.display_name}

diff --git a/common/lib/capa/capa/templates/editageneinput.html b/common/lib/capa/capa/templates/editageneinput.html index dd389987d4..4ee3cc5d7e 100644 --- a/common/lib/capa/capa/templates/editageneinput.html +++ b/common/lib/capa/capa/templates/editageneinput.html @@ -2,14 +2,8 @@
- % if status == 'unsubmitted': -
- % elif status == 'correct': -
- % elif status == 'incorrect': -
- % elif status == 'incomplete': -
+ % if status in ['unsubmitted', 'correct', 'incorrect', 'incomplete']: +
% endif
@@ -18,15 +12,7 @@

- % if status == 'unsubmitted': - unanswered - % elif status == 'correct': - correct - % elif status == 'incorrect': - incorrect - % elif status == 'incomplete': - incomplete - % endif + ${status.display_name}

diff --git a/common/lib/capa/capa/templates/editamolecule.html b/common/lib/capa/capa/templates/editamolecule.html index 235e30099e..e5131b21d9 100644 --- a/common/lib/capa/capa/templates/editamolecule.html +++ b/common/lib/capa/capa/templates/editamolecule.html @@ -1,15 +1,9 @@
- % if status == 'unsubmitted': -
- % elif status == 'correct': -
- % elif status == 'incorrect': -
- % elif status == 'incomplete': -
- % endif + % if status in ['unsubmitted', 'correct', 'incorrect', 'incomplete']: +
+ % endif
@@ -23,15 +17,7 @@

- % if status == 'unsubmitted': - unanswered - % elif status == 'correct': - correct - % elif status == 'incorrect': - incorrect - % elif status == 'incomplete': - incomplete - % endif + ${status.display_name}



diff --git a/common/lib/capa/capa/templates/filesubmission.html b/common/lib/capa/capa/templates/filesubmission.html index 374f9734a8..17209b8564 100644 --- a/common/lib/capa/capa/templates/filesubmission.html +++ b/common/lib/capa/capa/templates/filesubmission.html @@ -1,14 +1,9 @@
- % if status == 'unsubmitted': - Unanswered - % elif status == 'correct': - Correct - % elif status == 'incorrect': - Incorrect - % elif status == 'queued': - Queued - + + ${status.display_name} + % if status == 'queued': + % endif

${status}

diff --git a/common/lib/capa/capa/templates/formulaequationinput.html b/common/lib/capa/capa/templates/formulaequationinput.html index f5d9821232..10b3b22ea5 100644 --- a/common/lib/capa/capa/templates/formulaequationinput.html +++ b/common/lib/capa/capa/templates/formulaequationinput.html @@ -1,6 +1,6 @@ <% doinline = 'style="display:inline-block;vertical-align:top"' if inline else "" %>
-
+
- ${status_display} + - ${status.display_name}

diff --git a/common/lib/capa/capa/templates/imageinput.html b/common/lib/capa/capa/templates/imageinput.html index 25da119651..38dd42ba8d 100644 --- a/common/lib/capa/capa/templates/imageinput.html +++ b/common/lib/capa/capa/templates/imageinput.html @@ -39,38 +39,11 @@ (new ImageInput('${id}')); - % if status == 'unsubmitted': - Status: unanswered + ${status.display_name} - % elif status == 'correct': - - Status: correct - - % elif status == 'incorrect': - - Status: incorrect - - % elif status == 'incomplete': - - Status: incorrect - - % endif
diff --git a/common/lib/capa/capa/templates/jsinput.html b/common/lib/capa/capa/templates/jsinput.html index 6ad0ea7b77..b45dbda431 100644 --- a/common/lib/capa/capa/templates/jsinput.html +++ b/common/lib/capa/capa/templates/jsinput.html @@ -17,14 +17,8 @@
- % if status == 'unsubmitted': -
- % elif status == 'correct': -
- % elif status == 'incorrect': -
- % elif status == 'incomplete': -
+ % if status in ['unsubmitted', 'correct', 'incorrect', 'incomplete']: +
% endif