diff --git a/common/djangoapps/student/management/commands/pearson_make_tc_user.py b/common/djangoapps/student/management/commands/pearson_make_tc_user.py new file mode 100644 index 0000000000..d974c25b6b --- /dev/null +++ b/common/djangoapps/student/management/commands/pearson_make_tc_user.py @@ -0,0 +1,85 @@ +import uuid +from datetime import datetime +from optparse import make_option + +from django.contrib.auth.models import User +from django.core.management.base import BaseCommand, CommandError + +from student.models import TestCenterUser + +class Command(BaseCommand): + option_list = BaseCommand.option_list + ( + make_option( + '--client_candidate_id', + action='store', + dest='client_candidate_id', + help='ID we assign a user to identify them to Pearson' + ), + make_option( + '--first_name', + action='store', + dest='first_name', + ), + make_option( + '--last_name', + action='store', + dest='last_name', + ), + make_option( + '--address_1', + action='store', + dest='address_1', + ), + make_option( + '--city', + action='store', + dest='city', + ), + make_option( + '--state', + action='store', + dest='state', + help='Two letter code (e.g. MA)' + ), + make_option( + '--postal_code', + action='store', + dest='postal_code', + ), + make_option( + '--country', + action='store', + dest='country', + help='Three letter country code (ISO 3166-1 alpha-3), like USA' + ), + make_option( + '--phone', + action='store', + dest='phone', + help='Pretty free-form (parens, spaces, dashes), but no country code' + ), + make_option( + '--phone_country_code', + action='store', + dest='phone_country_code', + help='Phone country code, just "1" for the USA' + ), + ) + args = "" + help = "Create a TestCenterUser entry for a given Student" + + @staticmethod + def is_valid_option(option_name): + base_options = set(option.dest for option in BaseCommand.option_list) + return option_name not in base_options + + + def handle(self, *args, **options): + username = args[0] + print username + + our_options = dict((k, v) for k, v in options.items() + if Command.is_valid_option(k)) + student = User.objects.get(username=username) + student.test_center_user = TestCenterUser(**our_options) + student.test_center_user.save() diff --git a/common/djangoapps/student/migrations/0020_add_test_center_user.py b/common/djangoapps/student/migrations/0020_add_test_center_user.py index f3b729afdc..e308e2d7e0 100644 --- a/common/djangoapps/student/migrations/0020_add_test_center_user.py +++ b/common/djangoapps/student/migrations/0020_add_test_center_user.py @@ -11,6 +11,7 @@ class Migration(SchemaMigration): # Adding model 'TestCenterUser' db.create_table('student_testcenteruser', ( ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('user', self.gf('django.db.models.fields.related.ForeignKey')(default=None, to=orm['auth.User'], unique=True)), ('created_at', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, db_index=True, blank=True)), ('updated_at', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, db_index=True, blank=True)), ('user_updated_at', self.gf('django.db.models.fields.DateTimeField')(db_index=True)), @@ -157,6 +158,7 @@ class Migration(SchemaMigration): 'state': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '20', 'blank': 'True'}), 'suffix': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), 'updated_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['auth.User']", 'unique': 'True'}), 'user_updated_at': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True'}) }, 'student.userprofile': { diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index d379689639..61c2537399 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -8,7 +8,7 @@ Portal servers that hold the canoncial user information and that user information is replicated to slave Course server pools. Each Course has a set of servers that serves only its content and has users that are relevant only to it. -We replicate the following tables into the Course DBs where the user is +We replicate the following tables into the Course DBs where the user is enrolled. Only the Portal servers should ever write to these models. * UserProfile * CourseEnrollment @@ -41,33 +41,22 @@ import uuid from django.conf import settings from django.contrib.auth.models import User from django.db import models -from django.db.models.signals import post_delete, post_save -from django.dispatch import receiver -from django_countries import CountryField - from django.db.models.signals import post_save from django.dispatch import receiver -from functools import partial - import comment_client as cc -from django_comment_client.models import Role, Permission +from django_comment_client.models import Role -import logging - -from xmodule.modulestore.django import modulestore - -#from cache_toolbox import cache_model, cache_relation log = logging.getLogger(__name__) class UserProfile(models.Model): - """This is where we store all the user demographic fields. We have a + """This is where we store all the user demographic fields. We have a separate table for this rather than extending the built-in Django auth_user. Notes: - * Some fields are legacy ones from the first run of 6.002, from which + * Some fields are legacy ones from the first run of 6.002, from which we imported many users. * Fields like name and address are intentionally open ended, to account for international variations. An unfortunate side-effect is that we @@ -150,7 +139,7 @@ class TestCenterUser(models.Model): a limit of 255 while last_name only gets 50. """ # Our own record keeping... - # user = models.ForeignKey(User, unique=True) + user = models.ForeignKey(User, unique=True, default=None) created_at = models.DateTimeField(auto_now_add=True, db_index=True) updated_at = models.DateTimeField(auto_now=True, db_index=True) # user_updated_at happens only when the user makes a change to their data, @@ -198,7 +187,7 @@ class TestCenterUser(models.Model): @property def email(self): - return "" # should return user.email, but stub for now + return self.user.email ## TODO: Should be renamed to generic UserGroup, and possibly # Given an optional field for type of group