Commit 40efe3e7 by Piotr Mitros

merge

parents a3914cc1 e27d9f41
import uuid
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
## CRITICAL TODO/SECURITY
# Sanitize all fields.
# This is not visible to other users, but could introduce holes later
user = models.ForeignKey(User, unique=True, db_index=True)
name = models.TextField(blank=True)
language = models.TextField(blank=True)
location = models.TextField(blank=True)
meta = models.TextField(blank=True) # JSON dictionary for future expansion
courseware = models.TextField(blank=True, default='course.xml')
# class UserTestGroup(models.Model):
# ''' Group used for user tests.
# E.g. groupname = 'metacognition' and groupsection = ['A','B']
# '''
# groupname = models.TextField(blank=True)
# groupsection = models.TextField(blank=True)
# user = models.ManyToManyField(User)
class Registration(models.Model):
''' Allows us to wait for e-mail before user is registered. A
registration profile is created when the user creates an
account, but that account is inactive. Once the user clicks
on the activation key, it becomes active. '''
user = models.ForeignKey(User, unique=True)
activation_key = models.CharField(('activation key'), max_length=32, unique=True, db_index=True)
def register(self, user):
# MINOR TODO: Switch to crypto-secure key
self.activation_key=uuid.uuid4().hex
self.user=user
self.save()
def activate(self):
self.user.is_active = True
self.user.save()
self.delete()
...@@ -13,7 +13,7 @@ from django.db import connection ...@@ -13,7 +13,7 @@ from django.db import connection
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.shortcuts import redirect from django.shortcuts import redirect
from mitxmako.shortcuts import render_to_response, render_to_string from mitxmako.shortcuts import render_to_response, render_to_string
from models import Registration, UserProfile from courseware.models import Registration, UserProfile
log = logging.getLogger("mitx.auth") log = logging.getLogger("mitx.auth")
......
import copy import copy
import logging
import math import math
import numpy import numpy
import os import os
...@@ -19,6 +20,8 @@ from responsetypes import numericalresponse, formularesponse, customresponse, sc ...@@ -19,6 +20,8 @@ from responsetypes import numericalresponse, formularesponse, customresponse, sc
import calc import calc
import eia import eia
log = logging.getLogger("mitx.courseware")
response_types = {'numericalresponse':numericalresponse, response_types = {'numericalresponse':numericalresponse,
'formularesponse':formularesponse, 'formularesponse':formularesponse,
'customresponse':customresponse, 'customresponse':customresponse,
...@@ -80,6 +83,7 @@ class LoncapaProblem(object): ...@@ -80,6 +83,7 @@ class LoncapaProblem(object):
self.seed=struct.unpack('i', os.urandom(4))[0] self.seed=struct.unpack('i', os.urandom(4))[0]
## Parse XML file ## Parse XML file
log.debug(u"LoncapaProblem() opening file {0}".format(filename))
file_text = open(filename).read() file_text = open(filename).read()
# Convert startouttext and endouttext to proper <text></text> # Convert startouttext and endouttext to proper <text></text>
# TODO: Do with XML operations # TODO: Do with XML operations
......
...@@ -7,7 +7,7 @@ from mako.lookup import TemplateLookup ...@@ -7,7 +7,7 @@ from mako.lookup import TemplateLookup
try: # This lets us do __name__ == ='__main__' try: # This lets us do __name__ == ='__main__'
from django.conf import settings from django.conf import settings
from auth.models import UserProfile from models import UserProfile
except: except:
settings = None settings = None
......
"""
WE'RE USING MIGRATIONS!
If you make changes to this model, be sure to create an appropriate migration
file and check it in at the same time as your model changes. To do that,
1. Go to the mitx dir
2. ./manage.py schemamigration courseware --auto description_of_your_change
3. Add the migration file created in mitx/courseware/migrations/
"""
import uuid
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
...@@ -9,9 +22,9 @@ class StudentModule(models.Model): ...@@ -9,9 +22,9 @@ class StudentModule(models.Model):
('html','html'), ('html','html'),
) )
## These three are the key for the object ## These three are the key for the object
module_type = models.CharField(max_length=32, choices=MODULE_TYPES, default='problem') module_type = models.CharField(max_length=32, choices=MODULE_TYPES, default='problem', db_index=True)
module_id = models.CharField(max_length=255) # Filename for homeworks, etc. module_id = models.CharField(max_length=255, db_index=True) # Filename for homeworks, etc.
student = models.ForeignKey(User) student = models.ForeignKey(User, db_index=True)
class Meta: class Meta:
unique_together = (('student', 'module_id', 'module_type'),) unique_together = (('student', 'module_id', 'module_type'),)
...@@ -19,7 +32,7 @@ class StudentModule(models.Model): ...@@ -19,7 +32,7 @@ class StudentModule(models.Model):
state = models.TextField(null=True, blank=True) state = models.TextField(null=True, blank=True)
## Grade, and are we done? ## Grade, and are we done?
grade = models.FloatField(null=True, blank=True) grade = models.FloatField(null=True, blank=True, db_index=True)
#max_grade = models.FloatField(null=True, blank=True) #max_grade = models.FloatField(null=True, blank=True)
# DONE_TYPES = (('done','DONE'), # Finished # DONE_TYPES = (('done','DONE'), # Finished
...@@ -27,8 +40,47 @@ class StudentModule(models.Model): ...@@ -27,8 +40,47 @@ class StudentModule(models.Model):
# ('na','NA')) # Not applicable (e.g. vertical) # ('na','NA')) # Not applicable (e.g. vertical)
# done = models.CharField(max_length=16, choices=DONE_TYPES) # done = models.CharField(max_length=16, choices=DONE_TYPES)
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True, db_index=True)
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True, db_index=True)
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]
class UserProfile(models.Model):
class Meta:
db_table = "auth_userprofile"
## CRITICAL TODO/SECURITY
# Sanitize all fields.
# This is not visible to other users, but could introduce holes later
user = models.ForeignKey(User, unique=True, db_index=True)
name = models.TextField(blank=True, db_index=True)
language = models.TextField(blank=True, db_index=True)
location = models.TextField(blank=True, db_index=True)
meta = models.TextField(blank=True) # JSON dictionary for future expansion
courseware = models.TextField(blank=True, default='course.xml')
class Registration(models.Model):
''' Allows us to wait for e-mail before user is registered. A
registration profile is created when the user creates an
account, but that account is inactive. Once the user clicks
on the activation key, it becomes active. '''
class Meta:
db_table = "auth_registration"
user = models.ForeignKey(User, unique=True)
activation_key = models.CharField(('activation key'), max_length=32, unique=True, db_index=True)
def register(self, user):
# MINOR TODO: Switch to crypto-secure key
self.activation_key=uuid.uuid4().hex
self.user=user
self.save()
def activate(self):
self.user.is_active = True
self.user.save()
self.delete()
...@@ -19,8 +19,7 @@ from django.template import Context ...@@ -19,8 +19,7 @@ from django.template import Context
from django.template import Context, loader from django.template import Context, loader
from mitxmako.shortcuts import render_to_response, render_to_string from mitxmako.shortcuts import render_to_response, render_to_string
from auth.models import UserProfile from models import StudentModule, UserProfile
from models import StudentModule
import track.views import track.views
import courseware.content_parser as content_parser import courseware.content_parser as content_parser
......
...@@ -17,8 +17,7 @@ from django.db import connection ...@@ -17,8 +17,7 @@ from django.db import connection
from lxml import etree from lxml import etree
from auth.models import UserProfile from models import StudentModule, UserProfile
from models import StudentModule
from module_render import render_module, modx_dispatch from module_render import render_module, modx_dispatch
import courseware.content_parser as content_parser import courseware.content_parser as content_parser
import courseware.modules.capa_module import courseware.modules.capa_module
......
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