Arnaud Grausem avatar Arnaud Grausem committed 0fb9a5e

Bug fixed: Initial date never changes in report forms

Comments (0)

Files changed (1)

thot/report/forms.py

     # BASE REPORT FORM FIELDS                                           #
     #####################################################################
     
-    begin_date = forms.DateField(label=_('Date range'), 
-        initial=date.today()+relativedelta(months=-1))
-    end_date = forms.DateField(label=_('to'), initial=date.today())
+    begin_date = forms.DateField(label=_('Date range'))
+    end_date = forms.DateField(label=_('to'))
     detailed = forms.BooleanField(label=_('Detailed report'), 
         initial=False, required=False)
+
+    def __init__(self, *args, **kwargs):
+        super(BaseReportForm, self).__init__(*args, **kwargs)
+        # defines begin date and end date initial data for the form
+        # dynamically for different instance of the form
+        today = date.today()
+        self.fields['begin_date'].initial = today+relativedelta(month=-1)
+        self.fields['end_date'].initial = today
     
     def report_data(self):
         """Returns basic report between two dates
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.