diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-10-28 14:13:31 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-10-28 14:13:31 +0200 |
commit | 516a0a55be0a5dd4b3d1849ab5b7e150be1c9d7f (patch) | |
tree | 2c527257e8df950c22520da165c35935185ece22 /archaeological_files/forms.py | |
parent | 606e7a781722b671f98135f72149f7b290f320bd (diff) | |
download | Ishtar-516a0a55be0a5dd4b3d1849ab5b7e150be1c9d7f.tar.bz2 Ishtar-516a0a55be0a5dd4b3d1849ab5b7e150be1c9d7f.zip |
Use lazy model evaluation for fixed type constraints
Diffstat (limited to 'archaeological_files/forms.py')
-rw-r--r-- | archaeological_files/forms.py | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py index 26b839940..04badfc10 100644 --- a/archaeological_files/forms.py +++ b/archaeological_files/forms.py @@ -29,7 +29,8 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.safestring import mark_safe from ishtar_common.models import Person, PersonType, Organization, \ - OrganizationType, valid_id, Department + OrganizationType, valid_id, Department, person_type_pks_lazy, \ + person_type_pk_lazy, organization_type_pk_lazy, organization_type_pks_lazy from archaeological_operations.models import ActType, AdministrativeAct, \ OperationType import models @@ -38,15 +39,9 @@ from ishtar_common.forms import FinalForm, get_now, reverse_lazy, TableSelect, \ from ishtar_common.forms_common import get_town_field from archaeological_operations.forms import AdministrativeActOpeForm, \ AdministrativeActOpeFormSelection, \ - ParcelField, SLICING, HEAD_SCIENTIST, SRA_AGENT, AdministrativeActModifForm + ParcelField, SLICING, AdministrativeActModifForm from ishtar_common import widgets -GENERAL_CONTRACTOR, created = PersonType.objects.get_or_create( - txt_idx='general_contractor') - -GENERAL_CONTRACTOR_ORGA, created = OrganizationType.objects.get_or_create( - txt_idx='general_contractor') - class FileSelect(TableSelect): year = forms.IntegerField(label=_("Year")) @@ -70,21 +65,22 @@ class FileSelect(TableSelect): label=_(u"In charge"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-person', - args=[SRA_AGENT.pk]), + args=[person_type_pk_lazy('sra_agent')]), associated_model=Person), validators=[valid_id(Person)]) general_contractor = forms.IntegerField( label=_(u"General contractor"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-person', - args=[GENERAL_CONTRACTOR.pk]), + args=[person_type_pk_lazy('general_contractor')]), associated_model=Person), validators=[valid_id(Person)]) general_contractor__attached_to = forms.IntegerField( label=_(u"Organization of general contractor"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-organization', - args=[GENERAL_CONTRACTOR_ORGA.pk]), + args=[organization_type_pks_lazy([ + 'general_contractor'])]), associated_model=Organization), validators=[valid_id(Organization)]) history_creator = forms.IntegerField( @@ -205,8 +201,10 @@ class FileFormGeneral(ManageOldType, forms.Form): in_charge = forms.IntegerField( label=_("Person in charge"), widget=widgets.JQueryAutoComplete( - reverse_lazy('autocomplete-person', args=[SRA_AGENT.pk]), - limit={'person_types': [SRA_AGENT.pk]}, + reverse_lazy('autocomplete-person', args=[ + person_type_pks_lazy(['sra_agent'])]), + limit={'person_types': [ + person_type_pk_lazy('sra_agent')]}, associated_model=Person, new=True), validators=[valid_id(Person)]) year = forms.IntegerField(label=_("Year"), @@ -272,12 +270,6 @@ class FileFormGeneralRO(FileFormGeneral): _(u"Another file with this numeric id exists.")) return cleaned_data -RESPONSIBLE_PLANNING_SERVICE, created = PersonType.objects.get_or_create( - txt_idx='responsible_planning_service') - -RESPONSIBLE_PLANNING_SERVICE_ORGA, created = \ - OrganizationType.objects.get_or_create(txt_idx='planning_service') - class FileFormPreventive(ManageOldType, forms.Form): form_label = _(u"Preventive informations") @@ -290,10 +282,10 @@ class FileFormPreventive(ManageOldType, forms.Form): widget=widgets.JQueryAutoComplete( reverse_lazy( 'autocomplete-person', - args=[PersonType.objects.get(txt_idx='general_contractor').pk] + args=[person_type_pks_lazy(['general_contractor'])] ), limit={'person_types': [ - PersonType.objects.get(txt_idx='general_contractor').pk]}, + person_type_pk_lazy('general_contractor')]}, associated_model=Person, new=True), validators=[valid_id(Person)]) responsible_town_planning_service = forms.IntegerField( @@ -302,10 +294,11 @@ class FileFormPreventive(ManageOldType, forms.Form): widget=widgets.JQueryAutoComplete( reverse_lazy( 'autocomplete-person', - args=[RESPONSIBLE_PLANNING_SERVICE.pk] + args=[person_type_pks_lazy(['responsible_planning_service'])] ), limit={'person_types': [ - RESPONSIBLE_PLANNING_SERVICE.pk]}, + person_type_pk_lazy('responsible_planning_service') + ]}, associated_model=Person, new=True), validators=[valid_id(Person)]) permit_type = forms.ChoiceField(label=_(u"Permit type"), required=False, @@ -351,10 +344,9 @@ class FileFormResearch(ManageOldType, forms.Form): widget=widgets.JQueryAutoComplete( reverse_lazy( 'autocomplete-person', - args=["_".join([unicode(HEAD_SCIENTIST.pk), - unicode(SRA_AGENT.pk)])]), - limit={'person_types': [unicode(HEAD_SCIENTIST.pk), - unicode(SRA_AGENT.pk)]}, + args=[person_type_pks_lazy(['head_scientist', 'sra_agent'])]), + limit={'person_types': [person_type_pk_lazy('head_scientist'), + person_type_pk_lazy('sra_agent')]}, associated_model=Person, new=True), label=_(u"Scientist in charge")) requested_operation_type = forms.ChoiceField( @@ -454,8 +446,7 @@ class AdministrativeActFileSelect(TableSelect): widget=widgets.JQueryAutoComplete( reverse_lazy( 'autocomplete-person', - args=[ - PersonType.objects.get(txt_idx='general_contractor').pk]), + args=[person_type_pk_lazy('general_contractor')]), associated_model=Person), validators=[valid_id(Person)]) associated_file__general_contractor__attached_to = forms.IntegerField( @@ -463,7 +454,7 @@ class AdministrativeActFileSelect(TableSelect): widget=widgets.JQueryAutoComplete( reverse_lazy( 'autocomplete-organization', - args=[GENERAL_CONTRACTOR_ORGA.pk]), + args=[organization_type_pks_lazy(['general_contractor'])]), associated_model=Organization), validators=[valid_id(Organization)]) associated_file__numeric_reference = forms.IntegerField( @@ -476,7 +467,7 @@ class AdministrativeActFileSelect(TableSelect): widget=widgets.JQueryAutoComplete( reverse_lazy( 'autocomplete-person', - args=[SRA_AGENT.pk]), + args=[person_type_pk_lazy('sra_agent')]), associated_model=Person), validators=[valid_id(Person)]) associated_file__permit_reference = forms.CharField( |