summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_warehouse/models.py')
-rw-r--r--archaeological_warehouse/models.py80
1 files changed, 21 insertions, 59 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index 800cfbccf..bdd9e1ded 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -35,7 +35,13 @@ from django.apps import apps
from ishtar_common.data_importer import post_importer_action, pre_importer_action, \
ImporterError
from ishtar_common.model_managers import UUIDModelManager
-from ishtar_common.models import ValueGetter, get_current_profile, HistoryModel, Imported
+from ishtar_common.models import (
+ get_current_profile,
+ HistoryModel,
+ Imported,
+ Town,
+ ValueGetter,
+)
from ishtar_common.models_common import (
GeneralType,
BaseHistorizedItem,
@@ -45,14 +51,12 @@ from ishtar_common.models_common import (
post_save_cache,
DashboardFormItem,
document_attached_changed,
- GeoItem,
CompleteIdentifierItem,
SearchVectorConfig,
DocumentItem,
QuickAction,
MainItem,
Merge,
- GeoVectorData,
)
from ishtar_common.model_merging import merge_model_objects
from ishtar_common.utils import (
@@ -61,6 +65,7 @@ from ishtar_common.utils import (
get_generated_id,
SearchAltName,
)
+from archaeological_context_records.models import GeographicSubTownItem
logger = logging.getLogger(__name__)
@@ -272,55 +277,10 @@ post_delete.connect(post_save_cache, sender=WarehouseType)
NO_DIVISION_ERROR = _("The division number {} has not been set for the warehouse {}.")
-def warehouse_post_save_geo(item, q_check_town, save=True):
- # manage geodata towns
- if getattr(item, "_post_save_geo_ok", False):
- # prevent infinite loop - should not happen, but...
- return
- item._post_save_geo_ok = True
- if not q_check_town.count():
- town_id = None
- q_geotown = GeoVectorData.objects.filter(pk=None)
- else:
- town_id = q_check_town.values_list("precise_town_id", flat=True)[0]
- q_geotown = GeoVectorData.objects.filter(
- source_content_type__model="town",
- source_content_type__app_label="ishtar_common",
- source_id=town_id,
- multi_polygon__isnull=False)
- q_geodata_town = item.geodata.filter(
- source_content_type__model="town",
- source_content_type__app_label="ishtar_common",
- )
- changed = False
- if not q_geotown.count():
- # no simple town - clean
- for geo in q_geodata_town.all():
- item.geodata.remove(geo)
- if item.main_geodata == geo:
- item.main_geodata = None
- changed = True
- else:
- for geo in q_geodata_town.exclude(source_id=town_id).all():
- item.geodata.remove(geo)
- if item.main_geodata == geo:
- item.main_geodata = None
- changed = True
- if not q_geodata_town.filter(source_id=town_id).count():
- item.geodata.add(q_geotown.all()[0])
- changed = True
-
- if changed and save:
- item.skip_history_when_saving = True
- item._no_move = True
- item.save()
- return changed
-
-
class Warehouse(
Address,
DocumentItem,
- GeoItem,
+ GeographicSubTownItem,
CompleteIdentifierItem,
OwnPerms,
MainItem,
@@ -492,13 +452,17 @@ class Warehouse(
def __str__(self):
return self.name
- def post_save_geo(self, save=True):
- q_check_town = Warehouse.objects.filter(pk=self.pk, precise_town_id__isnull=False)
- return warehouse_post_save_geo(self, q_check_town, save=save)
+ def _get_geo_town(self):
+ town_id = self.precise_town_id or (
+ self.organization and self.organization.precise_town_id
+ )
+ if not town_id:
+ return
+ return Town.objects.get(pk=town_id)
def get_container_type_by_place(self, place: int):
"""
- Container type by place based on the default organisation of the
+ Container type by place based on the default organization of the
warehouse
:param place: place number
@@ -881,7 +845,7 @@ class Container(
Merge,
BaseHistorizedItem,
CompleteIdentifierItem,
- GeoItem,
+ GeographicSubTownItem,
OwnPerms,
MainItem,
DivisionContainer,
@@ -1182,6 +1146,7 @@ class Container(
(("archaeological_finds", "Find"), "finds__pk"),
(("archaeological_finds", "Find"), "finds_ref__pk"),
]
+ UPPER_GEO = ["location"]
DEFAULT_WIZARD = reverse_lazy("container_search", args=["selec-container_search"])
objects = UUIDModelManager()
@@ -1293,11 +1258,8 @@ class Container(
def __str__(self):
return self.cached_label or ""
- def post_save_geo(self, save=True):
- q_check_town = Warehouse.objects.filter(
- pk=self.location_id, precise_town_id__isnull=False
- )
- return warehouse_post_save_geo(self, q_check_town, save=save)
+ def _get_geo_town(self):
+ return self.location._get_geo_town()
@property
def start_division_number(self):