Commit 01776bb8 by Alan Boudreault

Just used python native values and not LightChildField classes

parent 2a9a65a8
...@@ -56,8 +56,7 @@ class HTMLBlock(LightChild): ...@@ -56,8 +56,7 @@ class HTMLBlock(LightChild):
return block return block
def student_view(self, context=None): def student_view(self, context=None):
# TODO HACK, TO MODIFY, SHOULDN'T USE A get() METHOD return Fragment(self.content)
return Fragment(self.content.get())
def mentoring_view(self, context=None): def mentoring_view(self, context=None):
return self.student_view(context) return self.student_view(context)
......
...@@ -217,17 +217,7 @@ class LightChild(Plugin, LightChildrenMixin): ...@@ -217,17 +217,7 @@ class LightChild(Plugin, LightChildrenMixin):
fields = [(attr, value) for attr, value in self.__class__.__dict__.iteritems() if \ fields = [(attr, value) for attr, value in self.__class__.__dict__.iteritems() if \
isinstance(value, LightChildField)] isinstance(value, LightChildField)]
for attr, value in fields: for attr, value in fields:
self.__dict__[attr] = copy.deepcopy(value) self.__dict__[attr] = value.value # set the default value
def __setattr__(self, name, value):
field = getattr(self, name) if hasattr(self, name) else None
# If the property is a LightChildField instance, use its setattr
if isinstance(field, LightChildField):
field.set(value)
else:
super(LightChild, self).__setattr__(name, value)
@lazy @lazy
def student_data(self): def student_data(self):
...@@ -292,7 +282,7 @@ class LightChild(Plugin, LightChildrenMixin): ...@@ -292,7 +282,7 @@ class LightChild(Plugin, LightChildrenMixin):
# Get All LightChild fields to save # Get All LightChild fields to save
for field in self.get_fields_to_save(): for field in self.get_fields_to_save():
self.student_data[field] = getattr(self, field).to_json() self.student_data[field] = getattr(self, field)
if self.name: if self.name:
lightchild_data = self.get_lightchild_model_object() lightchild_data = self.get_lightchild_model_object()
...@@ -339,18 +329,6 @@ class LightChildField(object): ...@@ -339,18 +329,6 @@ class LightChildField(object):
def get(self): def get(self):
return self.value return self.value
def to_json(self):
"""
Returns the JSON representation of the LightChieldField.
"""
return self.value
def from_json(self, value):
"""
Returns value as a native full featured python type from a JSON value.
"""
pass
class String(LightChildField): class String(LightChildField):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
...@@ -370,9 +348,6 @@ class Integer(LightChildField): ...@@ -370,9 +348,6 @@ class Integer(LightChildField):
def __str__(self): def __str__(self):
return str(self.value) return str(self.value)
def __int__(self):
return self.value
def __nonzero__(self): def __nonzero__(self):
try: try:
int(self.value) int(self.value)
...@@ -381,18 +356,6 @@ class Integer(LightChildField): ...@@ -381,18 +356,6 @@ class Integer(LightChildField):
return self.value is not None return self.value is not None
def set(self, value):
try:
self.value = int(value)
except (TypeError, ValueError): # not an integer
self.value = None
def from_json(self, value):
if value is None or value == '':
return None
return int(value)
class Boolean(LightChildField): class Boolean(LightChildField):
pass pass
......
...@@ -43,7 +43,7 @@ class MRQBlock(QuestionnaireAbstractBlock): ...@@ -43,7 +43,7 @@ class MRQBlock(QuestionnaireAbstractBlock):
An XBlock used to ask multiple-response questions An XBlock used to ask multiple-response questions
""" """
student_choices = List(help="Last submissions by the student", default=[], scope=Scope.user_state) student_choices = List(help="Last submissions by the student", default=[], scope=Scope.user_state)
max_attempts = Integer(help="Number of max attempts for this questions", default=None, scope=Scope.content) max_attempts = Integer(help="Number of max attempts for this questions", scope=Scope.content)
num_attempts = Integer(help="Number of attempts a user has answered for this questions", scope=Scope.user_state) num_attempts = Integer(help="Number of attempts a user has answered for this questions", scope=Scope.user_state)
# TODO REMOVE THIS, ONLY NEEDED FOR LIGHTCHILDREN # TODO REMOVE THIS, ONLY NEEDED FOR LIGHTCHILDREN
...@@ -53,7 +53,6 @@ class MRQBlock(QuestionnaireAbstractBlock): ...@@ -53,7 +53,6 @@ class MRQBlock(QuestionnaireAbstractBlock):
'num_attempts' 'num_attempts'
] ]
# TODO REMOVE ALL USE OF THE get() METHOD
def submit(self, submissions): def submit(self, submissions):
log.debug(u'Received MRQ submissions: "%s"', submissions) log.debug(u'Received MRQ submissions: "%s"', submissions)
...@@ -67,18 +66,18 @@ class MRQBlock(QuestionnaireAbstractBlock): ...@@ -67,18 +66,18 @@ class MRQBlock(QuestionnaireAbstractBlock):
for choice in self.custom_choices: for choice in self.custom_choices:
choice_completed = True choice_completed = True
choice_tips_fragments = [] choice_tips_fragments = []
choice_selected = choice.value.get() in submissions choice_selected = choice.value in submissions
for tip in self.get_tips(): for tip in self.get_tips():
if choice.value.get() in tip.display_with_defaults: if choice.value in tip.display_with_defaults:
choice_tips_fragments.append(tip.render()) choice_tips_fragments.append(tip.render())
if ((not choice_selected and choice.value.get() in tip.require_with_defaults) or if ((not choice_selected and choice.value in tip.require_with_defaults) or
(choice_selected and choice.value.get() in tip.reject_with_defaults)): (choice_selected and choice.value in tip.reject_with_defaults)):
choice_completed = False choice_completed = False
completed = completed and choice_completed completed = completed and choice_completed
results.append({ results.append({
'value': choice.value.get(), 'value': choice.value,
'selected': choice_selected, 'selected': choice_selected,
'completed': choice_completed, 'completed': choice_completed,
'tips': render_template('templates/html/tip_choice_group.html', { 'tips': render_template('templates/html/tip_choice_group.html', {
...@@ -90,18 +89,17 @@ class MRQBlock(QuestionnaireAbstractBlock): ...@@ -90,18 +89,17 @@ class MRQBlock(QuestionnaireAbstractBlock):
self.message = u'Your answer is correct!' if completed else u'Your answer is incorrect.' self.message = u'Your answer is correct!' if completed else u'Your answer is incorrect.'
num_attempts = self.num_attempts.get() + 1 if self.max_attempts else 0 setattr(self, 'num_attempts', self.num_attempts + 1)
setattr(self, 'num_attempts', num_attempts)
max_attempts_reached = False max_attempts_reached = False
if self.max_attempts: if self.max_attempts:
max_attempts = self.max_attempts.get() max_attempts = self.max_attempts
num_attempts = self.num_attempts.get() num_attempts = self.num_attempts
max_attempts_reached = num_attempts >= max_attempts max_attempts_reached = num_attempts >= max_attempts
if max_attempts_reached and (not completed or num_attempts > max_attempts): if max_attempts_reached and (not completed or num_attempts > max_attempts):
completed = True completed = True
self.message = self.message.get() + u' You have reached the maximum number of attempts for this question. ' \ self.message += u' You have reached the maximum number of attempts for this question. ' \
u'Your next answers won''t be saved. You can check the answer(s) using the "Show Answer(s)" button.' u'Your next answers won''t be saved. You can check the answer(s) using the "Show Answer(s)" button.'
else: else:
self.student_choices = submissions self.student_choices = submissions
...@@ -110,9 +108,9 @@ class MRQBlock(QuestionnaireAbstractBlock): ...@@ -110,9 +108,9 @@ class MRQBlock(QuestionnaireAbstractBlock):
'submissions': submissions, 'submissions': submissions,
'completed': completed, 'completed': completed,
'choices': results, 'choices': results,
'message': self.message.get(), 'message': self.message,
'max_attempts': self.max_attempts.get() if self.max_attempts else None, 'max_attempts': self.max_attempts,
'num_attempts': self.num_attempts.get() 'num_attempts': self.num_attempts
} }
log.debug(u'MRQ submissions result: %s', result) log.debug(u'MRQ submissions result: %s', result)
......
...@@ -97,7 +97,7 @@ function MRQBlock(runtime, element) { ...@@ -97,7 +97,7 @@ function MRQBlock(runtime, element) {
choiceResultDOM.removeClass('incorrect icon-exclamation correct icon-ok'); choiceResultDOM.removeClass('incorrect icon-exclamation correct icon-ok');
/* show hint if checked or max_attempts is disabled */ /* show hint if checked or max_attempts is disabled */
if (choiceInputDOM.prop('checked') || _.isNull(result.max_attempts)) { if (choiceInputDOM.prop('checked') || result.max_attempts <= 0) {
if (choice.completed) { if (choice.completed) {
choiceResultDOM.addClass('correct icon-ok'); choiceResultDOM.addClass('correct icon-ok');
} else if (!choice.completed) { } else if (!choice.completed) {
......
<script type="text/template" id="xblock-mrq-attempts"> <script type="text/template" id="xblock-mrq-attempts">
<% if (_.isNumber(max_attempts)) {{ %> <% if (_.isNumber(max_attempts) && max_attempts > 0) {{ %>
<% if (num_attempts >= max_attempts) {{ %> <% if (num_attempts >= max_attempts) {{ %>
<button class="show"> <button class="show">
......
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