Source code for ferrosoft.apps.dataimport.management.commands.dataimport_json

import sys

from django.core.management import BaseCommand

from ferrosoft.apps.dataimport.services.database import (
    import_json,
    DATAIMPORT_CONVERTERS,
)
from ferrosoft.apps.dataimport.services.fixtures import (
    CatalogValidationError,
)
from ferrosoft.apps.ferrobase.management.tenantcommand import TenantAwareCommand


[docs] class Command(TenantAwareCommand, BaseCommand):
[docs] def add_arguments(self, parser): super().add_arguments(parser) parser.add_argument( "-s", "--schema", type=str, help="JSON schema file name", ) parser.add_argument( "-c", "--converters", type=str, default=DATAIMPORT_CONVERTERS, ) parser.add_argument( "catalog", nargs="+", type=str, help="Catalog file name", )
[docs] def handle_tenant(self, *args, **options): try: fixtures = import_json( options["converters"], options["catalog"], options["schema"], ) self.stderr.write( self.style.SUCCESS("Imported %d fixtures" % len(fixtures)) ) except CatalogValidationError as e: self.stderr.write(str(e)) sys.exit(1)