Skip to content

Commit

Permalink
Done fixing form continuity
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Sep 30, 2015
1 parent 74e5a3e commit 5cf5019
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions panoramix/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self, viz):
description="One or many metrics to display"),
'metric': SelectField(
'Metric', choices=datasource.metrics_combo,
default='',
description="One or many metrics to display"),
'groupby': SelectMultipleField(
'Group by',
Expand Down
24 changes: 15 additions & 9 deletions panoramix/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ class BaseViz(object):
css_files = []

def __init__(self, datasource, form_data):
self.orig_form_data = form_data
self.datasource = datasource
self.request = request
self.viz_type = form_data.get("viz_type")

ff = FormFactory(self)
form_class = ff.get_form()
Expand All @@ -39,27 +41,21 @@ def __init__(self, datasource, form_data):
form = form_class(**form_data)
data = form.data.copy()
previous_viz_type = form_data.get('previous_viz_type')
if previous_viz_type in viz_types:
if previous_viz_type in viz_types and previous_viz_type != self.viz_type:
data = {
k: form.data[k]
for k in form_data.keys()
if k in viz_types[previous_viz_type].flat_form_fields() and k in form.data}
defaults.update(data)
self.form_data = defaults

self.form_data['previous_viz_type'] = form_data.get("viz_type")
self.form_data['previous_viz_type'] = self.viz_type
self.token = self.form_data.get(
'token', 'token_' + uuid.uuid4().hex[:8])

as_list = ('metrics', 'groupby')
for k, v in self.form_data.items():
if k in as_list and not isinstance(v, list):
self.form_data[k] = [v]
elif k not in as_list and isinstance(v, list) and v:
self.form_data[k] = v[0]

self.metrics = self.form_data.get('metrics') or []
self.groupby = self.form_data.get('groupby') or []
self.reassignments()

@classmethod
def flat_form_fields(cls):
Expand All @@ -71,6 +67,9 @@ def flat_form_fields(cls):
l.append(obj)
return l

def reassignments(self):
pass

def get_url(self, **kwargs):
d = self.form_data.copy()
if 'action' in d:
Expand Down Expand Up @@ -311,12 +310,19 @@ class BigNumberViz(BaseViz):
#('rolling_type', 'rolling_periods'),
]

def reassignments(self):
metric = self.form_data.get('metric')
if not metric:
self.form_data['metric'] = self.orig_form_data.get('metrics')


def query_obj(self):
d = super(BigNumberViz, self).query_obj()
metric = self.form_data.get('metric')
if not metric:
raise Exception("Pick a metric!")
d['metrics'] = [self.form_data.get('metric')]
self.form_data['metric'] = metric
return d

def get_json(self):
Expand Down

0 comments on commit 5cf5019

Please sign in to comment.