diff options
author | Sanmugasundaram K | 2015-01-07 19:18:22 +0530 |
---|---|---|
committer | Sanmugasundaram K | 2015-01-07 19:24:11 +0530 |
commit | 2ae49074f030b61088317526b023b9e21124dbfc (patch) | |
tree | 957f0138c0f2a96fd2c818a7035d2bbd48d3400c /migrate_spoken | |
parent | 9a5a239295e7aae2d211c07c9fdb117cf8252e99 (diff) | |
download | FOSSEE-Forum-2ae49074f030b61088317526b023b9e21124dbfc.tar.gz FOSSEE-Forum-2ae49074f030b61088317526b023b9e21124dbfc.tar.bz2 FOSSEE-Forum-2ae49074f030b61088317526b023b9e21124dbfc.zip |
drupal auth user id change to spoken auth user id in all old records
Diffstat (limited to 'migrate_spoken')
-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 |
5 files changed, 76 insertions, 0 deletions
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!") |