diff options
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 |
commit | 0da18d32564c5020eaab7a77e7ee88aeb5f260d9 (patch) | |
tree | b75fdd0ee3bd9104919b20d7059adf5561694636 /archaeological_finds | |
parent | 22d83247ab5045a6b7f22fbbd058e9ee8785222f (diff) | |
download | Ishtar-0da18d32564c5020eaab7a77e7ee88aeb5f260d9.tar.bz2 Ishtar-0da18d32564c5020eaab7a77e7ee88aeb5f260d9.zip |
Imports, add post import trigger for finds: set_localisation_1, _2, ...
Diffstat (limited to 'archaeological_finds')
-rw-r--r-- | archaeological_finds/models_finds.py | 75 |
1 files changed, 75 insertions, 0 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 |