diff options
Diffstat (limited to 'archaeological_finds/models_finds.py')
| -rw-r--r-- | archaeological_finds/models_finds.py | 157 | 
1 files changed, 140 insertions, 17 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index b8f8d61a7..5dc8abc98 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -673,7 +673,8 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,                    'base_finds__context_record__label',                    'material_types__label', 'object_types__label',                    'datings__period__label', -                  'container__cached_label', ] +                  'container__cached_label', +                  'container_ref__cached_label']      if settings.COUNTRY == 'fr':          TABLE_COLS.insert(              3, 'base_finds__context_record__operation__code_patriarche') @@ -683,7 +684,7 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,          'previous_id', 'label', 'material_types__label',          'datings__period__label', 'find_number', 'object_types__label',          'container__cached_label', -        'container__cached_location', +        'container_ref__cached_label',          'description',          'base_finds__context_record__town__name',          'base_finds__context_record__parcel', ] @@ -701,7 +702,7 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,          'base_finds__context_record__archaeological_site__name':              IshtarSiteProfile.get_default_site_label,          'base_finds__context_record__parcel': _(u"Parcel"), -        'base_finds__batch':_(u"Batch"), +        'base_finds__batch': _(u"Batch"),          'base_finds__comment': _(u"Base find - Comment"),          'base_finds__description': _(u"Base find - Description"),          'base_finds__topographic_localisation': _(u"Base find - " @@ -711,7 +712,8 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,              u"Base find - Discovery date (exact or TPQ)"),          'base_finds__discovery_date_taq': _(              u"Base find - Discovery date (TAQ)"), -        'container__cached_label': _(u"Container"), +        'container__cached_label': _(u"Current container"), +        'container_ref__cached_label': _(u"Reference container"),          'datings__period__label': _(u"Periods"),          'material_types__label': _(u"Material types"),          'object_types__label': _(u"Object types"), @@ -894,20 +896,36 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,              pgettext_lazy("key for text search", u"has-image"),              'documents__image__isnull',          ), -        'container__location': ( +        'container_ref__location': (              pgettext_lazy("key for text search", u"location"), +            'container_ref__location__name__iexact', +        ), +        'container_ref__responsible': ( +            pgettext_lazy("key for text search", u"warehouse"), +            'container_ref__responsible__name__iexact', +        ), +        'container_ref__index': ( +            pgettext_lazy("key for text search", u"container-index"), +            'container_ref__index', +        ), +        'container_ref__reference': ( +            pgettext_lazy("key for text search", u"container-ref"), +            'container_ref__reference__iexact', +        ), +        'container__location': ( +            pgettext_lazy("key for text search", u"current-location"),              'container__location__name__iexact',          ),          'container__responsible': ( -            pgettext_lazy("key for text search", u"warehouse"), +            pgettext_lazy("key for text search", u"current-warehouse"),              'container__responsible__name__iexact',          ),          'container__index': ( -            pgettext_lazy("key for text search", u"container-index"), +            pgettext_lazy("key for text search", u"current-container-index"),              'container__index',          ),          'container__reference': ( -            pgettext_lazy("key for text search", u"container-ref"), +            pgettext_lazy("key for text search", u"current-container-ref"),              'container__reference__iexact',          ),          'basket': ( @@ -1034,6 +1052,11 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,          "archaeological_warehouse.Container", verbose_name=_(u"Container"),          blank=True, null=True,          related_name='finds', on_delete=models.SET_NULL) +    container_ref = models.ForeignKey( +        "archaeological_warehouse.Container", +        verbose_name=_(u"Reference container"), +        blank=True, null=True, +        related_name='finds_ref', on_delete=models.SET_NULL)      is_complete = models.NullBooleanField(_(u"Is complete?"), blank=True,                                            null=True)      object_types = models.ManyToManyField( @@ -1541,21 +1564,62 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,          with connection.cursor() as c:              c.execute(sql, args) -    def get_localisation(self, place): +    def get_localisation(self, place, is_ref=False):          """          Get localisation reference in the warehouse          :param place: number of the localisation starting with 0 +        :param is_ref: if true - reference container else current container          :return: reference - empty string if not available          """ -        if not self.container: +        if is_ref: +            container = self.container_ref +        else: +            container = self.container +        if not container:              return "" -        locas = self.container.get_localisations() +        locas = container.get_localisations()          if len(locas) < (place + 1):              return ""          return locas[place]      @property +    def reference_localisation_1(self): +        return self.get_localisation(0, is_ref=True) + +    @property +    def reference_localisation_2(self): +        return self.get_localisation(1, is_ref=True) + +    @property +    def reference_localisation_3(self): +        return self.get_localisation(2, is_ref=True) + +    @property +    def reference_localisation_4(self): +        return self.get_localisation(3, is_ref=True) + +    @property +    def reference_localisation_5(self): +        return self.get_localisation(4, is_ref=True) + +    @property +    def reference_localisation_6(self): +        return self.get_localisation(5, is_ref=True) + +    @property +    def reference_localisation_7(self): +        return self.get_localisation(6, is_ref=True) + +    @property +    def reference_localisation_8(self): +        return self.get_localisation(7, is_ref=True) + +    @property +    def reference_localisation_9(self): +        return self.get_localisation(8, is_ref=True) + +    @property      def localisation_1(self):          return self.get_localisation(0) @@ -1591,19 +1655,75 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,      def localisation_9(self):          return self.get_localisation(8) -    def set_localisation(self, place, context, value): -        if not self.container: +    def set_localisation(self, place, context, value, is_ref=False): +        """ +        Get localisation reference in the warehouse + +        :param place: number of the localisation starting with 0 +        :param context: context of the request - not used +        :param value: localisation value +        :param is_ref: if true - reference container else current container +        :return: None +        """ +        if is_ref: +            container = self.container_ref +        else: +            container = self.container + +        if not container:              if not value:                  return -            raise ImporterError(_(u"No container have been set - the " -                                  u"localisation cannot be set.")) +            if is_ref: +                raise ImporterError( +                    _(u"No reference container have been set - the " +                      u"localisation cannot be set.")) +            else: +                raise ImporterError( +                    _(u"No container have been set - the localisation cannot " +                      u"be set.")) -        localisation = self.container.set_localisation(place, value) +        localisation = container.set_localisation(place, value)          if value and value != '-' and not localisation:              raise ImporterError(                  unicode(_(u"The division number {} have not been set "                            u"for the warehouse {}.")).format( -                    place + 1, self.container.location)) +                    place + 1, container.location)) + +    @post_importer_action +    def set_reference_localisation_1(self, context, value): +        return self.set_localisation(0, context, value, is_ref=True) + +    @post_importer_action +    def set_reference_localisation_2(self, context, value): +        return self.set_localisation(1, context, value, is_ref=True) + +    @post_importer_action +    def set_reference_localisation_3(self, context, value): +        return self.set_localisation(2, context, value, is_ref=True) + +    @post_importer_action +    def set_reference_localisation_4(self, context, value): +        return self.set_localisation(3, context, value, is_ref=True) + +    @post_importer_action +    def set_reference_localisation_5(self, context, value): +        return self.set_localisation(4, context, value, is_ref=True) + +    @post_importer_action +    def set_reference_localisation_6(self, context, value): +        return self.set_localisation(5, context, value, is_ref=True) + +    @post_importer_action +    def set_reference_localisation_7(self, context, value): +        return self.set_localisation(6, context, value, is_ref=True) + +    @post_importer_action +    def set_reference_localisation_8(self, context, value): +        return self.set_localisation(7, context, value, is_ref=True) + +    @post_importer_action +    def set_reference_localisation_9(self, context, value): +        return self.set_localisation(8, context, value, is_ref=True)      @post_importer_action      def set_localisation_1(self, context, value): @@ -1682,6 +1802,9 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, OwnPerms,          super(Find, self).save(*args, **kwargs)          self.skip_history_when_saving = True +        if self.container_ref and not self.container: +            self.container = self.container_ref +          updated = self.update_external_id(save=False)          if updated:              self._cached_label_checked = False  | 
