From 435797a54e4d322a46711f303c2fc1fd5286330e Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 10 Oct 2024 13:42:18 +0200 Subject: ✨ site and operation relations forms refactoring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- archaeological_operations/models.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'archaeological_operations/models.py') diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index f8c8f20a0..63904bebe 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -759,18 +759,31 @@ class ArchaeologicalSite( base_finds__context_record__archaeological_site__pk=self.pk ) - def get_extra_actions(self, request): + def get_extra_actions(self, request, window_id=None): """ For sheet template """ # url, base_text, icon, extra_text, extra css class, is a quick action actions = super(ArchaeologicalSite, self).get_extra_actions(request) - # is_locked = self.is_locked(request.user) + is_locked = self.is_locked(request.user) profile = get_current_profile() + can_edit_site = self.can_do(request, "change_archaeologicalsite") can_add_geo = profile.mapping and self.can_do(request, "add_geovectordata") if can_add_geo: actions.append(self.get_add_geo_action()) + if can_edit_site and not is_locked: + actions += [ + ( + reverse("site-operation-relations-modify", args=[self.pk, window_id]), + _("Modify site-operation relations"), + "fa fa-retweet", + _("operations"), + "", + True, + ), + ] + can_create_operation = self.can_do(request, "change_operation") if can_create_operation and not self.operations.count(): actions.append( @@ -796,7 +809,6 @@ class ArchaeologicalSite( ) ) - can_edit_site = self.can_do(request, "change_archaeologicalsite") if can_edit_site: actions += [ ( @@ -2096,7 +2108,7 @@ class Operation( ).distinct("location", "index") return q - def get_extra_actions(self, request): + def get_extra_actions(self, request, window_id=None): """ For sheet template """ @@ -2160,6 +2172,16 @@ class Operation( True, ), ] + actions += [ + ( + reverse("operation-site-relations-modify", args=[self.pk, window_id]), + _("Modify operation-site relations"), + "fa fa-retweet", + profile.get_site_label("plural").lower(), + "", + True, + ), + ] if can_edit_operation: actions += [ -- cgit v1.2.3