From 974f7442899840152094cc04ad062920dcdea09c Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Mon, 30 Jan 2012 15:53:16 -0500 Subject: [PATCH 01/21] Amazon S3 SSL --- settings_new_askbot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/settings_new_askbot.py b/settings_new_askbot.py index 8ff19cace5..eebdf6d653 100644 --- a/settings_new_askbot.py +++ b/settings_new_askbot.py @@ -4,9 +4,9 @@ import sys import djcelery LIB_URL = '/static/lib/' -LIB_URL = 'http://mitxstatic.s3-website-us-east-1.amazonaws.com/js/' +LIB_URL = 'https://mitxstatic.s3.amazonaws.com/js/' BOOK_URL = '/static/book/' -BOOK_URL = 'http://mitxstatic.s3-website-us-east-1.amazonaws.com/book_images/' +BOOK_URL = 'https://mitxstatic.s3.amazonaws.com/book_images/' # Our parent dir (mitx_all) is the BASE_DIR BASE_DIR = os.path.abspath(os.path.join(__file__, "..", "..")) From 811995a27ea0a5a6742b5976c91ad3156c1c5ac3 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Mon, 30 Jan 2012 16:43:17 -0500 Subject: [PATCH 02/21] Changes needed for Askbot S3 --- settings_new_askbot.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/settings_new_askbot.py b/settings_new_askbot.py index eebdf6d653..347f851b78 100644 --- a/settings_new_askbot.py +++ b/settings_new_askbot.py @@ -34,6 +34,10 @@ HTTPS = 'on' MEDIA_URL = '' MEDIA_ROOT = '' +# Needed for Askbot +# Deployed machines: Move to S3 +DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' + DEBUG = True TEMPLATE_DEBUG = DEBUG @@ -251,13 +255,15 @@ import site STATICFILES_DIRS = STATICFILES_DIRS + ( ASKBOT_DIR+'/askbot/skins',) -# Needed for Askbot -# Critical TODO: Move to S3 -MEDIA_URL = '/discussion/upfiles/' -MEDIA_ROOT = ASKBOT_DIR+'/askbot/upfiles' - ASKBOT_ROOT = os.path.dirname(askbot.__file__) +# Needed for Askbot +# Deployed machines: Move to S3 +if MEDIA_ROOT == '': + MEDIA_ROOT = ASKBOT_DIR+'/askbot/upfiles' +if MEDIA_URL == '': + MEDIA_URL = '/discussion/upfiles/' + site.addsitedir(os.path.join(os.path.dirname(askbot.__file__), 'deps')) TEMPLATE_LOADERS = TEMPLATE_LOADERS + ('askbot.skins.loaders.filesystem_load_template_source',) @@ -281,7 +287,6 @@ FILE_UPLOAD_HANDLERS = ( ASKBOT_ALLOWED_UPLOAD_FILE_TYPES = ('.jpg', '.jpeg', '.gif', '.bmp', '.png', '.tiff') ASKBOT_MAX_UPLOAD_FILE_SIZE = 1024 * 1024 #result in bytes # ASKBOT_FILE_UPLOAD_DIR = os.path.join(os.path.dirname(__file__), 'askbot', 'upfiles') -DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' PROJECT_ROOT = os.path.dirname(__file__) From cf1b0a86550c3c6fae50e83e8f17e42873d42836 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Mon, 30 Jan 2012 17:44:02 -0500 Subject: [PATCH 03/21] Seq module makes nicer class types for Kyle's video styling --- courseware/modules/seq_module.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/courseware/modules/seq_module.py b/courseware/modules/seq_module.py index 02c8320ac8..33c4088486 100644 --- a/courseware/modules/seq_module.py +++ b/courseware/modules/seq_module.py @@ -9,6 +9,10 @@ from mitxmako.shortcuts import render_to_response, render_to_string from x_module import XModule +# HACK: This shouldn't be hard-coded to two types +# OBSOLETE: This obsoletes 'type' +class_priority = ['video', 'problem'] + class SequentialModule(XModule): ''' Layout module which lays out content in a temporal sequence ''' @@ -55,10 +59,21 @@ class SequentialModule(XModule): return {'content':content, "destroy_js":m['destroy_js'], 'init_js':m['init_js'], - 'type':m['type']} + 'type': m['type']} + + + ## Returns a set of all types of all sub-children + child_classes = [set([i.tag for i in e.iter()]) for e in self.xmltree] self.contents=[(e.get("name"),j(self.render_function(e))) \ for e in self.xmltree] + + for (content, element_class) in zip(self.contents, child_classes): + new_class = 'other' + for c in class_priority: + if c in element_class: + new_class = c + content[1]['type'] = new_class js="" From ef1bc239712c0cd83becf4d191c86462fa8bd649 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Mon, 30 Jan 2012 20:19:11 -0500 Subject: [PATCH 04/21] JSON password reset --- auth/views.py | 18 ++++++++++++++++-- urls.py | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/auth/views.py b/auth/views.py index f2f945644f..8336afa65b 100644 --- a/auth/views.py +++ b/auth/views.py @@ -5,12 +5,12 @@ import string from django.conf import settings from django.contrib.auth import logout, authenticate, login -from django.contrib.auth.models import User +from django.contrib.auth.forms import PasswordResetForm from django.contrib.auth.models import User from django.core.context_processors import csrf from django.core.validators import validate_email, validate_slug from django.db import connection -from django.http import HttpResponse +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 @@ -230,3 +230,17 @@ def activate_account(request, key): if len(r)==0: return render_to_response("activation_invalid.html",{'csrf':csrf(request)['csrf_token']}) return HttpResponse("Unknown error. Please e-mail us to let us know how it happened.") + +def password_reset(request): + ''' Attempts to send a password reset e-mail. ''' + if request.method != "POST": + raise Http404 + form = PasswordResetForm(request.POST) + if form.is_valid(): + form.save( use_https = request.is_secure(), + from_email = settings.DEFAULT_FROM_EMAIL, + request = request ) + return HttpResponse(json.dumps({'success':True})) + else: + return HttpResponse(json.dumps({'success':False, + 'error': 'Invalid e-mail'})) diff --git a/urls.py b/urls.py index 5ebda7bd4e..567d219506 100644 --- a/urls.py +++ b/urls.py @@ -19,6 +19,7 @@ urlpatterns = ('', url(r'^$', 'auth.views.index'), url(r'^password_reset/$', 'django.contrib.auth.views.password_reset', dict(from_email='registration@mitx.mit.edu'),name='auth_password_reset'), +# url(r'^password_reset/$', 'auth.views.password_reset'), url(r'^password_change/$',django.contrib.auth.views.password_change,name='auth_password_change'), url(r'^password_change_done/$',django.contrib.auth.views.password_change_done,name='auth_password_change_done'), url(r'^password_reset_confirm/(?P[0-9A-Za-z]+)-(?P.+)/$',django.contrib.auth.views.password_reset_confirm, From 472a3996672f4ecac171654b2f7ca1225c21a0cc Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Tue, 31 Jan 2012 16:31:29 -0500 Subject: [PATCH 05/21] STATIC_GRAB, starting to make course.xml ready for AB tests --- courseware/content_parser.py | 6 +++++- settings_new_askbot.py | 4 ++++ static_template_view/views.py | 11 ++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/courseware/content_parser.py b/courseware/content_parser.py index fd6fbb2d58..a783a172a4 100644 --- a/courseware/content_parser.py +++ b/courseware/content_parser.py @@ -2,6 +2,7 @@ import json import hashlib from lxml import etree +from mako.template import Template try: # This lets us do __name__ == ='__main__' from django.conf import settings @@ -89,7 +90,10 @@ def id_tag(course): def course_file(user): # TODO: Cache. - tree = etree.parse(settings.DATA_DIR+UserProfile.objects.get(user=user).courseware) + filename = settings.DATA_DIR+UserProfile.objects.get(user=user).courseware + data_template = Template(filename=filename) + + tree = etree.XML(data_template.render()) id_tag(tree) return tree diff --git a/settings_new_askbot.py b/settings_new_askbot.py index 347f851b78..e95d57e7a3 100644 --- a/settings_new_askbot.py +++ b/settings_new_askbot.py @@ -3,6 +3,10 @@ import sys import djcelery +# Configuration option for when we want to grab server error pages +STATIC_GRAB = False +DEV_CONTENT = True + LIB_URL = '/static/lib/' LIB_URL = 'https://mitxstatic.s3.amazonaws.com/js/' BOOK_URL = '/static/book/' diff --git a/static_template_view/views.py b/static_template_view/views.py index 734434b43a..a66a3cd8c5 100644 --- a/static_template_view/views.py +++ b/static_template_view/views.py @@ -6,6 +6,7 @@ from mitxmako.shortcuts import render_to_response, render_to_string from django.shortcuts import redirect from django.core.context_processors import csrf +from django.conf import settings #valid_templates=['index.html', 'staff.html', 'info.html', 'credits.html'] valid_templates=['mitx_global.html', @@ -13,7 +14,15 @@ valid_templates=['mitx_global.html', 'tos.html', 'privacy.html', 'honor.html', - 'copyright.html'] + 'copyright.html', + '404.html'] + +print "!!",settings.__dict__ + +if settings.STATIC_GRAB: + valid_templates = valid_templates+['server-down.html', + 'server-error.html' + 'server-overloaded.html'] def index(request, template): csrf_token = csrf(request)['csrf_token'] From a6977aae4cf132936bb8646202aa4e34cf856a8b Mon Sep 17 00:00:00 2001 From: Ernie Park Date: Wed, 1 Feb 2012 11:59:27 -0500 Subject: [PATCH 06/21] update routes and new password_reset --- auth/views.py | 13 +++++++------ urls.py | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/auth/views.py b/auth/views.py index 8336afa65b..df6980afb5 100644 --- a/auth/views.py +++ b/auth/views.py @@ -237,10 +237,11 @@ def password_reset(request): raise Http404 form = PasswordResetForm(request.POST) if form.is_valid(): - form.save( use_https = request.is_secure(), - from_email = settings.DEFAULT_FROM_EMAIL, + form.save( use_https = request.is_secure(), + from_email = settings.DEFAULT_FROM_EMAIL, request = request ) - return HttpResponse(json.dumps({'success':True})) - else: - return HttpResponse(json.dumps({'success':False, - 'error': 'Invalid e-mail'})) + return HttpResponse(json.dumps({'success':True, + 'value': render_to_string('registration/password_reset_done.html', {})})) + else: + return HttpResponse(json.dumps({'success':False, + 'error': 'Invalid e-mail'})) diff --git a/urls.py b/urls.py index 567d219506..bd9af13d21 100644 --- a/urls.py +++ b/urls.py @@ -17,9 +17,9 @@ urlpatterns = ('', url(r'^create_account$', 'auth.views.create_account'), url(r'^activate/(?P[^/]*)$', 'auth.views.activate_account'), url(r'^$', 'auth.views.index'), - url(r'^password_reset/$', 'django.contrib.auth.views.password_reset', - dict(from_email='registration@mitx.mit.edu'),name='auth_password_reset'), -# url(r'^password_reset/$', 'auth.views.password_reset'), +# url(r'^password_reset/$', 'django.contrib.auth.views.password_reset', +# dict(from_email='registration@mitx.mit.edu'),name='auth_password_reset'), + url(r'^password_reset/$', 'auth.views.password_reset'), url(r'^password_change/$',django.contrib.auth.views.password_change,name='auth_password_change'), url(r'^password_change_done/$',django.contrib.auth.views.password_change_done,name='auth_password_change_done'), url(r'^password_reset_confirm/(?P[0-9A-Za-z]+)-(?P.+)/$',django.contrib.auth.views.password_reset_confirm, From b0451083501f3999c1f64a9d7b8f92f58c234df0 Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Wed, 1 Feb 2012 12:28:50 -0500 Subject: [PATCH 07/21] 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 08/21] 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 09/21] 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 10/21] 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 11/21] 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 12/21] 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 13/21] 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 14/21] 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