diff options
Diffstat (limited to 'migrate_spoken/views.py')
-rw-r--r-- | migrate_spoken/views.py | 44 |
1 files changed, 44 insertions, 0 deletions
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!") |