diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-04-06 12:31:38 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:20 +0100 |
commit | 0f96790ca2866d205b262c96ddb1b155abb80ef6 (patch) | |
tree | 1ac684557b5b6d2b7457b80040f8955e0db19d07 /archaeological_finds/models_finds.py | |
parent | 8b69114b1932329283f3563077a3cb53149af7c8 (diff) | |
download | Ishtar-0f96790ca2866d205b262c96ddb1b155abb80ef6.tar.bz2 Ishtar-0f96790ca2866d205b262c96ddb1b155abb80ef6.zip |
New container localisation - adapt sheets, imports
Diffstat (limited to 'archaeological_finds/models_finds.py')
-rw-r--r-- | archaeological_finds/models_finds.py | 168 |
1 files changed, 155 insertions, 13 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 0260200e9..119a2022a 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -785,8 +785,7 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem, 'base_finds__context_record__label', 'cached_materials', 'cached_object_types', 'cached_periods', - 'container__cached_label', - 'container_ref__cached_label'] + 'container__cached_label'] if settings.COUNTRY == 'fr': TABLE_COLS.insert( 3, 'base_finds__context_record__operation__code_patriarche') @@ -2294,7 +2293,8 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem, def localisation_9(self): return self.get_localisation(8) - def set_localisation(self, place, context, value, is_ref=False): + def set_localisation(self, place, context, value, is_ref=False, + static=False): """ Get localisation reference in the warehouse @@ -2302,6 +2302,7 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem, :param context: context of the request - not used :param value: localisation value :param is_ref: if true - reference container else current container + :param static: if true: do not create new container :return: None """ if is_ref: @@ -2314,19 +2315,17 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem, return if is_ref: raise ImporterError( - _(u"No reference container have been set - the " - u"localisation cannot be set.")) + _("No reference container have been set - the " + "localisation cannot be set.")) else: raise ImporterError( - _(u"No container have been set - the localisation cannot " - u"be set.")) + _("No container have been set - the localisation cannot " + "be set.")) - localisation = container.set_localisation(place, value) - if value and value != '-' and not localisation: - raise ImporterError( - str(_(u"The division number {} have not been set " - u"for the warehouse {}.")).format( - place + 1, container.location)) + localisation, error = container.set_localisation( + place, value, static=static, return_errors=True) + if error: + raise ImporterError(error) @post_importer_action def set_reference_localisation_1(self, context, value): @@ -2374,6 +2373,60 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem, set_reference_localisation_9.post_save = True @post_importer_action + def set_reference_static_localisation_1(self, context, value): + return self.set_localisation(0, context, value, is_ref=True, + static=True) + set_reference_static_localisation_1.post_save = True + + @post_importer_action + def set_reference_static_localisation_2(self, context, value): + return self.set_localisation(1, context, value, is_ref=True, + static=True) + set_reference_static_localisation_2.post_save = True + + @post_importer_action + def set_reference_static_localisation_3(self, context, value): + return self.set_localisation(2, context, value, is_ref=True, + static=True) + set_reference_static_localisation_3.post_save = True + + @post_importer_action + def set_reference_static_localisation_4(self, context, value): + return self.set_localisation(3, context, value, is_ref=True, + static=True) + set_reference_static_localisation_4.post_save = True + + @post_importer_action + def set_reference_static_localisation_5(self, context, value): + return self.set_localisation(4, context, value, is_ref=True, + static=True) + set_reference_static_localisation_5.post_save = True + + @post_importer_action + def set_reference_static_localisation_6(self, context, value): + return self.set_localisation(5, context, value, is_ref=True, + static=True) + set_reference_static_localisation_6.post_save = True + + @post_importer_action + def set_reference_static_localisation_7(self, context, value): + return self.set_localisation(6, context, value, is_ref=True, + static=True) + set_reference_static_localisation_7.post_save = True + + @post_importer_action + def set_reference_static_localisation_8(self, context, value): + return self.set_localisation(7, context, value, is_ref=True, + static=True) + set_reference_static_localisation_8.post_save = True + + @post_importer_action + def set_reference_static_localisation_9(self, context, value): + return self.set_localisation(8, context, value, is_ref=True, + static=True) + set_reference_static_localisation_9.post_save = True + + @post_importer_action def set_localisation_1(self, context, value): return self.set_localisation(0, context, value) set_localisation_1.post_save = True @@ -2418,6 +2471,51 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem, return self.set_localisation(8, context, value) set_localisation_9.post_save = True + @post_importer_action + def set_static_localisation_1(self, context, value): + return self.set_localisation(0, context, value, static=True) + set_static_localisation_1.post_save = True + + @post_importer_action + def set_static_localisation_2(self, context, value): + return self.set_localisation(1, context, value, static=True) + set_static_localisation_2.post_save = True + + @post_importer_action + def set_static_localisation_3(self, context, value): + return self.set_localisation(2, context, value, static=True) + set_static_localisation_3.post_save = True + + @post_importer_action + def set_static_localisation_4(self, context, value): + return self.set_localisation(3, context, value, static=True) + set_static_localisation_4.post_save = True + + @post_importer_action + def set_static_localisation_5(self, context, value): + return self.set_localisation(4, context, value, static=True) + set_static_localisation_5.post_save = True + + @post_importer_action + def set_static_localisation_6(self, context, value): + return self.set_localisation(5, context, value, static=True) + set_static_localisation_6.post_save = True + + @post_importer_action + def set_static_localisation_7(self, context, value): + return self.set_localisation(6, context, value, static=True) + set_static_localisation_7.post_save = True + + @post_importer_action + def set_static_localisation_8(self, context, value): + return self.set_localisation(7, context, value, static=True) + set_static_localisation_8.post_save = True + + @post_importer_action + def set_static_localisation_9(self, context, value): + return self.set_localisation(8, context, value, static=True) + set_static_localisation_9.post_save = True + def generate_index(self): """ Generate index based on operation or context record (based on @@ -2555,6 +2653,50 @@ m2m_changed.connect(base_find_find_changed, sender=Find.base_finds.through) m2m_changed.connect(document_attached_changed, sender=Find.documents.through) + +class FindInsideContainer(models.Model): + CREATE_SQL = """ + CREATE VIEW find_inside_container AS + SELECT fb.id AS find_id, fb.container_id AS container_id + FROM archaeological_finds_find fb + WHERE fb.downstream_treatment_id IS NULL AND fb.container_id IS NOT NULL + UNION + SELECT f.id AS find_id, r.container_parent_id AS container_id + FROM archaeological_finds_find f + INNER JOIN container_tree r + ON r.container_id = f.container_id + WHERE f.downstream_treatment_id IS NULL; + + -- deactivate deletion + CREATE RULE find_inside_container_del AS + ON DELETE TO find_inside_container + DO INSTEAD DELETE FROM archaeological_finds_find where id=NULL; + """ + DELETE_SQL = """ + DROP VIEW IF EXISTS find_inside_container; + """ + TABLE_COLS = ["find__" + t for t in Find.TABLE_COLS] + COL_LABELS = { + "find__" + k: Find.COL_LABELS[k] for k in Find.COL_LABELS.keys() + } + EXTRA_REQUEST_KEYS = { + "find__" + k: + "find__" + Find.EXTRA_REQUEST_KEYS[k] + for k in Find.EXTRA_REQUEST_KEYS.keys() + } + + find = models.OneToOneField( + Find, verbose_name=_("Find"), related_name="inside_container", + primary_key=True) + container = models.ForeignKey("archaeological_warehouse.Container", + verbose_name=_("Container"), + related_name="container_content") + + class Meta: + managed = False + db_table = 'find_inside_container' + + for attr in Find.HISTORICAL_M2M: m2m_changed.connect(m2m_historization_changed, sender=getattr(Find, attr).through) |