]> git.openstreetmap.org Git - osqa.git/blobdiff - forum_modules/sximporter/importer.py
Sor order was not working.
[osqa.git] / forum_modules / sximporter / importer.py
index 1ab6abe9951fdec43458b2d8677e44e2a71ff22e..a16b29c741ada6038cb0ce9aec5ef405b2225594 100644 (file)
@@ -47,7 +47,7 @@ class UnknownUser(object):
 class IdMapper(dict):\r
     def __getitem__(self, key):\r
         key = int(key)\r
-        return super(IdMapper, self).get(key, key)\r
+        return super(IdMapper, self).get(key, 1)\r
 \r
     def __setitem__(self, key, value):\r
         super(IdMapper, self).__setitem__(int(key), int(value))\r
@@ -80,16 +80,16 @@ def userimport(dump, options):
             username = sxu.get('displayname', sxu.get('displaynamecleaned', sxu.get('realname', UnknownUser())))\r
 \r
             if not isinstance(username, UnknownUser) and username in user_by_name:\r
-                if options.get('mergesimilar', False) and sxu.get('email', 'INVALID') == user_by_name[username].email:\r
-                    osqau = user_by_name[username]\r
-                    create = False\r
-                    uidmapper[sxu.get('id')] = osqau.id\r
-                else:\r
-                    inc = 1\r
-                    while ("%s %d" % (username, inc)) in user_by_name:\r
-                        inc += 1\r
+                #if options.get('mergesimilar', False) and sxu.get('email', 'INVALID') == user_by_name[username].email:\r
+                #    osqau = user_by_name[username]\r
+                #    create = False\r
+                #    uidmapper[sxu.get('id')] = osqau.id\r
+                #else:\r
+                inc = 1\r
+                while ("%s %d" % (username, inc)) in user_by_name:\r
+                    inc += 1\r
 \r
-                    username = "%s %d" % (username, inc)\r
+                username = "%s %d" % (username, inc)\r
 \r
         sxbadges = sxu.get('badgesummary', None)\r
         badges = {'1':'0','2':'0','3':'0'}\r
@@ -120,10 +120,13 @@ def userimport(dump, options):
 \r
             osqau.save()\r
 \r
-            s = orm.SubscriptionSettings(user=osqau)\r
-            s.save()\r
+            try:\r
+                orm.SubscriptionSettings.objects.get(user=osqau)\r
+            except:\r
+                s = orm.SubscriptionSettings(user=osqau)\r
+                s.save()\r
 \r
-            user_by_name[osqau.username] = osqau\r
+            uidmapper[osqau.id] = osqau.id\r
         else:\r
             new_about = sxu.get('aboutme', None)\r
             if new_about and osqau.about != new_about:\r
@@ -142,6 +145,7 @@ def userimport(dump, options):
             merged_users.append(osqau.id)\r
             osqau.save()\r
 \r
+        user_by_name[osqau.username] = osqau\r
 \r
         openid = sxu.get('openid', None)\r
         if openid and openidre.match(openid):\r
@@ -173,6 +177,7 @@ def tagsimport(dump, uidmap):
 \r
 def postimport(dump, uidmap, tagmap):\r
     history = {}\r
+    accepted = {}\r
     all = {}\r
 \r
     for h in readTable(dump, "PostHistory"):\r
@@ -184,8 +189,6 @@ def postimport(dump, uidmap, tagmap):
     posts = readTable(dump, "Posts")\r
 \r
     for sxpost in posts:\r
-        accepted = {}\r
-\r
         postclass = sxpost.get('posttypeid') == '1' and orm.Question or orm.Answer\r
 \r
         post = postclass(\r
@@ -233,6 +236,7 @@ def postimport(dump, uidmap, tagmap):
                 post.closed_at = datetime.now()\r
 \r
             if sxpost.get('acceptedanswerid', None):\r
+                post.accepted_answer_id = int(sxpost.get('acceptedanswerid'))\r
                 accepted[int(sxpost.get('acceptedanswerid'))] = post\r
 \r
         else:\r
@@ -240,13 +244,9 @@ def postimport(dump, uidmap, tagmap):
             post.parent_id = sxpost['parentid']\r
 \r
             if int(post.id) in accepted:\r
-                question = accepted[int(post.id)]\r
-                question.accepted_answer_id = post\r
-                question.save()\r
-\r
                 post.accepted = True\r
                 post.accepted_at = datetime.now()\r
-                post.accepted_by_id = question.author_id\r
+                post.accepted_by_id = accepted[int(post.id)].author_id\r
 \r
         all[int(post.id)] = post\r
 \r
@@ -263,7 +263,7 @@ def comment_import(dump, uidmap, posts):
             id = currid,\r
             node_type = "comment",\r
             added_at = readTime(sxc['creationdate']),\r
-            author_id = uidmap[sxc['userid']],\r
+            author_id = uidmap[sxc.get('userid', 1)],\r
             body = sxc['text'],\r
             parent_id = sxc.get('postid'),\r
             vote_up_count = 0,\r
@@ -276,7 +276,7 @@ def comment_import(dump, uidmap, posts):
             oc.deleted_by_id = uidmap[sxc['deletionuserid']]\r
             oc.author_id = uidmap[sxc['deletionuserid']]\r
         else:\r
-            oc.author_id = uidmap[sxc['userid']]\r
+            oc.author_id = uidmap[sxc.get('userid', 1)]\r
 \r
 \r
         posts[oc.id] = oc\r
@@ -426,6 +426,7 @@ def sximport(dump, options):
     \r
     \r
 PG_SEQUENCE_RESETS = """\r
+SELECT setval('"auth_user_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user";\r
 SELECT setval('"auth_user_groups_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user_groups";\r
 SELECT setval('"auth_user_user_permissions_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user_user_permissions";\r
 SELECT setval('"activity_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "activity";\r