From 7ce36668ea3fe664f7e0b7d6731ca584ebeefd8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Poulain?= Date: Sat, 8 Aug 2020 17:21:36 +0200 Subject: [PATCH] feat(import): ajoute l option --user --- drupal2spip_lal/base/convert.py | 5 +++++ .../base/management/commands/import.py | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drupal2spip_lal/base/convert.py b/drupal2spip_lal/base/convert.py index 5cf4155..b53c046 100644 --- a/drupal2spip_lal/base/convert.py +++ b/drupal2spip_lal/base/convert.py @@ -209,6 +209,11 @@ def convert_node(node, options): 'Article {} updated from node {}.'.format(article.pk, node.pk) ) + else: + logger.info( + 'Skipped node {}. Try --update to update it.'.format(node.pk) + ) + if article: user_attributes = { 'nom': node.user.name, diff --git a/drupal2spip_lal/base/management/commands/import.py b/drupal2spip_lal/base/management/commands/import.py index 5136b91..b988fb8 100644 --- a/drupal2spip_lal/base/management/commands/import.py +++ b/drupal2spip_lal/base/management/commands/import.py @@ -12,11 +12,17 @@ class Command(BaseCommand): help = "Import Drupal nodes to SPIP articles." def add_arguments(self, parser): + parser.add_argument( + '--user', + nargs='*', + type=str, + help='Selects users nodes to be imported. Default is nobody.', + ) parser.add_argument( '--node', nargs='*', type=int, - help='Selects what nodes should be imported. Default is none.', + help='Selects what nodes to be imported. Default is none.', ) parser.add_argument( '--update', @@ -30,7 +36,13 @@ class Command(BaseCommand): ) def handle(self, **options): - for n in Node.objects.filter(pk__in=options.get('node', [])): + qs = Node.objects.none() + if options['node']: + qs |= Node.objects.filter(pk__in=options['node']) + if options['user']: + qs |= Node.objects.filter(user__name__in=options['user']) + + for n in qs: try: convert_node(n, options) except Exception as e: