Commit 3aa5df6a by Ernie Park

Piotr added comments

parent 138ff04f
...@@ -41,19 +41,21 @@ from django.contrib.auth.models import User ...@@ -41,19 +41,21 @@ from django.contrib.auth.models import User
class StudentModule(models.Model): class StudentModule(models.Model):
# For a homework problem, contains a JSON # For a homework problem, contains a JSON
# object consisting of state # object consisting of state
module_type = models.CharField(max_length=32, choices=MODULE_TYPES, default='problem')
module_id = models.CharField(max_length=255) # Filename for homeworks, etc.
student = models.ForeignKey(User)
class Meta:
unique_together = (('student', 'module_id', 'module_type'),)
state = models.TextField(null=True, blank=True) state = models.TextField(null=True, blank=True)
grade = models.FloatField(null=True, blank=True) grade = models.FloatField(null=True, blank=True)
student = models.ForeignKey(User)
MODULE_TYPES = (('problem','problem'), MODULE_TYPES = (('problem','problem'),
('video','video'), ('video','video'),
('html','html'), ('html','html'),
) )
module_type = models.CharField(max_length=32, choices=MODULE_TYPES, default='problem')
module_id = models.CharField(max_length=255) # Filename for homeworks, etc.
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True)
class Meta:
unique_together = (('student', 'module_id', 'module_type'),)
def __unicode__(self): def __unicode__(self):
return self.module_type+'/'+self.student.username+"/"+self.module_id+'/'+str(self.state)[:20] return self.module_type+'/'+self.student.username+"/"+self.module_id+'/'+str(self.state)[:20]
...@@ -37,6 +37,7 @@ modx_modules={'problem':capa_module.LoncapaModule, ...@@ -37,6 +37,7 @@ modx_modules={'problem':capa_module.LoncapaModule,
def modx_dispatch(request, module=None, dispatch=None, id=None): def modx_dispatch(request, module=None, dispatch=None, id=None):
''' Generic view for extensions. ''' ''' Generic view for extensions. '''
# Grab the student information for the module from the database
s = StudentModule.objects.filter(module_type=module, s = StudentModule.objects.filter(module_type=module,
student=request.user, student=request.user,
module_id=id) module_id=id)
...@@ -52,17 +53,22 @@ def modx_dispatch(request, module=None, dispatch=None, id=None): ...@@ -52,17 +53,22 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
id_tag=modx_modules[module].id_attribute id_tag=modx_modules[module].id_attribute
# Grab the XML corresponding to the request from course.xml
xml = content_parser.module_xml(content_parser.course_file(request.user), module, id_tag, id) xml = content_parser.module_xml(content_parser.course_file(request.user), module, id_tag, id)
# Create the module
instance=modx_modules[module](xml, instance=modx_modules[module](xml,
s.module_id, s.module_id,
ajax_url=ajax_url, ajax_url=ajax_url,
state=s.state) state=s.state)
html=instance.handle_ajax(dispatch, request.POST) # Let the module handle the AJAX
ajax_return=instance.handle_ajax(dispatch, request.POST)
# Save the state back to the database
s.state=instance.get_state() s.state=instance.get_state()
s.grade=instance.get_score()['score'] s.grade=instance.get_score()['score']
s.save() s.save()
return HttpResponse(html) # Return whatever the module wanted to return to the client/caller
return HttpResponse(ajax_return)
def vertical_module(request, module): def vertical_module(request, module):
''' Layout module which lays out content vertically. ''' Layout module which lays out content vertically.
......
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