From b388aaacb33fc607ee164853e3af262ede9f9745 Mon Sep 17 00:00:00 2001 From: Justin Pomeroy Date: Thu, 25 Sep 2014 15:13:36 -0500 Subject: [PATCH] Persist usage start and end dates in the session This patch adds the usage start and end dates to the user's session so they are saved while navigating between pages. Closes-Bug: #1373651 Change-Id: I3046b5533eb96f85fb2f90e63b3ff84360ad14c4 --- openstack_dashboard/usage/base.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/openstack_dashboard/usage/base.py b/openstack_dashboard/usage/base.py index 90de447563..e516524938 100644 --- a/openstack_dashboard/usage/base.py +++ b/openstack_dashboard/usage/base.py @@ -86,14 +86,21 @@ class BaseUsage(object): def get_form(self): if not hasattr(self, 'form'): - if any(key in ['start', 'end'] for key in self.request.GET): + req = self.request + start = req.GET.get('start', req.session.get('usage_start')) + end = req.GET.get('end', req.session.get('usage_end')) + if start and end: # bound form - self.form = forms.DateForm(self.request.GET) + self.form = forms.DateForm({'start': start, 'end': end}) else: # non-bound form init = self.init_form() - self.form = forms.DateForm(initial={'start': init[0], - 'end': init[1]}) + start = init[0].isoformat() + end = init[1].isoformat() + self.form = forms.DateForm(initial={'start': start, + 'end': end}) + req.session['usage_start'] = start + req.session['usage_end'] = end return self.form def _get_neutron_usage(self, limits, resource_name):