diff options
| -rw-r--r-- | ishtar_common/data_importer.py | 6 | ||||
| -rw-r--r-- | ishtar_common/management/commands/update_specific_importers.py | 13 | ||||
| -rw-r--r-- | ishtar_common/models.py | 9 | 
3 files changed, 25 insertions, 3 deletions
| diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index 5f70d81e3..1a77c2546 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -617,11 +617,13 @@ class Importer(object):          'regex_not_match': _(u"The regexp doesn't match.")      } -    def _create_models(self): +    def _create_models(self, force=False):          from ishtar_common import models          q = models.ImporterType.objects.filter(slug=self.SLUG) -        if not self.SLUG or q.count(): +        if not force and (not self.SLUG or q.count()):              return +        if force and q.count(): +            q.all()[0].delete()          name = self.NAME if self.NAME else self.SLUG          model_name = self.OBJECT_CLS.__module__ + '.' + \ diff --git a/ishtar_common/management/commands/update_specific_importers.py b/ishtar_common/management/commands/update_specific_importers.py index 46669a236..c5445eb0b 100644 --- a/ishtar_common/management/commands/update_specific_importers.py +++ b/ishtar_common/management/commands/update_specific_importers.py @@ -1,6 +1,8 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- +from optparse import make_option +  from django.core.management.base import BaseCommand  from django.conf import settings @@ -14,10 +16,19 @@ if 'archaeological_files' in settings.INSTALLED_APPS:  class Command(BaseCommand):      help = "Update each specific importer" +    option_list = list(BaseCommand.option_list) + [ +        make_option( +            '--force', +            action='store_true', +            dest='force', +            default=False, +            help='Force the deletion of existing importers. ' +                 'ATTENTION: all associated imports and all associated items ' +                 'will be deleted.')]      def handle(self, *args, **options):          for importer in IMPORTERS: -            response = importer()._create_models() +            response = importer()._create_models(force=options['force'])              if response:                  self.stdout.write("%s configured\n" % importer.__name__)                  self.stdout.flush() diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 7c8c8888d..25da4b7d7 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1237,6 +1237,9 @@ class ImporterDefault(models.Model):          verbose_name = _(u"Importer - Default")          verbose_name_plural = _(u"Importer - Defaults") +    def __unicode__(self): +        return u"{} - {}".format(self.importer_type, self.target) +      @property      def keys(self):          return tuple(self.target.split('__')) @@ -1263,6 +1266,9 @@ class ImporterDefaultValues(models.Model):      target = models.CharField(u"Target", max_length=500)      value = models.CharField(u"Value", max_length=500) +    def __unicode__(self): +        return u"{} - {}".format(self.default_target, self.target, self.value) +      class Meta:          verbose_name = _(u"Importer - Default value")          verbose_name_plural = _(u"Importer - Default values") @@ -1306,6 +1312,9 @@ class ImporterColumn(models.Model):          verbose_name = _(u"Importer - Column")          verbose_name_plural = _(u"Importer - Columns") +    def __unicode__(self): +        return u"{} - {}".format(self.importer_type, self.col_number) +  class ImporterDuplicateField(models.Model):      """ | 
