2020-08-08 11:32:28 +02:00
|
|
|
import logging
|
|
|
|
|
2020-08-03 16:59:21 +02:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
|
|
|
from drupal2spip_lal.base.convert import convert_node
|
|
|
|
from drupal2spip_lal.drupal.models import Node
|
|
|
|
|
|
|
|
|
2020-08-08 11:32:28 +02:00
|
|
|
logger = logging.getLogger('drupal2spip_lal')
|
|
|
|
|
|
|
|
|
2020-08-03 16:59:21 +02:00
|
|
|
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.',
|
|
|
|
)
|
2020-08-04 10:53:21 +02:00
|
|
|
parser.add_argument(
|
|
|
|
'--force-download',
|
|
|
|
action='store_true',
|
|
|
|
help='Force existing ressources to be downloaded. Default is skip.',
|
|
|
|
)
|
2020-08-03 16:59:21 +02:00
|
|
|
|
|
|
|
def handle(self, **options):
|
2020-08-08 11:32:28 +02:00
|
|
|
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)
|
|
|
|
)
|