Sets default values for month/year at Usage Form in overview page

Fixes bug 931227. The problem is with using 'initial' values for
a bound form. These are mutually exclusive.
Another solution is to use only unbound form,
with setting:
	forms.DateForm(initial={'month':
		self.request.GET.get('month', self.today.month,..)
but in that case all further validations for the form
will be disregarded(although there is no validation atm)

Change-Id: Ie4565b03a1414a0008abfd793d9ec4a181e0aa24
This commit is contained in:
Tihomir Trifonov
2012-02-14 12:29:43 +02:00
parent 293c2ee9f7
commit 7e717f3358

View File

@@ -68,9 +68,15 @@ class BaseUsage(object):
def get_form(self):
if not hasattr(self, 'form'):
self.form = forms.DateForm(self.request.GET,
initial={'year': self.today.year,
'month': self.today.month})
if (any(key in ['month', 'year']
for key in self.request.GET.keys())):
# bound form
self.form = forms.DateForm(self.request.GET)
else:
# non-bound form
self.form = forms.DateForm(initial={
'month': self.today.month,
'year': self.today.year})
return self.form
def get_usage_list(self, start, end):