Commits

Nicola Ferruzzi committed 96f1bba

Import User date_registered and last_login

Comments (0)

Files changed (1)

djangobb/djangobb_forum/management/commands/djangobb_importsmf.py

 from django.core.management.base import BaseCommand, CommandError
 from djangobb_forum.models import Category, Forum, Profile, Post, Topic
 from django.contrib.auth.models import User, Group
+from django.db import transaction
 
 import re, htmlentitydefs
 
              'email': user.emailAddress,
              'password':None,
              'signature': user.signature,
-             
+
              'isAdmin': user.ID_GROUP == 1,
              'isActive': user.is_activated == True,
              
              'avatar_url': user.avatar,
+             
+             'date_joined': user.dateRegistered,
+             'last_login': user.lastLogin,
+             
+             'reputation_good': user.karmaGood,
+             'reputation_bad': user.karmaBad,
+             
+             'gender': user.gender,
+             'location': user.location,
+             'birth_date': user.birthdate,
+             'site': user.websiteUrl,
              }
         return d
         
         for u in self.source.users():
             l = User.objects.filter(username=u['username'])
             if bool(l) == False:
-                us = User(username=u['username'],
-                          email=u['email'],
-                          first_name=u['first name'],
-                          last_name=u['last name'],
-                          is_active=u['isActive'],
-                          )
-                pf = Profile(user=us, signature=u['signature'])
+                rp = User.objects.make_random_password()
+                us = User.objects.create_user(u['username'], u['email'], rp)
+                us.first_name = u['first name']
+                us.last_name = u['last name']
+                us.is_active = u['isActive']
+                us.date_joined = datetime.fromtimestamp(u['date_joined'])
+                us.last_login = datetime.fromtimestamp(u['last_login'])
+                us.save()
+                pf = Profile(user=us,
+                             signature=u['signature'],
+                             site=u['site'],
+                             location=u['location'],
+                             )
                 print 'Importing user:', us
                 pf.save()
-                us.save()
                 self.users[u['ID']] = us
             else:
                 self.users[u['ID']] = l[0]
-    
+
     def importPostsAndTopics(self):
         for t in self.source.topics():
             print t['subject'], len(t['posts'])
                             po.save()
                 to.last_post = po
                 to.save()
-
             
     
 class Command(BaseCommand):