- user = orm.User(
- id = row.getc('id'),
- username = row.getc('username'),
- password = row.getc('password'),
- email = row.getc('email'),
- email_isvalid= valid_email,
- is_superuser = 'superuser' in roles,
- is_staff = 'moderator' in roles,
- is_active = True,
- date_joined = row.get('joindate').as_datetime(),
- about = row.getc('bio'),
- date_of_birth = row.get('birthdate').as_date(None),
- website = row.getc('website'),
- reputation = row.get('reputation').as_int(),
- gold = badges.get_attr('gold').as_int(),
- silver = badges.get_attr('silver').as_int(),
- bronze = badges.get_attr('bronze').as_int(),
- real_name = row.getc('realname'),
- location = row.getc('location'),
- )
+ if existent:
+ user = existent
+
+ user.reputation += row.get('reputation').as_int()
+ user.gold += badges.get_attr('gold').as_int()
+ user.silver += badges.get_attr('gold').as_int()
+ user.bronze += badges.get_attr('gold').as_int()
+
+ else:
+ username = row.getc('username')
+
+ if is_merge:
+ username_count = 0
+
+ while orm.User.objects.filter(username=username).count():
+ username_count += 1
+ username = "%s %s" % (row.getc('username'), username_count)
+
+ user = orm.User(
+ id = (not is_merge) and row.getc('id') or None,
+ username = username,
+ password = row.getc('password'),
+ email = row.getc('email'),
+ email_isvalid= valid_email,
+ is_superuser = (not is_merge) and 'superuser' in roles,
+ is_staff = ('moderator' in roles) or (is_merge and 'superuser' in roles),
+ is_active = row.get('active').as_bool(),
+ date_joined = row.get('joindate').as_datetime(),
+ about = row.getc('bio'),
+ date_of_birth = row.get('birthdate').as_date(None),
+ website = row.getc('website'),
+ reputation = row.get('reputation').as_int(),
+ gold = badges.get_attr('gold').as_int(),
+ silver = badges.get_attr('silver').as_int(),
+ bronze = badges.get_attr('bronze').as_int(),
+ real_name = row.getc('realname'),
+ location = row.getc('location'),
+ )