X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/cbd765eb6c18772c561357a870c261dd088b0c8b..3a1befca62834cd3c0b3aa3f6af974179ddfbea4:/forum_modules/sximporter/importer.py diff --git a/forum_modules/sximporter/importer.py b/forum_modules/sximporter/importer.py index bece48e..6669b8c 100644 --- a/forum_modules/sximporter/importer.py +++ b/forum_modules/sximporter/importer.py @@ -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 @@ -383,7 +393,7 @@ def remove_post_state(name, post): post.state_string = "".join("(%s)" % s for s in re.findall('\w+', post.state_string) if s != name) def postimport(dump, uidmap, tagmap): - all = [] + all = {} def callback(sxpost): nodetype = (sxpost.get('posttypeid') == '1') and "nodetype" or "answer" @@ -444,13 +454,15 @@ def postimport(dump, uidmap, tagmap): post.extra_count = sxpost.get('viewcount', 0) add_tags_to_post(post, tagmap) + all[int(post.id)] = int(post.id) else: post.parent_id = sxpost['parentid'] + post.abs_parent_id = sxpost['parentid'] + all[int(post.id)] = int(sxpost['parentid']) post.save() - all.append(int(post.id)) create_and_activate_revision(post) del post @@ -459,7 +471,9 @@ def postimport(dump, uidmap, tagmap): return all -def comment_import(dump, uidmap, posts): +def comment_import(dump, uidmap, absparent_map): + posts = absparent_map.keys() + currid = IdIncrementer(max(posts)) mapping = {} @@ -472,6 +486,7 @@ def comment_import(dump, uidmap, posts): author_id = uidmap[sxc.get('userid', 1)], body = sxc['text'], parent_id = sxc.get('postid'), + abs_parent_id = absparent_map.get(int(sxc.get('postid')), sxc.get('postid')) ) if sxc.get('deletiondate', None): @@ -758,6 +773,7 @@ def badges_import(dump, uidmap, post_list): osqaa.save() badge.awarded_count += 1 + user_badge_count[user_id] += 1 readTable(dump, "Users2Badges", callback) @@ -775,7 +791,7 @@ def save_setting(k, v): kv.save() -def pages_import(dump, currid): +def pages_import(dump, currid, owner): currid = IdIncrementer(currid) registry = {} @@ -796,7 +812,7 @@ def pages_import(dump, currid): 'sidebar_render': "html", 'comments': False }), - author_id = 1 + author_id = owner ) create_and_activate_revision(page) @@ -921,7 +937,7 @@ def sximport(dump, options): badges_import(dump, uidmap, posts) - pages_import(dump, max(posts)) + pages_import(dump, max(posts), uidmap.default) static_import(dump) gc.collect()