Commit 6437809f by Xavier Antoviaque

Allow to present previous answers as a read-only blockquote

parent 43721b0b
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import logging import logging
from xblock.core import XBlock from xblock.core import XBlock
from xblock.fields import Any, Scope from xblock.fields import Any, Boolean, Scope
from xblock.fragment import Fragment from xblock.fragment import Fragment
from .models import Answer from .models import Answer
...@@ -28,6 +28,7 @@ class AnswerBlock(XBlock): ...@@ -28,6 +28,7 @@ class AnswerBlock(XBlock):
to make them searchable and referenceable across xblocks. to make them searchable and referenceable across xblocks.
""" """
student_input = Any(help="Last input submitted by the student", default="", scope=Scope.user_state) student_input = Any(help="Last input submitted by the student", default="", scope=Scope.user_state)
read_only = Boolean(help="Display as a read-only field", default=False, scope=Scope.content)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(AnswerBlock, self).__init__(*args, **kwargs) super(AnswerBlock, self).__init__(*args, **kwargs)
...@@ -39,18 +40,23 @@ class AnswerBlock(XBlock): ...@@ -39,18 +40,23 @@ class AnswerBlock(XBlock):
return Fragment(u"<p>I can only appear inside problems.</p>") return Fragment(u"<p>I can only appear inside problems.</p>")
def mentoring_view(self, context=None): def mentoring_view(self, context=None):
html = u'<textarea cols="100" rows="10" maxlength="{}" name="input">{}</textarea>'.format( if not self.read_only:
Answer._meta.get_field('student_input').max_length, html = u'<textarea cols="100" rows="10" maxlength="{}" name="input">{}</textarea>'.format(
self.student_input) Answer._meta.get_field('student_input').max_length,
self.student_input)
else:
html = u'<blockquote class="answer read_only">{}</div>'.format(self.student_input)
fragment = Fragment(html) fragment = Fragment(html)
fragment.add_css(load_resource('static/css/answer.css'))
fragment.add_javascript(load_resource('static/js/answer.js')) fragment.add_javascript(load_resource('static/js/answer.js'))
fragment.initialize_js('AnswerBlock') fragment.initialize_js('AnswerBlock')
return fragment return fragment
def submit(self, submission): def submit(self, submission):
self.student_input = submission[0]['value'] if not self.read_only:
log.info(u'Answer submitted for`{}`: "{}"'.format(self.name, self.student_input)) self.student_input = submission[0]['value']
log.info(u'Answer submitted for`{}`: "{}"'.format(self.name, self.student_input))
return self.student_input return self.student_input
def save(self): def save(self):
...@@ -59,7 +65,7 @@ class AnswerBlock(XBlock): ...@@ -59,7 +65,7 @@ class AnswerBlock(XBlock):
""" """
super(AnswerBlock, self).save() super(AnswerBlock, self).save()
answer_data = self.get_model_object() answer_data = self.get_model_object()
if answer_data.student_input != self.student_input: if answer_data.student_input != self.student_input and not self.read_only:
answer_data.student_input = self.student_input answer_data.student_input = self.student_input
answer_data.save() answer_data.save()
......
blockquote.answer.read_only {
background: #f9f9f9;
border-left: 10px solid #ccc;
margin: 1.5em 10px;
padding: 0.5em 10px;
quotes: "\201C""\201D""\2018""\2019";
}
blockquote.answer.read_only:before {
color: #ccc;
content: "\201C";
font-size: 4em;
line-height: 0.1em;
margin-right: 0.25em;
vertical-align: -0.4em;
}
blockquote.answer.read_only p {
display inline;
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<p>Now you have a list of potential goals.</p> <p>Now you have a list of potential goals.</p>
</html> </html>
<answer name="brainstorm_goals" read-only="true" /> <answer name="brainstorm_goals" read_only="true" />
<html> <html>
<p>Before you select from among them, consider getting input from others. People that know you well may have a different idea of what changes would benefit you most. To complete this exercise, seek input from at least 3 people who know you well. What do they think would be a valuable thing for you to get better at? You might ask them: "Given how well you know me, if I could get significantly better at just one thing, what would you suggest that one thing should be?"</p> <p>Before you select from among them, consider getting input from others. People that know you well may have a different idea of what changes would benefit you most. To complete this exercise, seek input from at least 3 people who know you well. What do they think would be a valuable thing for you to get better at? You might ask them: "Given how well you know me, if I could get significantly better at just one thing, what would you suggest that one thing should be?"</p>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<p>Now, let’s make sure your goal meets the criteria for a strong column 1. Here is your goal:</p> <p>Now, let’s make sure your goal meets the criteria for a strong column 1. Here is your goal:</p>
</html> </html>
<answer name="improvement_goal" read-only="yes" /> <answer name="improvement_goal" read_only="yes" />
<quizz type="yes-no-unsure"> <quizz type="yes-no-unsure">
<question>Is this goal true for you?</question> <question>Is this goal true for you?</question>
......
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