diff options
Diffstat (limited to 'ishtar_common/models_imports.py')
| -rw-r--r-- | ishtar_common/models_imports.py | 30 | 
1 files changed, 23 insertions, 7 deletions
diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py index 852e9fe3a..6a313a95d 100644 --- a/ishtar_common/models_imports.py +++ b/ishtar_common/models_imports.py @@ -35,6 +35,7 @@ from django.core.files.base import ContentFile  from django.db.models.base import ModelBase  from django.db.models.signals import pre_delete  from django.template.defaultfilters import slugify +from django.utils.functional import cached_property  from django.utils.translation import ugettext_lazy as _, pgettext_lazy  from ishtar_common.utils import create_slug, \ @@ -462,6 +463,14 @@ class ImportTarget(models.Model):      def __unicode__(self):          return self.target[:50] if self.target else self.comment +    @cached_property +    def verbose_name(self): +        if not self.column.description: +            return self.target[:50] +        desc = self.column.description +        desc = desc[0].lower() + desc[1:] +        return u"{} - {}".format(self.target[:50], desc) +      def natural_key(self):          return self.column.importer_type.slug, self.column.col_number, \                 self.target @@ -518,8 +527,9 @@ class TargetKey(models.Model):      Also temporary used for GeneralType to point missing link before adding      them in ItemKey table.      A targetkey connection can be create to be applied to one particular -    import (associated_import), one particular user (associated_user) or to all -    imports (associated_import and associated_user are empty). +    import (associated_import), one particular user (associated_user), +    one particular group (associated_group) or to all imports +    (associated_import, associated_user and associated_group are empty).      """      target = models.ForeignKey(ImportTarget, related_name='keys')      key = models.TextField(_(u"Key")) @@ -534,6 +544,7 @@ class TargetKey(models.Model):                             'associated_import',)          verbose_name = _(u"Importer - Target key")          verbose_name_plural = _(u"Importer - Targets keys") +        ordering = ('target', 'key')      def __unicode__(self):          return u" - ".join([unicode(self.target), self.key[:50]]) @@ -740,18 +751,23 @@ ENCODINGS = [(settings.ENCODING, settings.ENCODING),  class Import(models.Model):      user = models.ForeignKey('IshtarUser') -    name = models.CharField(_(u"Name"), max_length=500, -                            blank=True, null=True) +    name = models.CharField(_(u"Name"), max_length=500, null=True)      importer_type = models.ForeignKey(ImporterType)      imported_file = models.FileField(          _(u"Imported file"), upload_to="upload/imports/%Y/%m/", max_length=220)      imported_images = models.FileField(          _(u"Associated images (zip file)"), upload_to="upload/imports/%Y/%m/",          blank=True, null=True, max_length=220) -    associated_group = models.ForeignKey(TargetKeyGroup, blank=True, null=True) +    associated_group = models.ForeignKey( +        TargetKeyGroup, blank=True, null=True, +        help_text=_(u"If a group is selected, target key saved in this group " +                    u"will be used.") +    )      encoding = models.CharField(_(u"Encoding"), choices=ENCODINGS,                                  default=u'utf-8', max_length=15) -    skip_lines = models.IntegerField(_(u"Skip lines"), default=1) +    skip_lines = models.IntegerField( +        _(u"Skip lines"), default=1, +        help_text=_(u"Number of header lines in your file (can be 0)."))      error_file = models.FileField(_(u"Error file"),                                    upload_to="upload/imports/%Y/%m/",                                    blank=True, null=True, max_length=255) @@ -765,7 +781,7 @@ class Import(models.Model):                               default=u'C')      conservative_import = models.BooleanField(          _(u"Conservative import"), default=False, -        help_text='If set to true, do not overload existing values') +        help_text=_(u'If set to true, do not overload existing values.'))      creation_date = models.DateTimeField(          _(u"Creation date"), auto_now_add=True, blank=True, null=True)      end_date = models.DateTimeField(_(u"End date"), blank=True,  | 
