From 06bcf48bb8c27aafeda817ccc63d1e4961a7174e Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 27 Oct 2015 03:03:51 +0100 Subject: Archaeological files forms: automatically manage instruction date --- archaeological_files_pdl/forms.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'archaeological_files_pdl/forms.py') diff --git a/archaeological_files_pdl/forms.py b/archaeological_files_pdl/forms.py index f71bf6a8a..fab2b982b 100644 --- a/archaeological_files_pdl/forms.py +++ b/archaeological_files_pdl/forms.py @@ -317,6 +317,12 @@ class FileFormInstruction(forms.Form): c_year = datetime.date.today().year if 'year' in kwargs: c_year = kwargs.pop('year') + saisine_type = None + if 'saisine_type' in kwargs: + saisine_type = kwargs.pop('saisine_type') + reception_date = None + if 'reception_date' in kwargs: + reception_date = kwargs.pop('reception_date') if 'data' in kwargs and kwargs['data']: kwargs['data'][kwargs.get('prefix', '') + '-year'] = c_year @@ -335,6 +341,17 @@ class FileFormInstruction(forms.Form): self.fields['numeric_reference'].initial = c_num + 1 if self.numeric_reference_is_readonly: self.fields['numeric_reference'].widget.attrs['readonly'] = True + if reception_date and saisine_type: + if type(reception_date) in (unicode, str): + try: + reception_date = datetime.datetime.strptime( + reception_date, '%d/%m/%Y') + self.fields['instruction_deadline'].initial = \ + (reception_date + datetime.timedelta( + days=saisine_type.delay or 0) + ).strftime('%Y-%m-%d') + except ValueError: + pass def clean_numeric_reference(self): if self.numeric_reference_is_readonly: -- cgit v1.2.3