diff options
Diffstat (limited to 'ishtar_common/management/commands')
3 files changed, 48 insertions, 13 deletions
diff --git a/ishtar_common/management/commands/ishtar_import.py b/ishtar_common/management/commands/ishtar_import.py index aba1e45d5..3b04528f0 100644 --- a/ishtar_common/management/commands/ishtar_import.py +++ b/ishtar_common/management/commands/ishtar_import.py @@ -3,22 +3,41 @@ from django.core.management.base import BaseCommand, CommandError -from ishtar_common import models +from ishtar_common import models, models_imports class Command(BaseCommand): help = "./manage.py ishtar_import <command> <import_id>\n\n"\ "Launch the importation a configured import.\n"\ - "<command> must be: \"analyse\", \"import\" or \"archive\"." + "<command> must be: \"list\", \"analyse\", \"import\" or " \ + "\"archive\"." + + def add_arguments(self, parser): + parser.add_argument('command', choices=["list", "analyse", "import", + "archive"]) + parser.add_argument('import_id', nargs='?', default=None) def handle(self, *args, **options): - if not args or len(args) < 2: - raise CommandError("<command> and <import_id> are mandatory") - command = args[0] - if args[0] not in ["analyse", "import", "archive"]: - raise CommandError( - "<command> must be: \"analyse\", \"import\" or \"archive\"." - ) + command = options['command'] + import_id = options['import_id'] + if command != "list" and not import_id: + raise CommandError("With {} <import_id> is mandatory".format( + command)) + if command == 'list': + state = dict(models_imports.IMPORT_STATE) + self.stdout.write("*" * 80 + "\n") + self.stdout.write( + "| pk | type | state " + "| name\n") + self.stdout.write("*" * 80 + "\n") + for imp in models.Import.objects.exclude(state="AC").all(): + self.stdout.write(u"|{: ^6}| {: ^32} | {: ^12} | {}\n".format( + imp.pk, unicode(imp.importer_type)[:32], + state[imp.state][:12], + imp.name[:128])) + self.stdout.write("*" * 80 + "\n") + self.stdout.flush() + return try: imp = models.Import.objects.get(pk=args[1]) except (ValueError, models.Import.DoesNotExist): diff --git a/ishtar_common/management/commands/reassociate_similar_images.py b/ishtar_common/management/commands/reassociate_similar_images.py index f6d432327..a0483ed3a 100644 --- a/ishtar_common/management/commands/reassociate_similar_images.py +++ b/ishtar_common/management/commands/reassociate_similar_images.py @@ -169,7 +169,7 @@ class Command(BaseCommand): for m2m in m2ms: for m2 in getattr(item, m2m).all(): - if m2 not in getattr(ref_item, m2m): + if m2 not in getattr(ref_item, m2m).all(): getattr(ref_item, m2m).add(m2) for rel_attr in Document.RELATED_MODELS: diff --git a/ishtar_common/management/commands/regenerate_search_vector_cached_label.py b/ishtar_common/management/commands/regenerate_search_vector_cached_label.py index 59e37d75b..404811acf 100644 --- a/ishtar_common/management/commands/regenerate_search_vector_cached_label.py +++ b/ishtar_common/management/commands/regenerate_search_vector_cached_label.py @@ -24,16 +24,32 @@ from django.core.management.base import BaseCommand from django.apps import apps +APPS = ['ishtar_common', 'archaeological_operations', + 'archaeological_context_records', 'archaeological_finds', + 'archaeological_warehouse'] + + class Command(BaseCommand): args = '' help = 'Regenerate cached labels and search vectors' + def add_arguments(self, parser): + parser.add_argument('app_name', nargs='?', default=None, + choices=APPS) + parser.add_argument('model_name', nargs='?', default=None) + def handle(self, *args, **options): - for app in ['ishtar_common', 'archaeological_operations', - 'archaeological_context_records', - 'archaeological_finds', 'archaeological_warehouse']: + limit = options['app_name'] + model_name = options['model_name'] + if model_name: + model_name = model_name.lower() + for app in APPS: + if limit and app != limit: + continue print(u"* app: {}".format(app)) for model in apps.get_app_config(app).get_models(): + if model_name and model.__name__.lower() != model_name: + continue if model.__name__.startswith('Historical'): continue if not bool( |