summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-08-07 21:23:25 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-08-07 21:23:25 +0200
commita52afe958a6f9d45d55065be044e3daf101936cd (patch)
treeb75fdd0ee3bd9104919b20d7059adf5561694636
parentdc643fdf32e0e27b99dc560f8b2c4107b6cefc19 (diff)
downloadIshtar-a52afe958a6f9d45d55065be044e3daf101936cd.tar.bz2
Ishtar-a52afe958a6f9d45d55065be044e3daf101936cd.zip
Imports, add post import trigger for finds: set_localisation_1, _2, ...
-rw-r--r--archaeological_finds/models_finds.py75
-rw-r--r--archaeological_warehouse/models.py36
-rw-r--r--ishtar_common/data_importer.py1
3 files changed, 109 insertions, 3 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 421274524..f16efcbcc 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -27,6 +27,7 @@ from django.db.models import Max, Q
from django.db.models.signals import m2m_changed, post_save, post_delete
from django.utils.translation import ugettext_lazy as _, ugettext
+from ishtar_common.data_importer import post_importer_action, ImporterError
from ishtar_common.utils import cached_label_changed, post_save_point
from ishtar_common.models import GeneralType, ImageModel, BaseHistorizedItem, \
@@ -1043,6 +1044,80 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, ImageModel,
with connection.cursor() as c:
c.execute(sql, args)
+ def get_localisation(self, place):
+ """
+ Get localisation reference in the warehouse
+
+ :param place: number of the localisation starting with 0
+ :return: reference - empty string if not available
+ """
+ if not self.container:
+ return ""
+ locas = self.container.get_localisations()
+ if len(locas) < place:
+ 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)
+
+ def set_localisation(self, place, context, value):
+ if not self.container:
+ raise ImporterError(_(u"No container have been set - the "
+ u"localisation cannot be set."))
+
+ localisation = self.container.set_localisation(place, value)
+ if not localisation:
+ raise ImporterError(
+ unicode(_(u"The division number {} have not been set "
+ u"for the warehouse {}.")).format(
+ place + 1, self.container.location))
+
+ @post_importer_action
+ def set_localisation_1(self, context, value):
+ return self.set_localisation(0, context, value)
+
+ @post_importer_action
+ def set_localisation_2(self, context, value):
+ return self.set_localisation(1, context, value)
+
+ @post_importer_action
+ def set_localisation_3(self, context, value):
+ return self.set_localisation(2, context, value)
+
+ @post_importer_action
+ def set_localisation_4(self, context, value):
+ return self.set_localisation(3, context, value)
+
+ @post_importer_action
+ def set_localisation_5(self, context, value):
+ return self.set_localisation(4, context, value)
+
+ @post_importer_action
+ def set_localisation_6(self, context, value):
+ return self.set_localisation(5, 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 35e5536fa..31701dbf9 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -21,10 +21,10 @@ import datetime
from django.conf import settings
from django.contrib.gis.db import models
-from django.db.models import Q, Count
+from django.db.models import Q
from django.db.models.signals import post_save, post_delete
from django.template.defaultfilters import slugify
-from django.utils.translation import ugettext_lazy as _, ugettext
+from django.utils.translation import ugettext_lazy as _
from ishtar_common.utils import cached_label_changed
@@ -328,6 +328,38 @@ class Container(LightHistorizedItem, ImageModel):
def precise_location(self):
return self.location.name + u" - " + self.divisions_lbl
+ def get_localisations(self):
+ """
+ Get precise localisation of the container in the warehouse.
+
+ :return: tuple of strings with localisations
+ """
+ return tuple((
+ loca.reference
+ for loca in ContainerLocalisation.objects.filter(
+ container=self).order_by('division__order')
+ ))
+
+ def set_localisation(self, place, value):
+ """
+ Set the reference for the localisation number "place" (starting from 0)
+ :param place: the number of the localisation
+ :param value: the reference to be set
+ :return: the container location object or None if the place does not
+ exist
+ """
+ q = WarehouseDivisionLink.objects.filter(
+ warehouse=self.location).order_by('order')
+ for idx, division_link in enumerate(q.all()):
+ if idx == place:
+ break
+ else:
+ return
+ obj, created = ContainerLocalisation.objects.update_or_create(
+ container=self, division=division_link,
+ defaults={'reference': value})
+ return obj
+
@property
def divisions_lbl(self):
locas = [
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py
index 9a4435c27..c89e46f0b 100644
--- a/ishtar_common/data_importer.py
+++ b/ishtar_common/data_importer.py
@@ -1417,7 +1417,6 @@ class Importer(object):
if func.importer_trigger == 'pre':
pass # TODO
elif func.importer_trigger == 'post':
- print("ok!!!!!!")
self._item_post_processing.append([attribute, data,
data[attribute]])
else: