diff --git a/courseware/models.py b/courseware/models.py index 6a039447e8..75b63cf9c7 100644 --- a/courseware/models.py +++ b/courseware/models.py @@ -41,19 +41,21 @@ from django.contrib.auth.models import User class StudentModule(models.Model): # For a homework problem, contains a JSON # 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) grade = models.FloatField(null=True, blank=True) - student = models.ForeignKey(User) MODULE_TYPES = (('problem','problem'), ('video','video'), ('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) modified = models.DateTimeField(auto_now=True) - class Meta: - unique_together = (('student', 'module_id', 'module_type'),) def __unicode__(self): return self.module_type+'/'+self.student.username+"/"+self.module_id+'/'+str(self.state)[:20] diff --git a/courseware/module_render.py b/courseware/module_render.py index 395630fb0b..97ca31c0c1 100644 --- a/courseware/module_render.py +++ b/courseware/module_render.py @@ -37,6 +37,7 @@ modx_modules={'problem':capa_module.LoncapaModule, def modx_dispatch(request, module=None, dispatch=None, id=None): ''' Generic view for extensions. ''' + # Grab the student information for the module from the database s = StudentModule.objects.filter(module_type=module, student=request.user, module_id=id) @@ -52,17 +53,22 @@ def modx_dispatch(request, module=None, dispatch=None, id=None): 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) + # Create the module instance=modx_modules[module](xml, s.module_id, ajax_url=ajax_url, 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.grade=instance.get_score()['score'] 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): ''' Layout module which lays out content vertically.