From b0451083501f3999c1f64a9d7b8f92f58c234df0 Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Wed, 1 Feb 2012 12:28:50 -0500 Subject: [PATCH 01/14] Add indexes to fields in courseware.StudentModule --- courseware/migrations/0001_initial.py | 112 ++++++++++++++++++++ courseware/migrations/0002_add_indexes.py | 120 ++++++++++++++++++++++ courseware/migrations/__init__.py | 0 courseware/models.py | 10 +- 4 files changed, 237 insertions(+), 5 deletions(-) create mode 100644 courseware/migrations/0001_initial.py create mode 100644 courseware/migrations/0002_add_indexes.py create mode 100644 courseware/migrations/__init__.py diff --git a/courseware/migrations/0001_initial.py b/courseware/migrations/0001_initial.py new file mode 100644 index 0000000000..205ed97136 --- /dev/null +++ b/courseware/migrations/0001_initial.py @@ -0,0 +1,112 @@ +# encoding: utf-8 +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + +class Migration(SchemaMigration): + + def forwards(self, orm): + + # Adding model 'StudentModule' + db.create_table('courseware_studentmodule', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('module_type', self.gf('django.db.models.fields.CharField')(default='problem', max_length=32)), + ('module_id', self.gf('django.db.models.fields.CharField')(max_length=255)), + ('student', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])), + ('state', self.gf('django.db.models.fields.TextField')(null=True, blank=True)), + ('grade', self.gf('django.db.models.fields.FloatField')(null=True, blank=True)), + ('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), + ('modified', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)), + )) + db.send_create_signal('courseware', ['StudentModule']) + + # Adding unique constraint on 'StudentModule', fields ['student', 'module_id', 'module_type'] + db.create_unique('courseware_studentmodule', ['student_id', 'module_id', 'module_type']) + + + def backwards(self, orm): + + # Removing unique constraint on 'StudentModule', fields ['student', 'module_id', 'module_type'] + db.delete_unique('courseware_studentmodule', ['student_id', 'module_id', 'module_type']) + + # Deleting model 'StudentModule' + db.delete_table('courseware_studentmodule') + + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'about': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'avatar_type': ('django.db.models.fields.CharField', [], {'default': "'n'", 'max_length': '1'}), + 'bronze': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'consecutive_days_visit_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'country': ('django_countries.fields.CountryField', [], {'max_length': '2', 'blank': 'True'}), + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'date_of_birth': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + 'display_tag_filter_strategy': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'email_isvalid': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'email_key': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}), + 'email_tag_filter_strategy': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'gold': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'gravatar': ('django.db.models.fields.CharField', [], {'max_length': '32'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ignored_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'interesting_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'last_seen': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), + 'new_response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'questions_per_page': ('django.db.models.fields.SmallIntegerField', [], {'default': '10'}), + 'real_name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), + 'reputation': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}), + 'seen_response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'show_country': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'silver': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'status': ('django.db.models.fields.CharField', [], {'default': "'w'", 'max_length': '2'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}), + 'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'courseware.studentmodule': { + 'Meta': {'unique_together': "(('student', 'module_id', 'module_type'),)", 'object_name': 'StudentModule'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'grade': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'module_id': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'module_type': ('django.db.models.fields.CharField', [], {'default': "'problem'", 'max_length': '32'}), + 'state': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'student': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) + } + } + + complete_apps = ['courseware'] diff --git a/courseware/migrations/0002_add_indexes.py b/courseware/migrations/0002_add_indexes.py new file mode 100644 index 0000000000..02f28c9f78 --- /dev/null +++ b/courseware/migrations/0002_add_indexes.py @@ -0,0 +1,120 @@ +# encoding: utf-8 +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + +class Migration(SchemaMigration): + + def forwards(self, orm): + + # Adding index on 'StudentModule', fields ['created'] + db.create_index('courseware_studentmodule', ['created']) + + # Adding index on 'StudentModule', fields ['grade'] + db.create_index('courseware_studentmodule', ['grade']) + + # Adding index on 'StudentModule', fields ['modified'] + db.create_index('courseware_studentmodule', ['modified']) + + # Adding index on 'StudentModule', fields ['module_type'] + db.create_index('courseware_studentmodule', ['module_type']) + + # Adding index on 'StudentModule', fields ['module_id'] + db.create_index('courseware_studentmodule', ['module_id']) + + + def backwards(self, orm): + + # Removing index on 'StudentModule', fields ['module_id'] + db.delete_index('courseware_studentmodule', ['module_id']) + + # Removing index on 'StudentModule', fields ['module_type'] + db.delete_index('courseware_studentmodule', ['module_type']) + + # Removing index on 'StudentModule', fields ['modified'] + db.delete_index('courseware_studentmodule', ['modified']) + + # Removing index on 'StudentModule', fields ['grade'] + db.delete_index('courseware_studentmodule', ['grade']) + + # Removing index on 'StudentModule', fields ['created'] + db.delete_index('courseware_studentmodule', ['created']) + + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'about': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'avatar_type': ('django.db.models.fields.CharField', [], {'default': "'n'", 'max_length': '1'}), + 'bronze': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'consecutive_days_visit_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'country': ('django_countries.fields.CountryField', [], {'max_length': '2', 'blank': 'True'}), + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'date_of_birth': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + 'display_tag_filter_strategy': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'email_isvalid': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'email_key': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}), + 'email_tag_filter_strategy': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'gold': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'gravatar': ('django.db.models.fields.CharField', [], {'max_length': '32'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ignored_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'interesting_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'last_seen': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), + 'new_response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'questions_per_page': ('django.db.models.fields.SmallIntegerField', [], {'default': '10'}), + 'real_name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), + 'reputation': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}), + 'seen_response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'show_country': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'silver': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'status': ('django.db.models.fields.CharField', [], {'default': "'w'", 'max_length': '2'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}), + 'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'courseware.studentmodule': { + 'Meta': {'unique_together': "(('student', 'module_id', 'module_type'),)", 'object_name': 'StudentModule'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}), + 'grade': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}), + 'module_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'module_type': ('django.db.models.fields.CharField', [], {'default': "'problem'", 'max_length': '32', 'db_index': 'True'}), + 'state': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'student': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) + } + } + + complete_apps = ['courseware'] diff --git a/courseware/migrations/__init__.py b/courseware/migrations/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/courseware/models.py b/courseware/models.py index 5c706f10a8..3b0247487d 100644 --- a/courseware/models.py +++ b/courseware/models.py @@ -9,8 +9,8 @@ class StudentModule(models.Model): ('html','html'), ) ## These three are the key for the object - module_type = models.CharField(max_length=32, choices=MODULE_TYPES, default='problem') - module_id = models.CharField(max_length=255) # Filename for homeworks, etc. + module_type = models.CharField(max_length=32, choices=MODULE_TYPES, default='problem', db_index=True) + module_id = models.CharField(max_length=255, db_index=True) # Filename for homeworks, etc. student = models.ForeignKey(User) class Meta: unique_together = (('student', 'module_id', 'module_type'),) @@ -19,7 +19,7 @@ class StudentModule(models.Model): state = models.TextField(null=True, blank=True) ## 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) # DONE_TYPES = (('done','DONE'), # Finished @@ -27,8 +27,8 @@ class StudentModule(models.Model): # ('na','NA')) # Not applicable (e.g. vertical) # done = models.CharField(max_length=16, choices=DONE_TYPES) - created = models.DateTimeField(auto_now_add=True) - modified = models.DateTimeField(auto_now=True) + created = models.DateTimeField(auto_now_add=True, db_index=True) + modified = models.DateTimeField(auto_now=True, db_index=True) def __unicode__(self): return self.module_type+'/'+self.student.username+"/"+self.module_id+'/'+str(self.state)[:20] From 2cd105ceef9db0cb84d2f1c6e6a8722f02193537 Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Wed, 1 Feb 2012 16:28:03 -0500 Subject: [PATCH 02/14] move local auth models into courseware, remove courseware migrations --- auth/models.py | 35 ------- auth/views.py | 2 +- courseware/content_parser.py | 2 +- courseware/migrations/0001_initial.py | 112 -------------------- courseware/migrations/0002_add_indexes.py | 120 ---------------------- courseware/migrations/__init__.py | 0 courseware/models.py | 50 ++++++++- courseware/module_render.py | 3 +- courseware/views.py | 3 +- 9 files changed, 49 insertions(+), 278 deletions(-) delete mode 100644 auth/models.py delete mode 100644 courseware/migrations/0001_initial.py delete mode 100644 courseware/migrations/0002_add_indexes.py delete mode 100644 courseware/migrations/__init__.py diff --git a/auth/models.py b/auth/models.py deleted file mode 100644 index 88cdd2da61..0000000000 --- a/auth/models.py +++ /dev/null @@ -1,35 +0,0 @@ -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 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() - diff --git a/auth/views.py b/auth/views.py index 8336afa65b..655a0a8634 100644 --- a/auth/views.py +++ b/auth/views.py @@ -13,7 +13,7 @@ from django.db import connection from django.http import HttpResponse, Http404 from django.shortcuts import redirect 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") diff --git a/courseware/content_parser.py b/courseware/content_parser.py index a783a172a4..299eae4ca0 100644 --- a/courseware/content_parser.py +++ b/courseware/content_parser.py @@ -6,7 +6,7 @@ from mako.template import Template try: # This lets us do __name__ == ='__main__' from django.conf import settings - from auth.models import UserProfile + from models import UserProfile except: settings = None diff --git a/courseware/migrations/0001_initial.py b/courseware/migrations/0001_initial.py deleted file mode 100644 index 205ed97136..0000000000 --- a/courseware/migrations/0001_initial.py +++ /dev/null @@ -1,112 +0,0 @@ -# encoding: utf-8 -import datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - -class Migration(SchemaMigration): - - def forwards(self, orm): - - # Adding model 'StudentModule' - db.create_table('courseware_studentmodule', ( - ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('module_type', self.gf('django.db.models.fields.CharField')(default='problem', max_length=32)), - ('module_id', self.gf('django.db.models.fields.CharField')(max_length=255)), - ('student', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])), - ('state', self.gf('django.db.models.fields.TextField')(null=True, blank=True)), - ('grade', self.gf('django.db.models.fields.FloatField')(null=True, blank=True)), - ('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), - ('modified', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)), - )) - db.send_create_signal('courseware', ['StudentModule']) - - # Adding unique constraint on 'StudentModule', fields ['student', 'module_id', 'module_type'] - db.create_unique('courseware_studentmodule', ['student_id', 'module_id', 'module_type']) - - - def backwards(self, orm): - - # Removing unique constraint on 'StudentModule', fields ['student', 'module_id', 'module_type'] - db.delete_unique('courseware_studentmodule', ['student_id', 'module_id', 'module_type']) - - # Deleting model 'StudentModule' - db.delete_table('courseware_studentmodule') - - - models = { - 'auth.group': { - 'Meta': {'object_name': 'Group'}, - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), - 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) - }, - 'auth.permission': { - 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, - 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) - }, - 'auth.user': { - 'Meta': {'object_name': 'User'}, - 'about': ('django.db.models.fields.TextField', [], {'blank': 'True'}), - 'avatar_type': ('django.db.models.fields.CharField', [], {'default': "'n'", 'max_length': '1'}), - 'bronze': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), - 'consecutive_days_visit_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), - 'country': ('django_countries.fields.CountryField', [], {'max_length': '2', 'blank': 'True'}), - 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'date_of_birth': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), - 'display_tag_filter_strategy': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), - 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), - 'email_isvalid': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'email_key': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}), - 'email_tag_filter_strategy': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}), - 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'gold': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), - 'gravatar': ('django.db.models.fields.CharField', [], {'max_length': '32'}), - 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'ignored_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}), - 'interesting_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}), - 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), - 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'last_seen': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), - 'new_response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), - 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), - 'questions_per_page': ('django.db.models.fields.SmallIntegerField', [], {'default': '10'}), - 'real_name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), - 'reputation': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}), - 'seen_response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), - 'show_country': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'silver': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), - 'status': ('django.db.models.fields.CharField', [], {'default': "'w'", 'max_length': '2'}), - 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), - 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}), - 'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}) - }, - 'contenttypes.contenttype': { - 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, - 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) - }, - 'courseware.studentmodule': { - 'Meta': {'unique_together': "(('student', 'module_id', 'module_type'),)", 'object_name': 'StudentModule'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'grade': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'module_id': ('django.db.models.fields.CharField', [], {'max_length': '255'}), - 'module_type': ('django.db.models.fields.CharField', [], {'default': "'problem'", 'max_length': '32'}), - 'state': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), - 'student': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) - } - } - - complete_apps = ['courseware'] diff --git a/courseware/migrations/0002_add_indexes.py b/courseware/migrations/0002_add_indexes.py deleted file mode 100644 index 02f28c9f78..0000000000 --- a/courseware/migrations/0002_add_indexes.py +++ /dev/null @@ -1,120 +0,0 @@ -# encoding: utf-8 -import datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - -class Migration(SchemaMigration): - - def forwards(self, orm): - - # Adding index on 'StudentModule', fields ['created'] - db.create_index('courseware_studentmodule', ['created']) - - # Adding index on 'StudentModule', fields ['grade'] - db.create_index('courseware_studentmodule', ['grade']) - - # Adding index on 'StudentModule', fields ['modified'] - db.create_index('courseware_studentmodule', ['modified']) - - # Adding index on 'StudentModule', fields ['module_type'] - db.create_index('courseware_studentmodule', ['module_type']) - - # Adding index on 'StudentModule', fields ['module_id'] - db.create_index('courseware_studentmodule', ['module_id']) - - - def backwards(self, orm): - - # Removing index on 'StudentModule', fields ['module_id'] - db.delete_index('courseware_studentmodule', ['module_id']) - - # Removing index on 'StudentModule', fields ['module_type'] - db.delete_index('courseware_studentmodule', ['module_type']) - - # Removing index on 'StudentModule', fields ['modified'] - db.delete_index('courseware_studentmodule', ['modified']) - - # Removing index on 'StudentModule', fields ['grade'] - db.delete_index('courseware_studentmodule', ['grade']) - - # Removing index on 'StudentModule', fields ['created'] - db.delete_index('courseware_studentmodule', ['created']) - - - models = { - 'auth.group': { - 'Meta': {'object_name': 'Group'}, - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), - 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) - }, - 'auth.permission': { - 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, - 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) - }, - 'auth.user': { - 'Meta': {'object_name': 'User'}, - 'about': ('django.db.models.fields.TextField', [], {'blank': 'True'}), - 'avatar_type': ('django.db.models.fields.CharField', [], {'default': "'n'", 'max_length': '1'}), - 'bronze': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), - 'consecutive_days_visit_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), - 'country': ('django_countries.fields.CountryField', [], {'max_length': '2', 'blank': 'True'}), - 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'date_of_birth': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), - 'display_tag_filter_strategy': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), - 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), - 'email_isvalid': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'email_key': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}), - 'email_tag_filter_strategy': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}), - 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'gold': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), - 'gravatar': ('django.db.models.fields.CharField', [], {'max_length': '32'}), - 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'ignored_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}), - 'interesting_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}), - 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), - 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'last_seen': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), - 'new_response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), - 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), - 'questions_per_page': ('django.db.models.fields.SmallIntegerField', [], {'default': '10'}), - 'real_name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), - 'reputation': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}), - 'seen_response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), - 'show_country': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'silver': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), - 'status': ('django.db.models.fields.CharField', [], {'default': "'w'", 'max_length': '2'}), - 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), - 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}), - 'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}) - }, - 'contenttypes.contenttype': { - 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, - 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) - }, - 'courseware.studentmodule': { - 'Meta': {'unique_together': "(('student', 'module_id', 'module_type'),)", 'object_name': 'StudentModule'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}), - 'grade': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}), - 'module_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), - 'module_type': ('django.db.models.fields.CharField', [], {'default': "'problem'", 'max_length': '32', 'db_index': 'True'}), - 'state': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), - 'student': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) - } - } - - complete_apps = ['courseware'] diff --git a/courseware/migrations/__init__.py b/courseware/migrations/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/courseware/models.py b/courseware/models.py index 3b0247487d..32462bc1c6 100644 --- a/courseware/models.py +++ b/courseware/models.py @@ -9,8 +9,8 @@ class StudentModule(models.Model): ('html','html'), ) ## These three are the key for the object - module_type = models.CharField(max_length=32, choices=MODULE_TYPES, default='problem', db_index=True) - module_id = models.CharField(max_length=255, db_index=True) # Filename for homeworks, etc. + 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'),) @@ -19,7 +19,7 @@ class StudentModule(models.Model): state = models.TextField(null=True, blank=True) ## Grade, and are we done? - grade = models.FloatField(null=True, blank=True, db_index=True) + grade = models.FloatField(null=True, blank=True) #max_grade = models.FloatField(null=True, blank=True) # DONE_TYPES = (('done','DONE'), # Finished @@ -27,8 +27,48 @@ class StudentModule(models.Model): # ('na','NA')) # Not applicable (e.g. vertical) # done = models.CharField(max_length=16, choices=DONE_TYPES) - created = models.DateTimeField(auto_now_add=True, db_index=True) - modified = models.DateTimeField(auto_now=True, db_index=True) + created = models.DateTimeField(auto_now_add=True) + modified = models.DateTimeField(auto_now=True) def __unicode__(self): 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) + 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 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_userprofile" + + 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() + diff --git a/courseware/module_render.py b/courseware/module_render.py index 6aa407bf80..85ece0f9cc 100644 --- a/courseware/module_render.py +++ b/courseware/module_render.py @@ -19,8 +19,7 @@ from django.template import Context from django.template import Context, loader from mitxmako.shortcuts import render_to_response, render_to_string -from auth.models import UserProfile -from models import StudentModule +from models import StudentModule, UserProfile import track.views import courseware.content_parser as content_parser diff --git a/courseware/views.py b/courseware/views.py index f7035975df..ffcac16951 100644 --- a/courseware/views.py +++ b/courseware/views.py @@ -17,8 +17,7 @@ from django.db import connection from lxml import etree -from auth.models import UserProfile -from models import StudentModule +from models import StudentModule, UserProfile from module_render import render_module, modx_dispatch import courseware.content_parser as content_parser import courseware.modules.capa_module From 4926701efbba69362d19afdcb34c1eba4345b70a Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Wed, 1 Feb 2012 16:40:49 -0500 Subject: [PATCH 03/14] add migrations for initial courseware and adding indexes --- courseware/migrations/0001_initial.py | 154 ++++++++++++++++++++++ courseware/migrations/0002_add_indexes.py | 154 ++++++++++++++++++++++ courseware/migrations/__init__.py | 0 courseware/models.py | 19 ++- 4 files changed, 317 insertions(+), 10 deletions(-) create mode 100644 courseware/migrations/0001_initial.py create mode 100644 courseware/migrations/0002_add_indexes.py create mode 100644 courseware/migrations/__init__.py diff --git a/courseware/migrations/0001_initial.py b/courseware/migrations/0001_initial.py new file mode 100644 index 0000000000..367c9f99cf --- /dev/null +++ b/courseware/migrations/0001_initial.py @@ -0,0 +1,154 @@ +# encoding: utf-8 +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + +class Migration(SchemaMigration): + + def forwards(self, orm): + + # Adding model 'StudentModule' + db.create_table('courseware_studentmodule', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('module_type', self.gf('django.db.models.fields.CharField')(default='problem', max_length=32)), + ('module_id', self.gf('django.db.models.fields.CharField')(max_length=255)), + ('student', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])), + ('state', self.gf('django.db.models.fields.TextField')(null=True, blank=True)), + ('grade', self.gf('django.db.models.fields.FloatField')(null=True, blank=True)), + ('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), + ('modified', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)), + )) + db.send_create_signal('courseware', ['StudentModule']) + + # Adding unique constraint on 'StudentModule', fields ['student', 'module_id', 'module_type'] + db.create_unique('courseware_studentmodule', ['student_id', 'module_id', 'module_type']) + + # Adding model 'UserProfile' + db.create_table('auth_userprofile', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], unique=True)), + ('name', self.gf('django.db.models.fields.TextField')(blank=True)), + ('language', self.gf('django.db.models.fields.TextField')(blank=True)), + ('location', self.gf('django.db.models.fields.TextField')(blank=True)), + ('meta', self.gf('django.db.models.fields.TextField')(blank=True)), + ('courseware', self.gf('django.db.models.fields.TextField')(default='course.xml', blank=True)), + )) + db.send_create_signal('courseware', ['UserProfile']) + + # Adding model 'Registration' + db.create_table('auth_userprofile', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], unique=True)), + ('activation_key', self.gf('django.db.models.fields.CharField')(unique=True, max_length=32, db_index=True)), + )) + db.send_create_signal('courseware', ['Registration']) + + + def backwards(self, orm): + + # Removing unique constraint on 'StudentModule', fields ['student', 'module_id', 'module_type'] + db.delete_unique('courseware_studentmodule', ['student_id', 'module_id', 'module_type']) + + # Deleting model 'StudentModule' + db.delete_table('courseware_studentmodule') + + # Deleting model 'UserProfile' + db.delete_table('auth_userprofile') + + # Deleting model 'Registration' + db.delete_table('auth_userprofile') + + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'about': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'avatar_type': ('django.db.models.fields.CharField', [], {'default': "'n'", 'max_length': '1'}), + 'bronze': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'consecutive_days_visit_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'country': ('django_countries.fields.CountryField', [], {'max_length': '2', 'blank': 'True'}), + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'date_of_birth': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + 'display_tag_filter_strategy': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'email_isvalid': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'email_key': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}), + 'email_tag_filter_strategy': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'gold': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'gravatar': ('django.db.models.fields.CharField', [], {'max_length': '32'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ignored_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'interesting_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'last_seen': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), + 'new_response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'questions_per_page': ('django.db.models.fields.SmallIntegerField', [], {'default': '10'}), + 'real_name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), + 'reputation': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}), + 'seen_response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'show_country': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'silver': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'status': ('django.db.models.fields.CharField', [], {'default': "'w'", 'max_length': '2'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}), + 'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'courseware.registration': { + 'Meta': {'object_name': 'Registration', 'db_table': "'auth_userprofile'"}, + 'activation_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '32', 'db_index': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'}) + }, + 'courseware.studentmodule': { + 'Meta': {'unique_together': "(('student', 'module_id', 'module_type'),)", 'object_name': 'StudentModule'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'grade': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'module_id': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'module_type': ('django.db.models.fields.CharField', [], {'default': "'problem'", 'max_length': '32'}), + 'state': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'student': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) + }, + 'courseware.userprofile': { + 'Meta': {'object_name': 'UserProfile', 'db_table': "'auth_userprofile'"}, + 'courseware': ('django.db.models.fields.TextField', [], {'default': "'course.xml'", 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'language': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'location': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'meta': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'name': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'}) + } + } + + complete_apps = ['courseware'] diff --git a/courseware/migrations/0002_add_indexes.py b/courseware/migrations/0002_add_indexes.py new file mode 100644 index 0000000000..116ccfcbb8 --- /dev/null +++ b/courseware/migrations/0002_add_indexes.py @@ -0,0 +1,154 @@ +# encoding: utf-8 +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + +class Migration(SchemaMigration): + + def forwards(self, orm): + + # Adding index on 'StudentModule', fields ['created'] + db.create_index('courseware_studentmodule', ['created']) + + # Adding index on 'StudentModule', fields ['grade'] + db.create_index('courseware_studentmodule', ['grade']) + + # Adding index on 'StudentModule', fields ['modified'] + db.create_index('courseware_studentmodule', ['modified']) + + # Adding index on 'StudentModule', fields ['module_type'] + db.create_index('courseware_studentmodule', ['module_type']) + + # Adding index on 'StudentModule', fields ['module_id'] + db.create_index('courseware_studentmodule', ['module_id']) + + # Adding index on 'UserProfile', fields ['name'] + db.create_index('auth_userprofile', ['name']) + + # Adding index on 'UserProfile', fields ['language'] + db.create_index('auth_userprofile', ['language']) + + # Adding index on 'UserProfile', fields ['location'] + db.create_index('auth_userprofile', ['location']) + + + def backwards(self, orm): + + # Removing index on 'UserProfile', fields ['location'] + db.delete_index('auth_userprofile', ['location']) + + # Removing index on 'UserProfile', fields ['language'] + db.delete_index('auth_userprofile', ['language']) + + # Removing index on 'UserProfile', fields ['name'] + db.delete_index('auth_userprofile', ['name']) + + # Removing index on 'StudentModule', fields ['module_id'] + db.delete_index('courseware_studentmodule', ['module_id']) + + # Removing index on 'StudentModule', fields ['module_type'] + db.delete_index('courseware_studentmodule', ['module_type']) + + # Removing index on 'StudentModule', fields ['modified'] + db.delete_index('courseware_studentmodule', ['modified']) + + # Removing index on 'StudentModule', fields ['grade'] + db.delete_index('courseware_studentmodule', ['grade']) + + # Removing index on 'StudentModule', fields ['created'] + db.delete_index('courseware_studentmodule', ['created']) + + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'auth.user': { + 'Meta': {'object_name': 'User'}, + 'about': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'avatar_type': ('django.db.models.fields.CharField', [], {'default': "'n'", 'max_length': '1'}), + 'bronze': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'consecutive_days_visit_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'country': ('django_countries.fields.CountryField', [], {'max_length': '2', 'blank': 'True'}), + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'date_of_birth': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + 'display_tag_filter_strategy': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'email_isvalid': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'email_key': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}), + 'email_tag_filter_strategy': ('django.db.models.fields.SmallIntegerField', [], {'default': '1'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'gold': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'gravatar': ('django.db.models.fields.CharField', [], {'max_length': '32'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ignored_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'interesting_tags': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'last_seen': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), + 'new_response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'questions_per_page': ('django.db.models.fields.SmallIntegerField', [], {'default': '10'}), + 'real_name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), + 'reputation': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}), + 'seen_response_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'show_country': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'silver': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}), + 'status': ('django.db.models.fields.CharField', [], {'default': "'w'", 'max_length': '2'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}), + 'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'courseware.registration': { + 'Meta': {'object_name': 'Registration', 'db_table': "'auth_userprofile'"}, + 'activation_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '32', 'db_index': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'}) + }, + 'courseware.studentmodule': { + 'Meta': {'unique_together': "(('student', 'module_id', 'module_type'),)", 'object_name': 'StudentModule'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}), + 'grade': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}), + 'module_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'module_type': ('django.db.models.fields.CharField', [], {'default': "'problem'", 'max_length': '32', 'db_index': 'True'}), + 'state': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'student': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) + }, + 'courseware.userprofile': { + 'Meta': {'object_name': 'UserProfile', 'db_table': "'auth_userprofile'"}, + 'courseware': ('django.db.models.fields.TextField', [], {'default': "'course.xml'", 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'language': ('django.db.models.fields.TextField', [], {'db_index': 'True', 'blank': 'True'}), + 'location': ('django.db.models.fields.TextField', [], {'db_index': 'True', 'blank': 'True'}), + 'meta': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'name': ('django.db.models.fields.TextField', [], {'db_index': 'True', 'blank': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'}) + } + } + + complete_apps = ['courseware'] diff --git a/courseware/migrations/__init__.py b/courseware/migrations/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/courseware/models.py b/courseware/models.py index 32462bc1c6..7e762d89a7 100644 --- a/courseware/models.py +++ b/courseware/models.py @@ -9,9 +9,9 @@ class StudentModule(models.Model): ('html','html'), ) ## These three are the key for the object - 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) + module_type = models.CharField(max_length=32, choices=MODULE_TYPES, default='problem', db_index=True) + module_id = models.CharField(max_length=255, db_index=True) # Filename for homeworks, etc. + student = models.ForeignKey(User, db_index=True) class Meta: unique_together = (('student', 'module_id', 'module_type'),) @@ -19,7 +19,7 @@ class StudentModule(models.Model): state = models.TextField(null=True, blank=True) ## 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) # DONE_TYPES = (('done','DONE'), # Finished @@ -27,8 +27,8 @@ class StudentModule(models.Model): # ('na','NA')) # Not applicable (e.g. vertical) # done = models.CharField(max_length=16, choices=DONE_TYPES) - created = models.DateTimeField(auto_now_add=True) - modified = models.DateTimeField(auto_now=True) + created = models.DateTimeField(auto_now_add=True, db_index=True) + modified = models.DateTimeField(auto_now=True, db_index=True) def __unicode__(self): return self.module_type+'/'+self.student.username+"/"+self.module_id+'/'+str(self.state)[:20] @@ -42,9 +42,9 @@ class UserProfile(models.Model): # 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) + 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') @@ -54,7 +54,6 @@ class Registration(models.Model): 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_userprofile" From 167d2dd8fe4cd8548b1bfac479a7ae4e00fc37df Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Wed, 1 Feb 2012 17:21:54 -0500 Subject: [PATCH 04/14] adding debug logging to show how often we're opening problem files (35x for /profile) --- courseware/capa/capa_problem.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/courseware/capa/capa_problem.py b/courseware/capa/capa_problem.py index b7ac8940fe..032b5d41b4 100644 --- a/courseware/capa/capa_problem.py +++ b/courseware/capa/capa_problem.py @@ -1,4 +1,5 @@ import copy +import logging import math import numpy import os @@ -19,6 +20,8 @@ from responsetypes import numericalresponse, formularesponse, customresponse, sc import calc import eia +log = logging.getLogger("mitx.courseware") + response_types = {'numericalresponse':numericalresponse, 'formularesponse':formularesponse, 'customresponse':customresponse, @@ -80,6 +83,7 @@ class LoncapaProblem(object): self.seed=struct.unpack('i', os.urandom(4))[0] ## Parse XML file + log.debug(u"LoncapaProblem() opening file {0}".format(filename)) file_text = open(filename).read() # Convert startouttext and endouttext to proper # TODO: Do with XML operations From bf0591631d3dc6fcc9795d1d77ca82bad4b7b02f Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Wed, 1 Feb 2012 17:26:41 -0500 Subject: [PATCH 05/14] fix migration to reflect the right table name for registration --- courseware/migrations/0001_initial.py | 6 +++--- courseware/migrations/0002_add_indexes.py | 2 +- courseware/models.py | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/courseware/migrations/0001_initial.py b/courseware/migrations/0001_initial.py index 367c9f99cf..77e50322e0 100644 --- a/courseware/migrations/0001_initial.py +++ b/courseware/migrations/0001_initial.py @@ -37,7 +37,7 @@ class Migration(SchemaMigration): db.send_create_signal('courseware', ['UserProfile']) # Adding model 'Registration' - db.create_table('auth_userprofile', ( + db.create_table('auth_registration', ( ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], unique=True)), ('activation_key', self.gf('django.db.models.fields.CharField')(unique=True, max_length=32, db_index=True)), @@ -57,7 +57,7 @@ class Migration(SchemaMigration): db.delete_table('auth_userprofile') # Deleting model 'Registration' - db.delete_table('auth_userprofile') + db.delete_table('auth_registration') models = { @@ -123,7 +123,7 @@ class Migration(SchemaMigration): 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) }, 'courseware.registration': { - 'Meta': {'object_name': 'Registration', 'db_table': "'auth_userprofile'"}, + 'Meta': {'object_name': 'Registration', 'db_table': "'auth_registration'"}, 'activation_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '32', 'db_index': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'}) diff --git a/courseware/migrations/0002_add_indexes.py b/courseware/migrations/0002_add_indexes.py index 116ccfcbb8..94fb6972c8 100644 --- a/courseware/migrations/0002_add_indexes.py +++ b/courseware/migrations/0002_add_indexes.py @@ -123,7 +123,7 @@ class Migration(SchemaMigration): 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) }, 'courseware.registration': { - 'Meta': {'object_name': 'Registration', 'db_table': "'auth_userprofile'"}, + 'Meta': {'object_name': 'Registration', 'db_table': "'auth_registration'"}, 'activation_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '32', 'db_index': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'}) diff --git a/courseware/models.py b/courseware/models.py index 7e762d89a7..c44b208fe3 100644 --- a/courseware/models.py +++ b/courseware/models.py @@ -1,3 +1,5 @@ +import uuid + from django.db import models from django.contrib.auth.models import User @@ -55,7 +57,7 @@ class Registration(models.Model): account, but that account is inactive. Once the user clicks on the activation key, it becomes active. ''' class Meta: - db_table = "auth_userprofile" + db_table = "auth_registration" user = models.ForeignKey(User, unique=True) activation_key = models.CharField(('activation key'), max_length=32, unique=True, db_index=True) From e27d9f41e1a7f5b1e7008e70ea0cb8c470c9bfde Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Wed, 1 Feb 2012 17:46:19 -0500 Subject: [PATCH 06/14] warning message so people know they have to use migrations for model changes --- courseware/models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/courseware/models.py b/courseware/models.py index c44b208fe3..fd88bea16c 100644 --- a/courseware/models.py +++ b/courseware/models.py @@ -1,3 +1,14 @@ +""" +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 a3914cc1ac833d7caeb33d3cb76874be42bdbeb2 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Wed, 1 Feb 2012 18:18:45 -0500 Subject: [PATCH 07/14] course.xml includes work --- auth/models.py | 8 ++++++++ courseware/content_parser.py | 12 +++++++++--- settings_new_askbot.py | 5 +++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/auth/models.py b/auth/models.py index 88cdd2da61..05a9d3028f 100644 --- a/auth/models.py +++ b/auth/models.py @@ -14,6 +14,14 @@ class UserProfile(models.Model): 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 diff --git a/courseware/content_parser.py b/courseware/content_parser.py index a783a172a4..ed0489f7f4 100644 --- a/courseware/content_parser.py +++ b/courseware/content_parser.py @@ -3,6 +3,7 @@ import hashlib from lxml import etree from mako.template import Template +from mako.lookup import TemplateLookup try: # This lets us do __name__ == ='__main__' from django.conf import settings @@ -88,12 +89,17 @@ def id_tag(course): else: elem.set('id', fasthash(etree.tostring(elem))) +template_lookup = TemplateLookup(directories = [settings.DATA_DIR], + module_directory = settings.MAKO_MODULE_DIR) + def course_file(user): # TODO: Cache. - filename = settings.DATA_DIR+UserProfile.objects.get(user=user).courseware - data_template = Template(filename=filename) + filename = UserProfile.objects.get(user=user).courseware + data_template = template_lookup.get_template(filename) - tree = etree.XML(data_template.render()) + options = {'dev_content':True} + + tree = etree.XML(data_template.render(**options)) id_tag(tree) return tree diff --git a/settings_new_askbot.py b/settings_new_askbot.py index e95d57e7a3..95b4a79d34 100644 --- a/settings_new_askbot.py +++ b/settings_new_askbot.py @@ -1,5 +1,6 @@ import os import sys +import tempfile import djcelery @@ -134,10 +135,14 @@ TRACK_MAX_EVENT = 1000 MAXLOG = 500 LOG_DIR = "/tmp/" +MAKO_MODULE_DIR = None # Make sure we execute correctly regardless of where we're called from execfile(os.path.join(BASE_DIR, "settings.py")) +if MAKO_MODULE_DIR == None: + MAKO_MODULE_DIR = tempfile.mkdtemp('mako') + # A sample logging configuration. The only tangible logging # performed by this configuration is to send an email to # the site admins on every HTTP 500 error. From 72c45e8bbb6ae5fc5f4b19a35fbc5143bb743f32 Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Wed, 1 Feb 2012 19:32:18 -0500 Subject: [PATCH 08/14] Move UserProfile and Registration out of courseware and into a renamed auth (now user) --HG-- rename : auth/__init__.py => user/__init__.py rename : auth/tests.py => user/tests.py rename : auth/views.py => user/views.py --- courseware/content_parser.py | 2 +- courseware/models.py | 39 --------------------------- courseware/module_render.py | 3 ++- courseware/views.py | 4 ++- settings_new_askbot.py | 2 +- urls.py | 16 +++++------ {auth => user}/__init__.py | 0 user/models.py | 52 ++++++++++++++++++++++++++++++++++++ {auth => user}/tests.py | 0 {auth => user}/views.py | 5 ++-- 10 files changed, 70 insertions(+), 53 deletions(-) rename {auth => user}/__init__.py (100%) create mode 100644 user/models.py rename {auth => user}/tests.py (100%) rename {auth => user}/views.py (99%) diff --git a/courseware/content_parser.py b/courseware/content_parser.py index 6203953fa4..75b14acbbe 100644 --- a/courseware/content_parser.py +++ b/courseware/content_parser.py @@ -7,7 +7,7 @@ from mako.lookup import TemplateLookup try: # This lets us do __name__ == ='__main__' from django.conf import settings - from models import UserProfile + from user.models import UserProfile except: settings = None diff --git a/courseware/models.py b/courseware/models.py index fd88bea16c..5110f1d24f 100644 --- a/courseware/models.py +++ b/courseware/models.py @@ -9,8 +9,6 @@ file and check it in at the same time as your model changes. To do that, 3. Add the migration file created in mitx/courseware/migrations/ """ -import uuid - from django.db import models from django.contrib.auth.models import User @@ -47,40 +45,3 @@ class StudentModule(models.Model): 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() - diff --git a/courseware/module_render.py b/courseware/module_render.py index 85ece0f9cc..b4a0f994ba 100644 --- a/courseware/module_render.py +++ b/courseware/module_render.py @@ -19,7 +19,8 @@ from django.template import Context from django.template import Context, loader from mitxmako.shortcuts import render_to_response, render_to_string -from models import StudentModule, UserProfile +from models import StudentModule +from user.models import UserProfile import track.views import courseware.content_parser as content_parser diff --git a/courseware/views.py b/courseware/views.py index ffcac16951..a292c577b1 100644 --- a/courseware/views.py +++ b/courseware/views.py @@ -17,8 +17,10 @@ from django.db import connection from lxml import etree -from models import StudentModule, UserProfile from module_render import render_module, modx_dispatch +from models import StudentModule +from user.models import UserProfile + import courseware.content_parser as content_parser import courseware.modules.capa_module diff --git a/settings_new_askbot.py b/settings_new_askbot.py index 95b4a79d34..30513c260a 100644 --- a/settings_new_askbot.py +++ b/settings_new_askbot.py @@ -112,7 +112,7 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', 'courseware', - 'auth', + 'user', 'django.contrib.humanize', 'static_template_view', 'staticbook', diff --git a/urls.py b/urls.py index 567d219506..b10fde59c0 100644 --- a/urls.py +++ b/urls.py @@ -10,13 +10,13 @@ import django.contrib.auth.views urlpatterns = ('', url(r'^event$', 'track.views.user_track'), url(r'^t/(?P