def migrate_author(self, author_name):
action_text = "<STR_LIT>""<STR_LIT>""<STR_LIT>""<STR_LIT>" % self.style.ITEM(author_name)<EOL>while <NUM_LIT>:<EOL><INDENT>selection = eval(input(smart_str(action_text)))<EOL>if selection and selection in '<STR_LIT>':<EOL><INDENT>break<EOL><DEDENT><DEDENT>if selection == '<STR_LIT:1>':<EOL><INDENT>users = Author.objects.all()<EOL>if users.count() == <NUM_LIT:1>:<EOL><INDENT>username = users[<NUM_LIT:0>].get_username()<EOL>preselected_user = username<EOL>usernames = [username]<EOL>usernames_display = ['<STR_LIT>' % username]<EOL><DEDENT>else:<EOL><INDENT>usernames = []<EOL>usernames_display = []<EOL>preselected_user = None<EOL>for user in users:<EOL><INDENT>username = user.get_username()<EOL>if username == author_name:<EOL><INDENT>usernames_display.append('<STR_LIT>' % username)<EOL>preselected_user = username<EOL><DEDENT>else:<EOL><INDENT>usernames_display.append(username)<EOL><DEDENT>usernames.append(username)<EOL><DEDENT><DEDENT>while <NUM_LIT>:<EOL><INDENT>user_text = "<STR_LIT>""<STR_LIT>""<STR_LIT>""<STR_LIT>" %'<STR_LIT:U+002CU+0020>'.join(usernames_display)<EOL>user_selected = eval(input(user_text))<EOL>if user_selected in usernames:<EOL><INDENT>break<EOL><DEDENT>if user_selected == '<STR_LIT>' and preselected_user:<EOL><INDENT>user_selected = preselected_user<EOL>break<EOL><DEDENT>if user_selected.strip() == '<STR_LIT>':<EOL><INDENT>return self.migrate_author(author_name)<EOL><DEDENT><DEDENT>return users.get(**{users[<NUM_LIT:0>].USERNAME_FIELD: user_selected})<EOL><DEDENT>else:<EOL><INDENT>create_text = "<STR_LIT>""<STR_LIT>" % author_name<EOL>author_mail = eval(input(create_text))<EOL>if author_mail.strip() == '<STR_LIT>':<EOL><INDENT>return self.migrate_author(author_name)<EOL><DEDENT>try:<EOL><INDENT>return Author.objects.create_user(author_name, author_mail)<EOL><DEDENT>except IntegrityError:<EOL><INDENT>return Author.objects.get(<EOL>**{Author.USERNAME_FIELD: author_name})<EOL><DEDENT><DEDENT>
Handle actions for migrating the authors.