From ef638946d6574241fb096b0037d99f3f182072c6 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Mon, 18 Nov 2024 14:32:42 +1100 Subject: [PATCH] rewrite the Pivotal '--ask-for-users' option to '--map-users' and optimistically try to map to existing users, no prompting --- .../commands/import_from_pivotal.py | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/taiga/importers/management/commands/import_from_pivotal.py b/taiga/importers/management/commands/import_from_pivotal.py index 11be32e9..2393052e 100644 --- a/taiga/importers/management/commands/import_from_pivotal.py +++ b/taiga/importers/management/commands/import_from_pivotal.py @@ -20,9 +20,9 @@ def add_arguments(self, parser): help='Project ID or full name (ex: taigaio/taiga-back)') parser.add_argument('--template', dest='template', default="scrum", help='template to use: scrum or kanban (default scrum)') - parser.add_argument('--ask-for-users', dest='ask_for_users', const=True, + parser.add_argument('--map-users', dest='map_users', const=True, action="store_const", default=False, - help='Import closed data') + help='Map usernames from Pivotal to Taiga. You can create users in Taiga in advance via /admin/users/user') parser.add_argument('--closed-data', dest='closed_data', const=True, action="store_const", default=False, help='Import closed data') @@ -50,25 +50,13 @@ def handle(self, *args, **options): project_id = input("Project id: ") users_bindings = {} - if options.get('ask_for_users', None): - print("Add the username or email for next pivotal users:") + if options.get('map_users', None): for user in importer.list_users(project_id): try: - users_bindings[user['id']] = User.objects.get(Q(email=user['person'].get('email', "not-valid"))) - break + users_bindings[user['person']['id']] = User.objects.get(Q(email=user['person'].get('email', "not-valid"))) except User.DoesNotExist: pass - while True: - username_or_email = input("{}: ".format(user['person']['name'])) - if username_or_email == "": - break - try: - users_bindings[user['id']] = User.objects.get(Q(username=username_or_email) | Q(email=username_or_email)) - break - except User.DoesNotExist: - print("ERROR: Invalid username or email") - options = { "template": options.get('template'), "import_closed_data": options.get("closed_data", False),