diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2015-10-27 03:03:51 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2015-10-27 03:03:51 +0100 |
commit | 06bcf48bb8c27aafeda817ccc63d1e4961a7174e (patch) | |
tree | 4d50ee8b814c84069bab176d043ddd4a888451bb /archaeological_files_pdl/forms.py | |
parent | dd633b6452d4ffacb850de227d847188ab5877bb (diff) | |
download | Ishtar-06bcf48bb8c27aafeda817ccc63d1e4961a7174e.tar.bz2 Ishtar-06bcf48bb8c27aafeda817ccc63d1e4961a7174e.zip |
Archaeological files forms: automatically manage instruction date
Diffstat (limited to 'archaeological_files_pdl/forms.py')
-rw-r--r-- | archaeological_files_pdl/forms.py | 17 |
1 files changed, 17 insertions, 0 deletions
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: |