diff options
Diffstat (limited to 'ishtar/furnitures/forms_operations.py')
-rw-r--r-- | ishtar/furnitures/forms_operations.py | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/ishtar/furnitures/forms_operations.py b/ishtar/furnitures/forms_operations.py index 17fd8f69d..3c2dbd734 100644 --- a/ishtar/furnitures/forms_operations.py +++ b/ishtar/furnitures/forms_operations.py @@ -118,7 +118,6 @@ class OperationWizard(Wizard): year = int(request.session[storage.prefix]['step_data']\ [general_form_key][general_form_key+"-year"]) data[prefix+'-hidden_year'] = year - data[prefix+'-hidden_ope'] = True # manage the dynamic choice of towns if step.startswith('towns-') and hasattr(form, 'management_form'): data['TOWNS'] = self.get_towns(request, storage) @@ -158,13 +157,11 @@ class OperationWizard(Wizard): def get_form_initial(self, request, storage, step): initial = super(OperationWizard, self).get_form_initial(request, storage, step) - if initial: - return initial # put hidden year and default operation_code field for refs general_form_key = 'general-' + self.url_name - initial = {} if step.startswith('refs-') \ - and self.session_has_key(request, storage, general_form_key): + and self.session_has_key(request, storage, general_form_key)\ + and 'operation_code' not in initial: year = int(request.session[storage.prefix]['step_data']\ [general_form_key][general_form_key+"-year"]) initial['hidden_year'] = year @@ -258,23 +255,24 @@ class OperationFormReference(forms.Form): 'associated_file':models.File, 'operation_type':models.OperationType} currents = {'associated_file':models.File} + pk = forms.IntegerField(required=False, widget=forms.HiddenInput) hidden_year = forms.IntegerField(widget=forms.HiddenInput) - hidden_ope = forms.BooleanField(widget=forms.HiddenInput, required=False) operation_code = forms.IntegerField(label=_(u"Operation code")) if settings.COUNTRY == 'fr': code_patriarche = forms.IntegerField(label=u"Code PATRIARCHE", required=False) code_dracar = forms.CharField(label=u"Code DRACAR", required=False, validators=[validators.MaxLengthValidator(10)]) + def clean(self): cleaned_data = self.cleaned_data - if 'hidden_ope' in cleaned_data and cleaned_data['hidden_ope']: - return cleaned_data year = cleaned_data.get("hidden_year") operation_code = cleaned_data.get("operation_code") ops = models.Operation.objects.filter(year=year, - operation_code=operation_code).count() - if ops: + operation_code=operation_code) + if 'pk' in cleaned_data and cleaned_data['pk']: + ops = ops.exclude(pk=cleaned_data['pk']) + if ops.count(): max_val = models.Operation.objects.filter(year=year).aggregate( Max('operation_code'))["operation_code__max"] raise forms.ValidationError(_(u"Operation code already exist for " |