drupal2spip_lal/drupal2spip_lal/base/management/commands/import.py

40 lines
1.2 KiB
Python

import logging
from django.core.management.base import BaseCommand
from drupal2spip_lal.base.convert import convert_node
from drupal2spip_lal.drupal.models import Node
logger = logging.getLogger('drupal2spip_lal')
class Command(BaseCommand):
help = "Import Drupal nodes to SPIP articles."
def add_arguments(self, parser):
parser.add_argument(
'--node',
nargs='*',
type=int,
help='Selects what nodes should be imported. Default is none.',
)
parser.add_argument(
'--update',
action='store_true',
help='Force existing articles to be updated. Default is skip.',
)
parser.add_argument(
'--force-download',
action='store_true',
help='Force existing ressources to be downloaded. Default is skip.',
)
def handle(self, **options):
for n in Node.objects.filter(pk__in=options.get('node', [])):
try:
convert_node(n, options)
except Exception as e:
logger.critical(
"L'import du node {} a échoué : {}".format(n.pk, e)
)