]> git.openstreetmap.org Git - osqa.git/commitdiff
A couple small fixes in the sximporter.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 16 Mar 2011 17:15:02 +0000 (17:15 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 16 Mar 2011 17:15:02 +0000 (17:15 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@856 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum_modules/sximporter/importer.py

index bece48e9362e155969f5fea2017ec2865e5346d7..58280905c2870b3fd01d155929839921bec4fbb6 100644 (file)
@@ -174,9 +174,13 @@ class UnknownYahooUser(UnknownUser):
 
 
 class IdMapper(dict):
+
+    def __init__(self):
+        self.default = 1
+
     def __getitem__(self, key):
         key = int(key)
-        return super(IdMapper, self).get(key, 1)
+        return super(IdMapper, self).get(key, self.default)
 
     def __setitem__(self, key, value):
         super(IdMapper, self).__setitem__(int(key), int(value))
@@ -200,15 +204,22 @@ def userimport(path, options):
     #check for empty values
     if not owneruid:
         owneruid = None
+    else:
+        owneruid = int(owneruid)
 
     def callback(sxu):
         create = True
+        set_mapper_defaults = False
 
         if sxu.get('id') == '-1':
             return
         #print "\n".join(["%s : %s" % i for i in sxu.items()])
 
-        if int(sxu.get('id')) == int(owneruid):
+        if (owneruid and (int(sxu.get('id')) == owneruid)) or (
+            (not owneruid) and len(uidmapper)):
+
+            set_mapper_defaults = True
+
             if authenticated_user:
                 osqau = orm.User.objects.get(id=authenticated_user.id)
 
@@ -216,12 +227,7 @@ def userimport(path, options):
                     openids.add(assoc.key)
 
                 uidmapper[owneruid] = osqau.id
-                uidmapper[-1] = osqau.id
                 create = False
-            else:
-                uidmapper[owneruid] = int(owneruid)
-                uidmapper[-1] = int(owneruid)
-
 
         sxbadges = sxu.get('badgesummary', None)
         badges = {'1':'0', '2':'0', '3':'0'}
@@ -320,6 +326,10 @@ def userimport(path, options):
             #merged_users.append(osqau.id)
             osqau.save()
 
+        if set_mapper_defaults:
+            uidmapper[-1] = osqau.id
+            uidmapper.default = osqau.id
+
         usernames.append(osqau.username)
 
         openid = sxu.get('openid', None)
@@ -336,8 +346,8 @@ def userimport(path, options):
 
     readTable(path, "Users", callback)
 
-    if uidmapper[-1] == -1:
-        uidmapper[-1] = 1
+    #if uidmapper[-1] == -1:
+    #    uidmapper[-1] = 1
 
     return uidmapper