Skip to content

Commit

Permalink
Sets default values for month/year at Usage Form in overview page
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ttrifonov committed Feb 14, 2012
1 parent 293c2ee commit 7e717f3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions horizon/horizon/usage/base.py
Expand Up @@ -68,9 +68,15 @@ def get_date_range(self):

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):
Expand Down

0 comments on commit 7e717f3

Please sign in to comment.