summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2020-12-02 12:57:43 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2020-12-02 12:57:43 +0100
commit4d1cd90d409a6f3d2fc86194336743db43d1c089 (patch)
treec8d3a53e5e3fa5d0ac63596a6788878674c1f80b
parent6d827d5c8448c761ec3c8475d5c67531e32911f2 (diff)
downloadIshtar-4d1cd90d409a6f3d2fc86194336743db43d1c089.tar.bz2
Ishtar-4d1cd90d409a6f3d2fc86194336743db43d1c089.zip
Archaeological files: fix default labels
-rw-r--r--archaeological_files_pdl/forms.py16
-rw-r--r--ishtar_common/models.py8
2 files changed, 16 insertions, 8 deletions
diff --git a/archaeological_files_pdl/forms.py b/archaeological_files_pdl/forms.py
index 7ada27be8..9974c184a 100644
--- a/archaeological_files_pdl/forms.py
+++ b/archaeological_files_pdl/forms.py
@@ -21,6 +21,7 @@ import datetime
from django import forms
from django.core import validators
+from django.utils.functional import lazy
from django.utils.safestring import mark_safe
from ishtar_common.utils import ugettext_lazy as _
@@ -266,7 +267,7 @@ class FileFormGeneralContractor(CustomForm, ManageOldType):
organization_type_pk_lazy('general_contractor')
]
},
- tips=get_orga_general_contractor_label,
+ tips=lazy(get_orga_general_contractor_label),
associated_model=models.Organization, new=True,
detail=True,
modify=True
@@ -284,7 +285,7 @@ class FileFormGeneralContractor(CustomForm, ManageOldType):
limit={'person_types': [
person_type_pk_lazy('general_contractor')
]},
- tips=get_general_contractor_label,
+ tips=lazy(get_general_contractor_label),
detail=True,
modify=True,
new=True),
@@ -300,7 +301,8 @@ class FileFormGeneralContractor(CustomForm, ManageOldType):
person = models.Person.objects.get(pk=general_contractor)
except models.Person.DoesNotExist:
raise forms.ValidationError(_("Non existing person."))
- if person.attached_to.pk != corporation_general_contractor:
+ if not person.attached_to or \
+ person.attached_to.pk != corporation_general_contractor:
raise forms.ValidationError(_(
"The organization of the person in charge differs from the "
"general contractor."))
@@ -327,7 +329,7 @@ class FileFormPlanningService(CustomForm, IshtarForm):
'organization_type':
[organization_type_pk_lazy(['planning_service'])],
},
- tips=get_orga_planning_service_label,
+ tips=lazy(get_orga_planning_service_label),
new=True,
detail=True,
modify=True,
@@ -347,7 +349,7 @@ class FileFormPlanningService(CustomForm, IshtarForm):
person_type_pk_lazy('responsible_planning_service')
]},
dynamic_limit=['planning_service'],
- tips=get_responsible_planning_service_label,
+ tips=lazy(get_responsible_planning_service_label),
detail=True,
modify=True,
new=True),
@@ -364,7 +366,7 @@ class FileFormPlanningService(CustomForm, IshtarForm):
person = models.Person.objects.get(pk=responsible)
except models.Person.DoesNotExist:
raise forms.ValidationError(_("Non existing person."))
- if person.attached_to.pk != orga:
+ if not person.attached_to or person.attached_to.pk != orga:
raise forms.ValidationError(_(
"The organization of the person in charge differs from the "
"planning service."))
@@ -388,7 +390,7 @@ class FileFormInstruction(CustomForm, IshtarForm):
'person_types': [
person_type_pk_lazy('sra_agent')]
},
- tips=get_sra_agent_label,
+ tips=lazy(get_sra_agent_label),
associated_model=Person, new=True,
),
validators=[valid_id(Person)])
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 3e0d061e4..a22a9307f 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -718,7 +718,9 @@ class GeneralType(Cached, models.Model):
item = cls.get_cache(slug)
if item:
return item
- item, created = cls.objects.get_or_create(
+ if isinstance(slug, list):
+ slug = slug[0]
+ item, __ = cls.objects.get_or_create(
txt_idx=slug, defaults={'label': label})
return item
@@ -1040,6 +1042,10 @@ class GeneralType(Cached, models.Model):
def save(self, *args, **kwargs):
if not self.id and not self.label:
+ txt_idx = self.txt_idx
+ if isinstance(txt_idx, list):
+ txt_idx = txt_idx[0]
+ self.txt_idx = txt_idx
self.label = " ".join(" ".join(self.txt_idx.split('-'))
.split('_')).title()
if not self.txt_idx: