From 7e717f3358619327afd7dda9908390f0d535cf0b Mon Sep 17 00:00:00 2001 From: Tihomir Trifonov Date: Tue, 14 Feb 2012 12:29:43 +0200 Subject: [PATCH] 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 --- horizon/horizon/usage/base.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/horizon/horizon/usage/base.py b/horizon/horizon/usage/base.py index c569e3686b4..43c561b51ab 100644 --- a/horizon/horizon/usage/base.py +++ b/horizon/horizon/usage/base.py @@ -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):