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