summaryrefslogtreecommitdiff
path: root/archaeological_context_records
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-06-13 12:50:39 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-06-13 12:50:39 +0200
commit87b95ae2f964f70993c490662017b227f0bef792 (patch)
tree780e7ef58503aa5b9fc8cf75d3d9e83c867b8935 /archaeological_context_records
parenteb030fbecd62326b61e8669c34dbae9cb4770cfe (diff)
downloadIshtar-87b95ae2f964f70993c490662017b227f0bef792.tar.bz2
Ishtar-87b95ae2f964f70993c490662017b227f0bef792.zip
🐛 operation/context record forms: filter site fields (refs #5873, #5874)
Diffstat (limited to 'archaeological_context_records')
-rw-r--r--archaeological_context_records/forms.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py
index 162c22f40..698484f50 100644
--- a/archaeological_context_records/forms.py
+++ b/archaeological_context_records/forms.py
@@ -27,7 +27,7 @@ from django import forms
from django.conf import settings
from django.core import validators
from django.forms.formsets import formset_factory
-from ishtar_common.utils import ugettext_lazy as _
+from ishtar_common.utils import get_current_profile, ugettext_lazy as _
from ishtar_common.models import (
valid_id,
@@ -188,7 +188,9 @@ class RecordSelect(GeoItemSelect, PeriodSelect):
SITE_KEYS = {"archaeological_site": None}
def __init__(self, *args, **kwargs):
- super(RecordSelect, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
+ if not get_current_profile().archaeological_site:
+ self._remove_fields(("archaeological_site",))
self._reorder_period_fields("unit")
def get_input_ids(self):
@@ -399,25 +401,27 @@ class RecordFormGeneral(CustomForm, ManageOldType):
kwargs["data"] = None
if "files" in kwargs:
kwargs.pop("files")
- super(RecordFormGeneral, self).__init__(*args, **kwargs)
- profile = IshtarSiteProfile.get_current_profile()
+ super().__init__(*args, **kwargs)
+ profile = get_current_profile()
self.fields["parcel"].choices = [("", "--")]
if not profile.parcel_mandatory:
self.fields["parcel"].required = False
self.fields["town"].choices = [("", "--")]
else:
self._remove_fields(("town",))
-
- site_label = IshtarSiteProfile.get_default_site_label()
- self.fields["archaeological_site"].label = site_label
- self.fields["archaeological_site"].choices = [("", "--")]
+ sites = []
+ if operation:
+ sites = [(site.pk, str(site)) for site in operation.archaeological_sites.all()]
+ if not sites or not profile.archaeological_site:
+ self._remove_fields(("archaeological_site",))
+ else:
+ site_label = IshtarSiteProfile.get_default_site_label()
+ self.fields["archaeological_site"].label = site_label
+ self.fields["archaeological_site"].choices = [("", "--")] + sites
if operation:
self.fields["operation_id"].initial = operation.pk
get_init_parcel(self, operation)
- self.fields["archaeological_site"].choices += [
- (site.pk, str(site)) for site in operation.archaeological_sites.all()
- ]
def clean(self):
# manage unique context record ID