def handle(self, *args, **options): importers = get_importers() imp_list = ', '.join(sorted(importers.keys())) if len(args) != 1: raise CommandError("Enter the name of the event importer module. Valid importers: %s" % imp_list) if not args[0] in importers: raise CommandError("Importer %s not found. Valid importers: %s" % (args[0], imp_list)) imp_class = importers[args[0]] if hasattr(settings, 'PROJECT_ROOT'): root_dir = settings.PROJECT_ROOT else: root_dir = settings.BASE_DIR importer = imp_class({'data_path': os.path.join(root_dir, 'data'), 'verbosity': int(options['verbosity']), 'cached': options['cached'], 'single': options['single']}) # Activate the default language for the duration of the import # to make sure translated fields are populated correctly. old_lang = get_language() activate(settings.LANGUAGES[0][0]) for imp_type in self.importer_types: name = "import_%s" % imp_type method = getattr(importer, name, None) if options[imp_type]: if not method: raise CommandError("Importer %s does not support importing %s" % (name, imp_type)) else: if not options['all']: continue if method: method() activate(old_lang)
def handle(self, *args, **options): importers = get_importers() imp_list = ', '.join(sorted(importers.keys())) if len(args) != 1: raise CommandError("Enter the name of the event importer module. Valid importers: %s" % imp_list) if not args[0] in importers: raise CommandError("Importer %s not found. Valid importers: %s" % (args[0], imp_list)) imp_class = importers[args[0]] if hasattr(settings, 'PROJECT_ROOT'): root_dir = settings.PROJECT_ROOT else: root_dir = settings.BASE_DIR importer = imp_class({'data_path': os.path.join(root_dir, 'data'), 'verbosity': int(options['verbosity']), 'cached': options['cached']}) # Activate the default language for the duration of the import # to make sure translated fields are populated correctly. old_lang = get_language() activate(settings.LANGUAGES[0][0]) for imp_type in self.importer_types: name = "import_%s" % imp_type method = getattr(importer, name, None) if options[imp_type]: if not method: raise CommandError("Importer %s does not support importing %s" % (name, imp_type)) else: if not options['all']: continue if method: method() activate(old_lang)
def __init__(self): super().__init__() self.importers = get_importers() self.imp_list = ', '.join(sorted(self.importers.keys())) self.missing_args_message = "Enter the name of the event importer module. Valid importers: %s" % self.imp_list