def import_users(self):
self.message('<STR_LIT>')<EOL>saved_users = self.saved_admins<EOL>for email in self.email_set:<EOL><INDENT>owner = self.users_dict[email].get('<STR_LIT>')<EOL>if owner.strip() == '<STR_LIT>':<EOL><INDENT>owner, domain = email.split('<STR_LIT:@>')<EOL>owner = owner.replace('<STR_LIT:.>', '<STR_LIT:U+0020>')<EOL><DEDENT>if '<STR_LIT:U+0020>' in owner:<EOL><INDENT>owner_parts = owner.split('<STR_LIT:U+0020>')<EOL>first_name = owner_parts[<NUM_LIT:0>]<EOL>last_name = owner_parts[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>first_name = owner<EOL>last_name = '<STR_LIT>'<EOL><DEDENT>username = slugify(owner)<EOL>try:<EOL><INDENT>user = User.objects.get(email=email)<EOL><DEDENT>except User.DoesNotExist:<EOL><INDENT>user = User()<EOL>user.username = username<EOL>user.password = self.generate_random_password()<EOL>user.is_active = True<EOL><DEDENT>user.first_name = first_name.capitalize()<EOL>user.last_name = last_name.capitalize()<EOL>user.email = email<EOL>oldest_node = OldNode.objects.filter(email=email).order_by('<STR_LIT>')[<NUM_LIT:0>]<EOL>user.date_joined = oldest_node.added<EOL>counter = <NUM_LIT:1><EOL>original_username = username<EOL>while True:<EOL><INDENT>if not user.pk and User.objects.filter(username=user.username).count() > <NUM_LIT:0>:<EOL><INDENT>counter += <NUM_LIT:1><EOL>user.username = '<STR_LIT>' % (original_username, counter)<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>try:<EOL><INDENT>user.full_clean()<EOL>user.save(sync_emailaddress=False)<EOL><DEDENT>except Exception:<EOL><INDENT>if(User.objects.filter(email=email).count() == <NUM_LIT:1>):<EOL><INDENT>user = User.objects.get(email=email)<EOL><DEDENT>else:<EOL><INDENT>tb = traceback.format_exc()<EOL>self.message('<STR_LIT>' % (user.username, tb))<EOL>continue<EOL><DEDENT><DEDENT>if user:<EOL><INDENT>self.users_dict[email]['<STR_LIT:id>'] = user.id<EOL>saved_users.append(user)<EOL>self.verbose('<STR_LIT>' % (user.username, user.get_full_name(), user.email))<EOL><DEDENT>if EMAIL_CONFIRMATION and EmailAddress.objects.filter(email=user.email).count() is <NUM_LIT:0>:<EOL><INDENT>try:<EOL><INDENT>email_address = EmailAddress(user=user, email=user.email, verified=True, primary=True)<EOL>email_address.full_clean()<EOL>email_address.save()<EOL><DEDENT>except Exception:<EOL><INDENT>tb = traceback.format_exc()<EOL>self.message('<STR_LIT>' % (user.username, tb))<EOL><DEDENT><DEDENT><DEDENT>self.message('<STR_LIT>' % len(saved_users))<EOL>self.saved_users = saved_users<EOL>
save users to local DB