diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-11-30 10:31:59 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-11-30 10:31:59 +0100 |
commit | f4466b9107ab7849db1ef8c092aadb5bb90331a3 (patch) | |
tree | c0f368005bc0393d40514cd7eb06cbe46008a45a | |
parent | 17d31c7c5fec183863f2616ca1e86d773205689e (diff) | |
download | Ishtar-f4466b9107ab7849db1ef8c092aadb5bb90331a3.tar.bz2 Ishtar-f4466b9107ab7849db1ef8c092aadb5bb90331a3.zip |
Containers: allow direct import of localisation
-rw-r--r-- | archaeological_finds/models_finds.py | 24 | ||||
-rw-r--r-- | archaeological_warehouse/models.py | 84 |
2 files changed, 108 insertions, 0 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 65850d4dc..8be440181 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -1147,6 +1147,18 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, ImageModel, def localisation_6(self): return self.get_localisation(5) + @property + def localisation_7(self): + return self.get_localisation(6) + + @property + def localisation_8(self): + return self.get_localisation(7) + + @property + def localisation_9(self): + return self.get_localisation(8) + def set_localisation(self, place, context, value): if not self.container: if not value: @@ -1185,6 +1197,18 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, ImageModel, def set_localisation_6(self, context, value): return self.set_localisation(5, context, value) + @post_importer_action + def set_localisation_7(self, context, value): + return self.set_localisation(6, context, value) + + @post_importer_action + def set_localisation_8(self, context, value): + return self.set_localisation(7, context, value) + + @post_importer_action + def set_localisation_9(self, context, value): + return self.set_localisation(8, context, value) + def generate_index(self): """ Generate index based on operation or context record (based on diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index fdd3a5e63..bea55be9b 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -26,6 +26,7 @@ from django.db.models.signals import post_save, post_delete from django.template.defaultfilters import slugify from django.utils.translation import ugettext_lazy as _ +from ishtar_common.data_importer import post_importer_action from ishtar_common.utils import cached_label_changed from ishtar_common.models import GeneralType, get_external_id, \ @@ -38,6 +39,8 @@ class WarehouseType(GeneralType): verbose_name = _(u"Warehouse type") verbose_name_plural = _(u"Warehouse types") ordering = ('label',) + + post_save.connect(post_save_cache, sender=WarehouseType) post_delete.connect(post_save_cache, sender=WarehouseType) @@ -217,6 +220,8 @@ class WarehouseDivision(GeneralType): class Meta: verbose_name = _(u"Warehouse division type") verbose_name_plural = _(u"Warehouse division types") + + post_save.connect(post_save_cache, sender=WarehouseDivision) post_delete.connect(post_save_cache, sender=WarehouseDivision) @@ -354,6 +359,48 @@ class Container(LightHistorizedItem, ImageModel): container=self).order_by('division__order') )) + def get_localisation(self, place): + locas = self.get_localisations() + if len(locas) < (place + 1): + return "" + return locas[place] + + @property + def localisation_1(self): + return self.get_localisation(0) + + @property + def localisation_2(self): + return self.get_localisation(1) + + @property + def localisation_3(self): + return self.get_localisation(2) + + @property + def localisation_4(self): + return self.get_localisation(3) + + @property + def localisation_5(self): + return self.get_localisation(4) + + @property + def localisation_6(self): + return self.get_localisation(5) + + @property + def localisation_7(self): + return self.get_localisation(6) + + @property + def localisation_8(self): + return self.get_localisation(7) + + @property + def localisation_9(self): + return self.get_localisation(8) + def set_localisation(self, place, value): """ Set the reference for the localisation number "place" (starting from 0) @@ -379,6 +426,42 @@ class Container(LightHistorizedItem, ImageModel): obj, created = ContainerLocalisation.objects.update_or_create(**dct) return obj + @post_importer_action + def set_localisation_1(self, context, value): + return self.set_localisation(0, value) + + @post_importer_action + def set_localisation_2(self, context, value): + return self.set_localisation(1, value) + + @post_importer_action + def set_localisation_3(self, context, value): + return self.set_localisation(2, value) + + @post_importer_action + def set_localisation_4(self, context, value): + return self.set_localisation(3, value) + + @post_importer_action + def set_localisation_5(self, context, value): + return self.set_localisation(4, value) + + @post_importer_action + def set_localisation_6(self, context, value): + return self.set_localisation(5, value) + + @post_importer_action + def set_localisation_7(self, context, value): + return self.set_localisation(6, value) + + @post_importer_action + def set_localisation_8(self, context, value): + return self.set_localisation(7, value) + + @post_importer_action + def set_localisation_9(self, context, value): + return self.set_localisation(8, value) + @property def divisions_lbl(self): locas = [ @@ -430,6 +513,7 @@ class Container(LightHistorizedItem, ImageModel): for loca in q.all(): loca.delete() + post_save.connect(cached_label_changed, sender=Container) |