Commit b729434e by Vik Paruchuri

work on save functionality

parent 0739d3ba
...@@ -8,9 +8,7 @@ $(document).on('click', 'section.sa-wrapper input#show', ( -> ...@@ -8,9 +8,7 @@ $(document).on('click', 'section.sa-wrapper input#show', ( ->
alert("posted") alert("posted")
if response.success if response.success
alert(response.rubric) alert(response.rubric)
$('section.sa-wrapper p#rubric').replace(response.rubric) $('section.sa-wrapper p#rubric').append(response.rubric)
alert("save")
)); ));
$(document).on('click', 'section.sa-wrapper input#save', ( -> $(document).on('click', 'section.sa-wrapper input#save', ( ->
......
...@@ -6,6 +6,8 @@ import sys ...@@ -6,6 +6,8 @@ import sys
from lxml import etree from lxml import etree
from lxml.html import rewrite_links from lxml.html import rewrite_links
from path import path from path import path
import json
from progress import Progress
from .x_module import XModule from .x_module import XModule
from pkg_resources import resource_string from pkg_resources import resource_string
...@@ -36,6 +38,12 @@ def only_one(lst, default="", process=lambda x: x): ...@@ -36,6 +38,12 @@ def only_one(lst, default="", process=lambda x: x):
else: else:
raise Exception('Malformed XML') raise Exception('Malformed XML')
class ComplexEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, complex):
return "{real:.7g}{imag:+.7g}*j".format(real=obj.real, imag=obj.imag)
return json.JSONEncoder.default(self, obj)
class SelfAssessmentModule(XModule): class SelfAssessmentModule(XModule):
js = {'coffee': [resource_string(__name__, 'js/src/javascript_loader.coffee'), js = {'coffee': [resource_string(__name__, 'js/src/javascript_loader.coffee'),
...@@ -53,42 +61,31 @@ class SelfAssessmentModule(XModule): ...@@ -53,42 +61,31 @@ class SelfAssessmentModule(XModule):
instance_state=None, shared_state=None, **kwargs): instance_state=None, shared_state=None, **kwargs):
XModule.__init__(self, system, location, definition, descriptor, XModule.__init__(self, system, location, definition, descriptor,
instance_state, shared_state, **kwargs) instance_state, shared_state, **kwargs)
dom2=etree.fromstring("<selfassessment>" + self.definition['data'] + "</selfassessment>") dom2=etree.fromstring("<selfassessment>" + self.definition['data'] + "</selfassessment>")
self.rubric=''.join([etree.tostring(child) for child in only_one(dom2.xpath('rubric'))]) self.rubric=''.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'))])
problem_form=('<section class="sa-wrapper"><input type="text" name="answer" ' problem_form=('<section class="sa-wrapper"><input type="text" name="answer" '
'id="answer"/><br/>' 'id="answer"/><br/>'
'<input type="button" value="Check" id ="show" name="show" url="{0}"/>' '<input type="button" value="Check" id ="show" name="show" url="{0}"/>'
'<p id="rubric"></p></section>').format(self.location) '<p id="rubric"></p></section>').format(self.location)
self.problem=''.join([self.problem,problem_form]) self.problem=''.join([self.problem,problem_form])
self.rubric=''.join([self.rubric,rubric_form]) self.rubric=''.join([self.rubric,rubric_form])
#print(etree.tostring(rubric))
#print(etree.tostring(problem))
self.html = self.problem self.html = self.problem
self.answers={} self.answers={}
self.score=0 self.score=0
self.top_score=1
self.max_score=1
def get_score(self): def get_score(self):
return self.score return self.score
def max_score(self): def max_score(self):
return self.max_score return self.top_score
def get_progress(self): def get_progress(self):
''' For now, just return score / max_score ''' For now, just return score / max_score
''' '''
score = self.get_score() score = self.get_score()
score = d['score']
total = self.max_score() total = self.max_score()
if total > 0: if total > 0:
try: try:
...@@ -130,7 +127,7 @@ class SelfAssessmentModule(XModule): ...@@ -130,7 +127,7 @@ class SelfAssessmentModule(XModule):
def show_rubric(self,get): def show_rubric(self,get):
return {'success': True, 'rubric':rubric_form} return {'success': True, 'rubric':self.rubric}
def save_problem(self, get): def save_problem(self, get):
......
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