From 496e4dc398102782e81b4bcd9749148412ac7d53 Mon Sep 17 00:00:00 2001 From: caseylitton Date: Fri, 18 Nov 2016 14:24:56 -0800 Subject: [PATCH] Add static word count message --- freetextresponse/freetextresponse.py | 35 +++++++++++++------ freetextresponse/private/view.html | 1 + freetextresponse/private/view.less | 8 +++++ freetextresponse/public/view.html | 2 +- freetextresponse/public/view.less | 8 +++++ freetextresponse/public/view.less.min.css | 2 +- freetextresponse/public/view.less.min.css.map | 2 +- 7 files changed, 44 insertions(+), 14 deletions(-) diff --git a/freetextresponse/freetextresponse.py b/freetextresponse/freetextresponse.py index 9e80419b..fcd632c9 100644 --- a/freetextresponse/freetextresponse.py +++ b/freetextresponse/freetextresponse.py @@ -217,6 +217,7 @@ def student_view(self, context=None): view_html = FreeTextResponse.get_resource_string('view.html') view_html = view_html.format( self=self, + word_count_message=self._get_word_count_message(), indicator_class=self._get_indicator_class(), problem_progress=self._get_problem_progress(), used_attempts_feedback=self._get_used_attempts_feedback(), @@ -341,22 +342,33 @@ def _get_indicator_visibility_class(self): def _get_word_count_message(self, ignore_attempts=False): """ - Returns the word count message based on the student's answer + Returns the word count message + """ + result = ungettext( + "Your response must be " + "between {min} and {max} word.", + "Your response must be " + "between {min} and {max} words.", + self.max_word_count, + ).format( + min=self.min_word_count, + max=self.max_word_count, + ) + return result + + def _get_invalid_word_count_message(self, ignore_attempts=False): + """ + Returns the invalid word count message """ result = '' if ( (ignore_attempts or self.count_attempts > 0) and (not self._word_count_valid()) ): - result = ungettext( - "Invalid Word Count. Your response must be " - "between {min} and {max} word.", - "Invalid Word Count. Your response must be " - "between {min} and {max} words.", - self.max_word_count, + word_count_message = self._get_word_count_message(ignore_attempts=ignore_attempts) + result = _("Invalid Word Count. {word_count_message}" ).format( - min=self.min_word_count, - max=self.max_word_count, + word_count_message=word_count_message, ) return result @@ -510,11 +522,12 @@ def _get_submitted_message(self): def _get_user_alert(self, ignore_attempts=False): """ - Returns the message to display in the user_alert(TBD) div + Returns the message to display in the user_alert div + depending on the student answer """ result = '' if not self._word_count_valid(): - result = self._get_word_count_message(ignore_attempts) + result = self._get_invalid_word_count_message(ignore_attempts) return result @XBlock.json_handler diff --git a/freetextresponse/private/view.html b/freetextresponse/private/view.html index 8f43a3bd..ad5dd8fb 100644 --- a/freetextresponse/private/view.html +++ b/freetextresponse/private/view.html @@ -2,6 +2,7 @@

{self.display_name}

{problem_progress}

{self.prompt}

+
{word_count_message}
diff --git a/freetextresponse/private/view.less b/freetextresponse/private/view.less index 5cb75ce7..7d9ff34f 100644 --- a/freetextresponse/private/view.less +++ b/freetextresponse/private/view.less @@ -85,6 +85,14 @@ font-size: 1em; } + .word-count-message { + display: inline-block; + padding-left: 5px; + color: @dark_grey; + font-weight: 100; + font-size: 1em; + } + .hidden{ visibility: hidden; } diff --git a/freetextresponse/public/view.html b/freetextresponse/public/view.html index b7f8ec45..dfcab702 100644 --- a/freetextresponse/public/view.html +++ b/freetextresponse/public/view.html @@ -1 +1 @@ -

{self.display_name}

{problem_progress}

{self.prompt}

{submitted_message}
{used_attempts_feedback}
{user_alert}
\ No newline at end of file +

{self.display_name}

{problem_progress}

{self.prompt}

{word_count_message}
{submitted_message}
{used_attempts_feedback}
{user_alert}
\ No newline at end of file diff --git a/freetextresponse/public/view.less b/freetextresponse/public/view.less index 5cb75ce7..7d9ff34f 100644 --- a/freetextresponse/public/view.less +++ b/freetextresponse/public/view.less @@ -85,6 +85,14 @@ font-size: 1em; } + .word-count-message { + display: inline-block; + padding-left: 5px; + color: @dark_grey; + font-weight: 100; + font-size: 1em; + } + .hidden{ visibility: hidden; } diff --git a/freetextresponse/public/view.less.min.css b/freetextresponse/public/view.less.min.css index dc097eb7..5d61c453 100644 --- a/freetextresponse/public/view.less.min.css +++ b/freetextresponse/public/view.less.min.css @@ -1 +1 @@ -.freetextresponse .user_input .status{margin-left:10px;display:inline-block}.freetextresponse .user_input.unanswered .status{width:14px;height:14px;background:url(images/unanswered-icon.png) center center no-repeat}.freetextresponse .user_input.correct .status{width:25px;height:20px;background:url(images/correct-icon.png) center center no-repeat}.freetextresponse .user_input.incorrect .status{width:20px;height:20px;background:url(images/incorrect-icon.png) center center no-repeat}.freetextresponse .user_input .student_answer{height:150px;box-sizing:border-box;border-radius:3px;border:2px solid #e4e4e4;min-width:160px}.freetextresponse .user_input.unanswered .student_answer{border:2px solid #e4e4e4}.freetextresponse .user_input.correct .student_answer{border:2px solid #1e9348}.freetextresponse .user_input.incorrect .student_answer{border:2px solid #b20610}.freetextresponse .action{margin-top:20px}.freetextresponse .action .save{height:40px;vertical-align:middle;font-weight:600}.freetextresponse .action .check{height:40px;vertical-align:middle;font-weight:600}.freetextresponse .action .used-attempts-feedback{display:inline-block;margin-top:8px;margin-left:10px;color:#666;font-style:italic}.freetextresponse .action .nodisplay{display:none}.freetextresponse .problem-progress{display:inline-block;padding-left:5px;color:#666;font-weight:100;font-size:1em}.freetextresponse .hidden{visibility:hidden}.freetextresponse .problem-header{display:inline-block}.freetextresponse .capa_alert{margin-top:10px;padding:8px 12px;border:1px solid #ebe8bf;border-radius:3px;background:#fffcdd;font-size:.9em}.freetextresponse div:empty{display:none} \ No newline at end of file +.freetextresponse .user_input .status{margin-left:10px;display:inline-block}.freetextresponse .user_input.unanswered .status{width:14px;height:14px;background:url(images/unanswered-icon.png) center center no-repeat}.freetextresponse .user_input.correct .status{width:25px;height:20px;background:url(images/correct-icon.png) center center no-repeat}.freetextresponse .user_input.incorrect .status{width:20px;height:20px;background:url(images/incorrect-icon.png) center center no-repeat}.freetextresponse .user_input .student_answer{height:150px;box-sizing:border-box;border-radius:3px;border:2px solid #e4e4e4;min-width:160px}.freetextresponse .user_input.unanswered .student_answer{border:2px solid #e4e4e4}.freetextresponse .user_input.correct .student_answer{border:2px solid #1e9348}.freetextresponse .user_input.incorrect .student_answer{border:2px solid #b20610}.freetextresponse .action{margin-top:20px}.freetextresponse .action .save{height:40px;vertical-align:middle;font-weight:600}.freetextresponse .action .check{height:40px;vertical-align:middle;font-weight:600}.freetextresponse .action .used-attempts-feedback{display:inline-block;margin-top:8px;margin-left:10px;color:#666;font-style:italic}.freetextresponse .action .nodisplay{display:none}.freetextresponse .problem-progress{display:inline-block;padding-left:5px;color:#666;font-weight:100;font-size:1em}.freetextresponse .word-count-message{display:inline-block;padding-left:5px;color:#666;font-weight:100;font-size:1em}.freetextresponse .hidden{visibility:hidden}.freetextresponse .problem-header{display:inline-block}.freetextresponse .capa_alert{margin-top:10px;padding:8px 12px;border:1px solid #ebe8bf;border-radius:3px;background:#fffcdd;font-size:.9em}.freetextresponse div:empty{display:none} \ No newline at end of file diff --git a/freetextresponse/public/view.less.min.css.map b/freetextresponse/public/view.less.min.css.map index 50f24562..c0d9a1f6 100644 --- a/freetextresponse/public/view.less.min.css.map +++ b/freetextresponse/public/view.less.min.css.map @@ -1 +1 @@ -{"version":3,"sources":["./freetextresponse/public/view.less"],"names":[],"mappings":"AAAA,iBAEE,YAEE,SACE,gBAAA,CACA,qBAGF,iBAPF,YAOG,WAAY,SACX,UAAA,CACA,WAAA,CACA,eAAgB,sDAGlB,iBAbF,YAaG,QAAS,SACR,UAAA,CACA,WAAA,CACA,eAAgB,mDAGlB,iBAnBF,YAmBG,UAAW,SACV,UAAA,CACA,WAAA,CACA,eAAgB,qDAxBtB,iBAEE,YAyBE,iBACE,YAAA,CACA,qBAAA,CACA,iBAAA,CACA,wBAAA,CACA,gBAGF,iBAjCF,YAiCG,WAAY,iBACX,yBAGF,iBArCF,YAqCG,QAAS,iBACR,yBAGF,iBAzCF,YAyCG,UAAW,iBACV,yBA5CN,iBAmDE,SACE,gBApDJ,iBAmDE,QAGE,OACE,WAAA,CACA,qBAAA,CACA,gBAzDN,iBAmDE,QASE,QACE,WAAA,CACA,qBAAA,CACA,gBA/DN,iBAmDE,QAeE,yBACE,oBAAA,CACA,cAAA,CACA,gBAAA,CACA,UAAA,CACA,kBAvEN,iBAmDE,QAuBE,YACE,aA3EN,iBA+EE,mBACE,oBAAA,CACA,gBAAA,CACA,UAAA,CACA,eAAA,CACA,cApFJ,iBAuFE,SACE,kBAxFJ,iBA2FE,iBACE,qBA5FJ,iBA+FE,aACE,eAAA,CACA,gBAAA,CACA,wBAAA,CACA,iBAAA,CACA,kBAAA,CACA,gBArGJ,iBAwGE,IAAG,OAAS","sourcesContent":[".freetextresponse {\n\n .user_input {\n\n .status {\n margin-left: 10px;\n display: inline-block;\n }\n\n &.unanswered .status {\n width: 14px;\n height: 14px;\n background: url(\"images/unanswered-icon.png\") center center no-repeat;\n }\n\n &.correct .status {\n width: 25px;\n height: 20px;\n background: url(\"images/correct-icon.png\") center center no-repeat;\n }\n\n &.incorrect .status {\n width: 20px;\n height: 20px;\n background: url(\"images/incorrect-icon.png\") center center no-repeat;\n }\n\n .student_answer {\n height:150px;\n box-sizing:border-box;\n border-radius:3px;\n border:2px solid #e4e4e4;\n min-width:160px;\n }\n\n &.unanswered .student_answer {\n border:2px solid #e4e4e4;\n }\n\n &.correct .student_answer {\n border:2px solid #1e9348;\n }\n\n &.incorrect .student_answer {\n border:2px solid #b20610;\n }\n\n }\n\n @dark_grey: #666;\n\n .action {\n margin-top: 20px;\n\n .save {\n height: 40px;\n vertical-align: middle;\n font-weight: 600;\n }\n\n .check {\n height: 40px;\n vertical-align: middle;\n font-weight: 600;\n }\n\n .used-attempts-feedback {\n display: inline-block;\n margin-top: 8px;\n margin-left: 10px;\n color: @dark_grey;\n font-style: italic;\n }\n\n .nodisplay{\n display: none;\n }\n }\n\n .problem-progress {\n display: inline-block;\n padding-left: 5px;\n color: @dark_grey;\n font-weight: 100;\n font-size: 1em;\n }\n\n .hidden{\n visibility: hidden;\n }\n\n .problem-header {\n display: inline-block;\n }\n\n .capa_alert {\n margin-top: 10px;\n padding: 8px 12px;\n border: 1px solid #ebe8bf;\n border-radius: 3px;\n background: #fffcdd;\n font-size: 0.9em;\n }\n\n div:empty { display: none }\n}\n"]} \ No newline at end of file +{"version":3,"sources":["./freetextresponse/public/view.less"],"names":[],"mappings":"AAAA,iBAEE,YAEE,SACE,gBAAA,CACA,qBAGF,iBAPF,YAOG,WAAY,SACX,UAAA,CACA,WAAA,CACA,eAAgB,sDAGlB,iBAbF,YAaG,QAAS,SACR,UAAA,CACA,WAAA,CACA,eAAgB,mDAGlB,iBAnBF,YAmBG,UAAW,SACV,UAAA,CACA,WAAA,CACA,eAAgB,qDAxBtB,iBAEE,YAyBE,iBACE,YAAA,CACA,qBAAA,CACA,iBAAA,CACA,wBAAA,CACA,gBAGF,iBAjCF,YAiCG,WAAY,iBACX,yBAGF,iBArCF,YAqCG,QAAS,iBACR,yBAGF,iBAzCF,YAyCG,UAAW,iBACV,yBA5CN,iBAmDE,SACE,gBApDJ,iBAmDE,QAGE,OACE,WAAA,CACA,qBAAA,CACA,gBAzDN,iBAmDE,QASE,QACE,WAAA,CACA,qBAAA,CACA,gBA/DN,iBAmDE,QAeE,yBACE,oBAAA,CACA,cAAA,CACA,gBAAA,CACA,UAAA,CACA,kBAvEN,iBAmDE,QAuBE,YACE,aA3EN,iBA+EE,mBACE,oBAAA,CACA,gBAAA,CACA,UAAA,CACA,eAAA,CACA,cApFJ,iBAuFE,qBACE,oBAAA,CACA,gBAAA,CACA,UAAA,CACA,eAAA,CACA,cA5FJ,iBA+FE,SACE,kBAhGJ,iBAmGE,iBACE,qBApGJ,iBAuGE,aACE,eAAA,CACA,gBAAA,CACA,wBAAA,CACA,iBAAA,CACA,kBAAA,CACA,gBA7GJ,iBAgHE,IAAG,OAAS","sourcesContent":[".freetextresponse {\n\n .user_input {\n\n .status {\n margin-left: 10px;\n display: inline-block;\n }\n\n &.unanswered .status {\n width: 14px;\n height: 14px;\n background: url(\"images/unanswered-icon.png\") center center no-repeat;\n }\n\n &.correct .status {\n width: 25px;\n height: 20px;\n background: url(\"images/correct-icon.png\") center center no-repeat;\n }\n\n &.incorrect .status {\n width: 20px;\n height: 20px;\n background: url(\"images/incorrect-icon.png\") center center no-repeat;\n }\n\n .student_answer {\n height:150px;\n box-sizing:border-box;\n border-radius:3px;\n border:2px solid #e4e4e4;\n min-width:160px;\n }\n\n &.unanswered .student_answer {\n border:2px solid #e4e4e4;\n }\n\n &.correct .student_answer {\n border:2px solid #1e9348;\n }\n\n &.incorrect .student_answer {\n border:2px solid #b20610;\n }\n\n }\n\n @dark_grey: #666;\n\n .action {\n margin-top: 20px;\n\n .save {\n height: 40px;\n vertical-align: middle;\n font-weight: 600;\n }\n\n .check {\n height: 40px;\n vertical-align: middle;\n font-weight: 600;\n }\n\n .used-attempts-feedback {\n display: inline-block;\n margin-top: 8px;\n margin-left: 10px;\n color: @dark_grey;\n font-style: italic;\n }\n\n .nodisplay{\n display: none;\n }\n }\n\n .problem-progress {\n display: inline-block;\n padding-left: 5px;\n color: @dark_grey;\n font-weight: 100;\n font-size: 1em;\n }\n\n .word-count-message {\n display: inline-block;\n padding-left: 5px;\n color: @dark_grey;\n font-weight: 100;\n font-size: 1em;\n }\n\n .hidden{\n visibility: hidden;\n }\n\n .problem-header {\n display: inline-block;\n }\n\n .capa_alert {\n margin-top: 10px;\n padding: 8px 12px;\n border: 1px solid #ebe8bf;\n border-radius: 3px;\n background: #fffcdd;\n font-size: 0.9em;\n }\n\n div:empty { display: none }\n}\n"]} \ No newline at end of file