Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change UserProfile to Profile class.

Closes #18.

We forgot to make the link from UserProfile -> User be the attribute
"user". This fixes that, but the easiest way to migrate between models
when changing the primary key is to create a new model and copy the data
back and forth. So I've created the Profile model that mirrors the old
UserProfile, except that "student" is now called "user".
  • Loading branch information...
commit d6bef0ee0e107b50dad1c5a53b2e4b6748621116 1 parent db2e404
@malcolmt authored
View
6 minerva/admin.py
@@ -12,8 +12,8 @@ class ProgressAdmin(admin.ModelAdmin):
# TODO: Make a column that is "correct / attempts" for readability.
list_filter = ["student"]
-class UserProfileAdmin(admin.ModelAdmin):
- list_display = ("student", "language")
+class ProfileAdmin(admin.ModelAdmin):
+ list_display = ("user", "language")
list_filter = ["language"]
class SessionProgressAdmin(admin.ModelAdmin):
@@ -22,7 +22,7 @@ class SessionProgressAdmin(admin.ModelAdmin):
admin.site.register(models.Word, WordAdmin)
admin.site.register(models.Progress, ProgressAdmin)
-admin.site.register(models.UserProfile, UserProfileAdmin)
+admin.site.register(models.Profile, ProfileAdmin)
admin.site.register(models.SessionProgress, SessionProgressAdmin)
admin.site.register(models.Language)
View
6 minerva/forms.py
@@ -1,7 +1,7 @@
from django import forms
from general import form_helpers
-from minerva.models import UserProfile, Language
+from minerva.models import Profile, Language
class QuestionForm(forms.Form):
meta = forms.CharField(widget=forms.HiddenInput)
@@ -44,12 +44,12 @@ def _unpack_question_meta_data(self, packed_data):
data = [int(i) for i in packed_data.split("|")]
return data[0], data[1:]
-class UserProfileForm(forms.Form):
+class ProfileForm(forms.Form):
language = forms.ChoiceField(required=False)
def __init__(self, *args, **kwargs):
language = kwargs.pop("language", None)
- super(UserProfileForm, self).__init__(*args, **kwargs)
+ super(ProfileForm, self).__init__(*args, **kwargs)
self.fields["language"].choices = ([("", "<No preference>")] +
list(Language.objects.values_list("code", "descriptive_name")))
self.fields['language'].initial = language
View
8 minerva/management/commands/create_missing_profiles.py
@@ -1,5 +1,5 @@
"""
-Create initial UserProfile classes for any users in the system that don't
+Create initial Profile classes for any users in the system that don't
already have one.
"""
@@ -9,14 +9,14 @@
from minerva import models
class Command(base.BaseCommand):
- help = "Create UserProfiles for any Users that don't have one."
+ help = "Create Profiles for any Users that don't have one."
def handle(self, *args, **options):
if len(args):
raise base.CommandError("Usage is create_user_profiles.")
verbosity = int(options.get("verbosity", 0))
- for user in auth_models.User.objects.filter(userprofile=None):
+ for user in auth_models.User.objects.filter(profile=None):
if verbosity > 0:
print "Create profile for %s" % user
- models.UserProfile(student=user).save()
+ models.Profile(user=user).save()
View
107 minerva/migrations/0017_add_profile_model.py
@@ -0,0 +1,107 @@
+# 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 'Profile'
+ db.create_table('minerva_profile', (
+ ('user', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.User'], unique=True, primary_key=True)),
+ ('language', self.gf('django.db.models.fields.CharField')(max_length=3, null=True, blank=True)),
+ ))
+ db.send_create_signal('minerva', ['Profile'])
+
+
+ def backwards(self, orm):
+
+ # Deleting model 'Profile'
+ db.delete_table('minerva_profile')
+
+
+ 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'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': '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'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ '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'})
+ },
+ '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'})
+ },
+ 'minerva.language': {
+ 'Meta': {'object_name': 'Language'},
+ 'code': ('django.db.models.fields.CharField', [], {'max_length': '3'}),
+ 'descriptive_name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+ },
+ 'minerva.profile': {
+ 'Meta': {'object_name': 'Profile'},
+ 'language': ('django.db.models.fields.CharField', [], {'max_length': '3', 'null': 'True', 'blank': 'True'}),
+ 'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'})
+ },
+ 'minerva.progress': {
+ 'Meta': {'object_name': 'Progress'},
+ 'anon_student': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+ 'attempts': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'correct': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'student': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+ 'word': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['minerva.Word']"})
+ },
+ 'minerva.sessionprogress': {
+ 'Meta': {'object_name': 'SessionProgress'},
+ 'anon_student': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+ 'correct': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'student': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+ 'weight': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'word': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['minerva.Word']"})
+ },
+ 'minerva.userprofile': {
+ 'Meta': {'object_name': 'UserProfile'},
+ 'language': ('django.db.models.fields.CharField', [], {'max_length': '3', 'null': 'True', 'blank': 'True'}),
+ 'student': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'})
+ },
+ 'minerva.word': {
+ 'Meta': {'unique_together': "(('word', 'lang_code'),)", 'object_name': 'Word'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'lang_code': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['minerva.Language']"}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'meaning': ('django.db.models.fields.TextField', [], {}),
+ 'sub_level': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'word': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ }
+ }
+
+ complete_apps = ['minerva']
View
107 minerva/migrations/0018_copy_userprofile_data_to_profile.py
@@ -0,0 +1,107 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import DataMigration
+from django.db import models
+
+class Migration(DataMigration):
+
+ def forwards(self, orm):
+ """
+ Copy all UserProfile objects over to Profile objects.
+ """
+ for obj in orm.UserProfile.objects.all():
+ orm.Profile(user_id=obj.student_id, language=obj.language).save()
+
+ def backwards(self, orm):
+ """
+ Copy all Profile data to UserProfile objects.
+ """
+ for obj in orm.Profile.objects.all():
+ orm.UserProfile(student_id=obj.user_id,
+ language=obj.language).save()
+
+
+ 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'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': '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'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ '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'})
+ },
+ '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'})
+ },
+ 'minerva.language': {
+ 'Meta': {'object_name': 'Language'},
+ 'code': ('django.db.models.fields.CharField', [], {'max_length': '3'}),
+ 'descriptive_name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+ },
+ 'minerva.profile': {
+ 'Meta': {'object_name': 'Profile'},
+ 'language': ('django.db.models.fields.CharField', [], {'max_length': '3', 'null': 'True', 'blank': 'True'}),
+ 'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'})
+ },
+ 'minerva.progress': {
+ 'Meta': {'object_name': 'Progress'},
+ 'anon_student': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+ 'attempts': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'correct': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'student': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+ 'word': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['minerva.Word']"})
+ },
+ 'minerva.sessionprogress': {
+ 'Meta': {'object_name': 'SessionProgress'},
+ 'anon_student': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+ 'correct': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'student': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+ 'weight': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'word': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['minerva.Word']"})
+ },
+ 'minerva.userprofile': {
+ 'Meta': {'object_name': 'UserProfile'},
+ 'language': ('django.db.models.fields.CharField', [], {'max_length': '3', 'null': 'True', 'blank': 'True'}),
+ 'student': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'})
+ },
+ 'minerva.word': {
+ 'Meta': {'unique_together': "(('word', 'lang_code'),)", 'object_name': 'Word'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'lang_code': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['minerva.Language']"}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'meaning': ('django.db.models.fields.TextField', [], {}),
+ 'sub_level': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'word': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ }
+ }
+
+ complete_apps = ['minerva']
View
102 minerva/migrations/0019_remove_userprofile_model.py
@@ -0,0 +1,102 @@
+# 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):
+
+ # Deleting model 'UserProfile'
+ db.delete_table('minerva_userprofile')
+
+
+ def backwards(self, orm):
+
+ # Adding model 'UserProfile'
+ db.create_table('minerva_userprofile', (
+ ('student', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.User'], unique=True, primary_key=True)),
+ ('language', self.gf('django.db.models.fields.CharField')(max_length=3, null=True, blank=True)),
+ ))
+ db.send_create_signal('minerva', ['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'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': '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'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ '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'})
+ },
+ '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'})
+ },
+ 'minerva.language': {
+ 'Meta': {'object_name': 'Language'},
+ 'code': ('django.db.models.fields.CharField', [], {'max_length': '3'}),
+ 'descriptive_name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+ },
+ 'minerva.profile': {
+ 'Meta': {'object_name': 'Profile'},
+ 'language': ('django.db.models.fields.CharField', [], {'max_length': '3', 'null': 'True', 'blank': 'True'}),
+ 'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'})
+ },
+ 'minerva.progress': {
+ 'Meta': {'object_name': 'Progress'},
+ 'anon_student': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+ 'attempts': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'correct': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'student': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+ 'word': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['minerva.Word']"})
+ },
+ 'minerva.sessionprogress': {
+ 'Meta': {'object_name': 'SessionProgress'},
+ 'anon_student': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
+ 'correct': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'student': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+ 'weight': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'word': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['minerva.Word']"})
+ },
+ 'minerva.word': {
+ 'Meta': {'unique_together': "(('word', 'lang_code'),)", 'object_name': 'Word'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'lang_code': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['minerva.Language']"}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'meaning': ('django.db.models.fields.TextField', [], {}),
+ 'sub_level': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'word': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ }
+ }
+
+ complete_apps = ['minerva']
View
5 minerva/models.py
@@ -87,11 +87,11 @@ def student_string(self):
return unicode(self.student)
student_string.short_description = "student" # pylint: disable-msg=W0612
-class UserProfile(models.Model):
+class Profile(models.Model):
"""
Tracking user specific settings
"""
- student = models.OneToOneField(a_models.User, primary_key=True)
+ user = models.OneToOneField(a_models.User, primary_key=True)
language = models.CharField(max_length=3, null=True, blank=True)
def __unicode__(self):
@@ -99,3 +99,4 @@ def __unicode__(self):
models.signals.post_save.connect(signal_handlers.create_user_profile,
sender=a_models.User)
+
View
6 minerva/signal_handlers.py
@@ -2,15 +2,15 @@
def create_user_profile(sender, **kwargs):
"""
- Create an empty UserProfile whenever a new User is created.
+ Create an empty Profile whenever a new User is created.
"""
from minerva import models
try:
- ContentType.objects.get_by_natural_key("minerva", "userprofile")
+ ContentType.objects.get_by_natural_key("minerva", "profile")
except ContentType.DoesNotExist:
# Minerva app hasn't been installed yet.
return
if not kwargs["created"]:
return
- models.UserProfile(student=kwargs["instance"]).save()
+ models.Profile(user=kwargs["instance"]).save()
View
14 minerva/views.py
@@ -2,8 +2,8 @@
from django.template import RequestContext
from minerva.questions import create_question_complex, process_answer
-from minerva.models import Progress, Word, UserProfile, SessionProgress
-from minerva.forms import QuestionForm, UserProfileForm
+from minerva.models import Progress, Word, Profile, SessionProgress
+from minerva.forms import QuestionForm, ProfileForm
def validate_answer(request, query_base):
"""
@@ -43,7 +43,7 @@ def question(request):
query= {}
if request.user.is_authenticated():
query['student'] = request.user
- language = str(UserProfile.objects.get(student = request.user).language)
+ language = str(Profile.objects.get(user=request.user).language)
else:
query['anon_student'] = request.session.session_key
language = request.session.get('language', 'zho')
@@ -71,12 +71,12 @@ def status(request):
query['anon_student'] = request.session.session_key
if request.method == 'POST':
- user_profile_form = UserProfileForm(request.POST)
+ user_profile_form = ProfileForm(request.POST)
if user_profile_form.is_valid():
language = user_profile_form.cleaned_data['language']
changed = False
if request.user.is_authenticated():
- profile = UserProfile.objects.get(student=request.user)
+ profile = Profile.objects.get(user=request.user)
changed = profile.language != language
profile.language = language
profile.save()
@@ -89,11 +89,11 @@ def status(request):
else:
# FIXME - move the setting of the language to the cont
if request.user.is_authenticated():
- profile = UserProfile.objects.get(student=request.user)
+ profile = Profile.objects.get(user=request.user)
language = profile.language
else:
language = request.session.get('language', '')
- user_profile_form = UserProfileForm(language = language)
+ user_profile_form = ProfileForm(language = language)
context = {}
progress = Progress.objects.filter(**query).order_by('correct').reverse()
context['progress'] = progress
View
2  settings.py
@@ -92,7 +92,7 @@
)
LOGIN_REDIRECT_URL = "/"
-AUTH_PROFILE_MODULE = "minerva.UserProfile"
+AUTH_PROFILE_MODULE = "minerva.Profile"
DEBUG_TOOLBAR_CONFIG = {
"INTERCEPT_REDIRECTS": False,
View
10 user_management/views.py
@@ -3,23 +3,23 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
-from minerva.models import UserProfile
-from minerva.forms import UserProfileForm
+from minerva.models import Profile
+from minerva.forms import ProfileForm
def create_user(request):
if request.method == 'POST':
user_create_form = UserCreationForm(request.POST)
- user_profile_form = UserProfileForm(request.POST)
+ user_profile_form = ProfileForm(request.POST)
if user_create_form.is_valid():
user = user_create_form.save()
if user_profile_form.is_valid():
- profile = UserProfile.objects.get(student=user)
+ profile = Profile.objects.get(user=user)
profile.language = user_profile_form.cleaned_data['language']
profile.save()
return HttpResponseRedirect('/login/')
else:
user_create_form = UserCreationForm()
- user_profile_form = UserProfileForm()
+ user_profile_form = ProfileForm()
context = {
'user_create_form': user_create_form,
'user_profile_form': user_profile_form
Please sign in to comment.
Something went wrong with that request. Please try again.