Commit a60b914b by Vik Paruchuri

add ability to store multiple answers

parent 52c971dc
...@@ -69,7 +69,7 @@ class SelfAssessmentModule(XModule): ...@@ -69,7 +69,7 @@ class SelfAssessmentModule(XModule):
instance_state, shared_state, **kwargs) instance_state, shared_state, **kwargs)
""" """
Definition file should have 3 blocks -- problem, rubric, and submitmessage Definition file should have 4 blocks -- problem, rubric, submitmessage, and maxattempts
Sample file: Sample file:
<selfassessment> <selfassessment>
...@@ -82,11 +82,14 @@ class SelfAssessmentModule(XModule): ...@@ -82,11 +82,14 @@ class SelfAssessmentModule(XModule):
<submitmessage> <submitmessage>
Thanks for submitting! Thanks for submitting!
</submitmessage> </submitmessage>
<maxattempts>
1
</maxattempts>
</selfassessment> </selfassessment>
""" """
#Initialize variables #Initialize variables
self.answer = "" self.answer = []
self.score = 0 self.score = 0
self.top_score = 1 self.top_score = 1
self.attempts = 0 self.attempts = 0
...@@ -109,7 +112,10 @@ class SelfAssessmentModule(XModule): ...@@ -109,7 +112,10 @@ class SelfAssessmentModule(XModule):
self.attempts = instance_state['attempts'] self.attempts = instance_state['attempts']
if instance_state is not None and 'student_answers' in instance_state: if instance_state is not None and 'student_answers' in instance_state:
self.answer = instance_state['student_answers'] if(type(instance_state['student_answers']) in [type(u''),type('')]):
self.answer = self.answer.append(instance_state['student_answers'])
elif(type(instance_state['student_answers'])==type([])):
self.answer = instance_state['student_answers']
if instance_state is not None and 'done' in instance_state: if instance_state is not None and 'done' in instance_state:
self.done = instance_state['done'] self.done = instance_state['done']
...@@ -125,6 +131,13 @@ class SelfAssessmentModule(XModule): ...@@ -125,6 +131,13 @@ class SelfAssessmentModule(XModule):
#Parse definition file #Parse definition file
dom2 = etree.fromstring("<selfassessment>" + self.definition['data'] + "</selfassessment>") dom2 = etree.fromstring("<selfassessment>" + self.definition['data'] + "</selfassessment>")
max_attempt_parsed=dom2.xpath('maxattempts')[0].text
try:
self.max_attempts=int(max_attempt_parsed)
except:
pass
#Extract problem, submission message and rubric from definition file #Extract problem, submission message and rubric from definition file
self.rubric = "<br/>" + ''.join([etree.tostring(child) for child in only_one(dom2.xpath('rubric'))]) self.rubric = "<br/>" + ''.join([etree.tostring(child) for child in only_one(dom2.xpath('rubric'))])
self.problem = ''.join([etree.tostring(child) for child in only_one(dom2.xpath('problem'))]) self.problem = ''.join([etree.tostring(child) for child in only_one(dom2.xpath('problem'))])
...@@ -152,8 +165,8 @@ class SelfAssessmentModule(XModule): ...@@ -152,8 +165,8 @@ class SelfAssessmentModule(XModule):
rubric_header=('<br/><br/><b>Rubric</b>') rubric_header=('<br/><br/><b>Rubric</b>')
#Combine problem, rubric, and the forms #Combine problem, rubric, and the forms
if self.answer is not "" : if type(self.answer)==type([]) and self.answer is not [] :
answer_html="<br/>Previous answer: {0}<br/>".format(self.answer) answer_html="<br/>Previous answer: {0}<br/>".format(self.answer[len(self.answer)-1])
self.problem = ''.join([self.problem, answer_html, problem_form]) self.problem = ''.join([self.problem, answer_html, problem_form])
else: else:
self.problem = ''.join([self.problem, problem_form]) self.problem = ''.join([self.problem, problem_form])
...@@ -218,7 +231,7 @@ class SelfAssessmentModule(XModule): ...@@ -218,7 +231,7 @@ class SelfAssessmentModule(XModule):
""" """
#Check to see if attempts are less than max #Check to see if attempts are less than max
if(self.attempts < self.max_attempts): if(self.attempts < self.max_attempts):
self.answer = get.keys()[0] self.answer = self.answer.append(get.keys()[0])
log.debug(self.answer) log.debug(self.answer)
return {'success': True, 'rubric': self.rubric} return {'success': True, 'rubric': self.rubric}
else: else:
......
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