diff options
Diffstat (limited to 'archaeological_operations/forms.py')
| -rw-r--r-- | archaeological_operations/forms.py | 66 | 
1 files changed, 36 insertions, 30 deletions
| diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 3bef38a9c..3c93b945c 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -40,9 +40,10 @@ from bootstrap_datepicker.widgets import DateField  from ishtar_common import widgets  from ishtar_common.forms import FinalForm, FormSet, get_now, \      reverse_lazy, TableSelect, get_data_from_formset, QAForm, CustomFormSearch,\ -    ManageOldType, IshtarForm, CustomForm, FieldType, FormHeader, HistorySelect +    ManageOldType, IshtarForm, CustomForm, FieldType, FormHeader, \ +    HistorySelect, LockForm, MultiSearchForm  from ishtar_common.forms_common import TownFormSet, get_town_field, TownForm -from ishtar_common.models import valid_id, Person, Town, \ +from ishtar_common.models import valid_id, valid_ids, Person, Town, \      DocumentTemplate, Organization, get_current_profile, \      person_type_pks_lazy, person_type_pk_lazy, organization_type_pks_lazy, \      organization_type_pk_lazy, SpatialReferenceSystem, Area @@ -599,7 +600,7 @@ class OperationSelect(HistorySelect):                  ('', '--')] + list(settings.ISHTAR_DPTS) -class OperationFormSelection(CustomFormSearch): +class OperationFormSelection(LockForm, CustomFormSearch):      SEARCH_AND_SELECT = True      form_label = _(u"Operation search")      associated_models = {'pk': models.Operation} @@ -612,19 +613,19 @@ class OperationFormSelection(CustomFormSearch):              source_full=reverse_lazy('get-operation-full')),          validators=[valid_id(models.Operation)]) -    def clean(self): -        cleaned_data = self.cleaned_data -        if 'pk' not in cleaned_data or not cleaned_data['pk']: -            raise forms.ValidationError(_(u"You should select an operation.")) -        pk = self.cleaned_data["pk"] -        try: -            item = models.Operation.objects.get(pk=pk) -        except models.Operation.DoesNotExist: -            raise forms.ValidationError(_("Invalid selection.")) -        if item.locked: -            raise forms.ValidationError(_("This operation is locked for " -                                          "edition.")) -        return self.cleaned_data + +class OperationFormMultiSelection(LockForm, MultiSearchForm): +    form_label = _(u"Operation search") +    associated_models = {'pks': models.Operation} +    pk_key = 'pks' +    pk = forms.CharField( +        label="", required=False, +        widget=widgets.DataTable( +            reverse_lazy('get-operation'), OperationSelect, models.Operation, +            gallery=True, map=True, +            multiple_select=True, +            source_full=reverse_lazy('get-operation-full')), +        validators=[valid_ids(models.Operation)])  class OperationCodeInput(forms.TextInput): @@ -1307,6 +1308,7 @@ ArchaeologicalSiteFormSet.extra_form_modals = ["archaeologicalsite"]  class ArchaeologicalSiteSelectionForm(IshtarForm): +    # TODO: used?      form_label = _("Associated archaeological sites")      archaeological_sites = forms.IntegerField(          widget=widgets.JQueryAutoComplete( @@ -1401,7 +1403,7 @@ class SiteSelect(HistorySelect):              self.fields.pop('drassm_number') -class SiteFormSelection(CustomFormSearch): +class SiteFormSelection(LockForm, CustomFormSearch):      SEARCH_AND_SELECT = True      associated_models = {'pk': models.ArchaeologicalSite}      currents = {'pk': models.ArchaeologicalSite} @@ -1418,19 +1420,23 @@ class SiteFormSelection(CustomFormSearch):      def form_label(cls):          return get_current_profile().get_site_label('search') -    def clean(self): -        cleaned_data = self.cleaned_data -        if 'pk' not in cleaned_data or not cleaned_data['pk']: -            raise forms.ValidationError(_(u"You should select an item.")) -        pk = self.cleaned_data["pk"] -        try: -            item = models.ArchaeologicalSite.objects.get(pk=pk) -        except models.ArchaeologicalSite.DoesNotExist: -            raise forms.ValidationError(_("Invalid selection.")) -        if item.locked: -            raise forms.ValidationError(_("This site is locked for " -                                          "edition.")) -        return self.cleaned_data + +class SiteFormMultiSelection(LockForm, MultiSearchForm): +    associated_models = {'pks': models.ArchaeologicalSite} + +    pk = forms.CharField( +        label="", required=False, +        widget=widgets.DataTable( +            reverse_lazy('get-site'), SiteSelect, +            models.ArchaeologicalSite, +            gallery=True, map=True, +            multiple_select=True, +            source_full=reverse_lazy('get-site-full')), +        validators=[valid_ids(models.ArchaeologicalSite)]) + +    @classmethod +    def form_label(cls): +        return get_current_profile().get_site_label('search')  class SiteForm(CustomForm, ManageOldType): | 
