diff options
-rw-r--r-- | forums/settings.py | 10 | ||||
-rw-r--r-- | forums/urls.py | 1 | ||||
-rw-r--r-- | migrate_spoken/__init__.py | 0 | ||||
-rw-r--r-- | migrate_spoken/admin.py | 3 | ||||
-rw-r--r-- | migrate_spoken/models.py | 26 | ||||
-rw-r--r-- | migrate_spoken/tests.py | 3 | ||||
-rw-r--r-- | migrate_spoken/views.py | 44 | ||||
-rw-r--r-- | spoken_auth/models.py | 1 | ||||
-rw-r--r-- | spoken_auth/routers.py | 4 |
9 files changed, 92 insertions, 0 deletions
diff --git a/forums/settings.py b/forums/settings.py index d793004..7b758e0 100644 --- a/forums/settings.py +++ b/forums/settings.py @@ -35,6 +35,15 @@ DATABASES = { 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. 'PORT': '', # Set to empty string for default. }, + 'cdeep': { + 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. + 'NAME': 'CDEEP', # Or path to database file if using sqlite3. + # The following settings are not used with sqlite3: + 'USER': db_user, + 'PASSWORD': db_pass, + 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. + 'PORT': '', # Set to empty string for default. + }, } # Hosts/domain names that are valid for this site; required if DEBUG is False @@ -150,6 +159,7 @@ INSTALLED_APPS = ( 'spoken_auth', 'compressor', 'debug_toolbar', + 'migrate_spoken', ) # A sample logging configuration. The only tangible logging diff --git a/forums/urls.py b/forums/urls.py index 9a0ec63..cb8b54e 100644 --- a/forums/urls.py +++ b/forums/urls.py @@ -19,4 +19,5 @@ urlpatterns = patterns('', # User account urls url(r'^accounts/login/', 'forums.views.user_login', name='user_login'), url(r'^accounts/logout/', 'forums.views.user_logout', name='user_logout'), + url(r'^migrate', 'migrate_spoken.views.chenage_drupal_userid_spoken', name='chenage_drupal_userid_spoken'), ) diff --git a/migrate_spoken/__init__.py b/migrate_spoken/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/migrate_spoken/__init__.py diff --git a/migrate_spoken/admin.py b/migrate_spoken/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/migrate_spoken/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/migrate_spoken/models.py b/migrate_spoken/models.py new file mode 100644 index 0000000..c5d7343 --- /dev/null +++ b/migrate_spoken/models.py @@ -0,0 +1,26 @@ +from django.db import models + +class OldUsers(models.Model): + uid = models.IntegerField(primary_key=True) + name = models.CharField(unique=True, max_length=60) + pass_field = models.CharField(db_column='pass', max_length=32) # Field renamed because it was a Python reserved word. + mail = models.CharField(max_length=64, blank=True) + mode = models.IntegerField() + sort = models.IntegerField(blank=True, null=True) + threshold = models.IntegerField(blank=True, null=True) + theme = models.CharField(max_length=255) + signature = models.CharField(max_length=255) + signature_format = models.IntegerField() + created = models.IntegerField() + access = models.IntegerField() + login = models.IntegerField() + status = models.IntegerField() + timezone = models.CharField(max_length=8, blank=True) + language = models.CharField(max_length=12) + picture = models.CharField(max_length=255) + init = models.CharField(max_length=64, blank=True) + data = models.TextField(blank=True) + last_login = models.DateTimeField(blank=True, null=True) + class Meta: + db_table = 'users' + diff --git a/migrate_spoken/tests.py b/migrate_spoken/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/migrate_spoken/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/migrate_spoken/views.py b/migrate_spoken/views.py new file mode 100644 index 0000000..fc56c25 --- /dev/null +++ b/migrate_spoken/views.py @@ -0,0 +1,44 @@ +from django.shortcuts import render +from django.http import HttpResponse, HttpResponseRedirect +from website.models import Question, Answer, AnswerComment, Notification +from migrate_spoken.models import OldUsers +from spoken_auth.models import Users +# Create your views here. + +def get_old_user(uid): + try: + return OldUsers.objects.get(pk = uid) + except Exception, e: + return None + +def get_current_user_from_old_email(mail): + try: + return Users.objects.get(email = mail) + except Exception, e: + print e + return None + +def get_current_user_id_from_old_uerid(uid): + old_user = get_old_user(uid) + if old_user: + #print old_user.uid, " => ", old_user.mail + current_user = get_current_user_from_old_email(old_user.mail) + if current_user: + #print current_user.id, " => ", current_user.email + return current_user + return None + +def chenage_drupal_userid_spoken(request): + models = ['Question', 'Answer', 'AnswerComment', 'Notification'] + for model in models: + model = eval(model) + collection = model.objects.all() + for c in collection: + uid = get_current_user_id_from_old_uerid(c.uid) + if uid: + c.uid = uid + c.save() + else: + print c.uid + print model, " Done!!" + return HttpResponse("Migration Done!") diff --git a/spoken_auth/models.py b/spoken_auth/models.py index 1992ed8..b315b2d 100644 --- a/spoken_auth/models.py +++ b/spoken_auth/models.py @@ -8,6 +8,7 @@ from django.contrib.auth.models import ( class Users(AbstractBaseUser): id = models.IntegerField(primary_key=True) username = models.CharField(max_length=100L, unique=True) + email = models.CharField(max_length=100L, unique=True) USERNAME_FIELD = 'username' class Meta: db_table = 'auth_user' diff --git a/spoken_auth/routers.py b/spoken_auth/routers.py index f2d759b..6b6174c 100644 --- a/spoken_auth/routers.py +++ b/spoken_auth/routers.py @@ -2,11 +2,15 @@ class DrupalAuthRouter(object): def db_for_read(self, model, **hints): if model._meta.app_label == 'spoken_auth': return 'spoken' + if model._meta.app_label == 'migrate_spoken': + return 'cdeep' return 'default' def db_for_write(self, model, **hints): if model._meta.app_label == 'spoken_auth': return 'spoken' + if model._meta.app_label == 'migrate_spoken': + return 'cdeep' return 'default' def allow_relation(self, obj1, obj2, **hints): |