diff options
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/management/commands/ishtar_import.py | 38 | ||||
| -rw-r--r-- | ishtar_common/models.py | 4 | 
2 files changed, 40 insertions, 2 deletions
| diff --git a/ishtar_common/management/commands/ishtar_import.py b/ishtar_common/management/commands/ishtar_import.py new file mode 100644 index 000000000..49a7a0e64 --- /dev/null +++ b/ishtar_common/management/commands/ishtar_import.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from django.core.management.base import BaseCommand, CommandError + +from ishtar_common import models + + +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\"." + +    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\"." +            ) +        try: +            imp = models.Import.objects.get(pk=args[1]) +        except (ValueError, models.Import.DoesNotExist): +            raise CommandError("{} is not a valid import ID".format(args[0])) +        if command == 'analyse': +            imp.initialize() +            self.stdout.write("* {} analysed\n".format(imp)) +            self.stdout.flush() +        elif command == 'import': +            self.stdout.write("* import {}\n".format(imp)) +            imp.importation(output='cli') +            self.stdout.write("* {} imported\n".format(imp)) +            self.stdout.flush() +        elif command == 'archive': +            imp.archive() +            self.stdout.write("*{} archived\n".format(imp)) +            self.stdout.flush() diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 20b8a6f46..c657f532d 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1690,8 +1690,8 @@ class Import(models.Model):          verbose_name_plural = _(u"Imports")      def __unicode__(self): -        return u"%s - %s" % (unicode(self.importer_type), -                             unicode(self.user)) +        return u"%s - %s - %d" % (unicode(self.importer_type), +                                  unicode(self.user), self.pk)      def need_matching(self):          return bool(TargetKey.objects.filter(associated_import=self, | 
