From 4e0fa869d575b649c88bc26ce3eb1fd0d23de647 Mon Sep 17 00:00:00 2001 From: "Alexis A." Date: Mon, 18 Nov 2024 23:25:34 +0100 Subject: [PATCH] chore(project): simplify area --- project/models/project_base.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/project/models/project_base.py b/project/models/project_base.py index a4ac3aa90..aa25eebc3 100644 --- a/project/models/project_base.py +++ b/project/models/project_base.py @@ -417,27 +417,17 @@ def get_folder_name(self): @property def area(self) -> float: - """ - The area of the combined emprise of the project in hectare. - As this value should not change after the creation of a project, - we cache it for an arbitrary long time. - """ cache_key = f"project/{self.id}/area" if cache.has_key(cache_key): return cache.get(cache_key) - total_area = 0 - - for emprise in self.emprise_set.all(): - total_area += emprise.mpoly.transform(emprise.srid_source, clone=True).area - - total_area /= 10000 + area = self.land.area ONE_MONTH = 60 * 60 * 24 * 30 - cache.set(key=cache_key, value=total_area, timeout=ONE_MONTH) + cache.set(key=cache_key, value=area, timeout=ONE_MONTH) - return total_area + return area @cached_property def __related_departements(self): @@ -1040,7 +1030,7 @@ def get_base_sol_artif(self, sol: Literal["couverture", "usage"] = "couverture") .annotate(surface=Sum("surface")) ) - @property + @cached_property def land(self) -> Commune | Departement | Epci | Region | Scot: return Land(self.get_public_key()).land