Skip to content

Commit

Permalink
Code cleanup PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgaspar committed Jun 21, 2017
1 parent 6f7429b commit 3a2ea98
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 60 deletions.
1 change: 0 additions & 1 deletion flask_appbuilder/babel/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from flask import session, has_request_context
from flask_babel import Babel
from ..basemanager import BaseManager
from .. import translations
from .views import LocaleView


Expand Down
75 changes: 32 additions & 43 deletions flask_appbuilder/charts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ class BaseChartView(BaseModelView):
group_bys = {}
""" New for 0.6.4, on test, don't use yet """


def __init__(self, **kwargs):
self._init_titles()
super(BaseChartView, self).__init__(**kwargs)


def _init_titles(self):
self.title = self.chart_title

Expand All @@ -67,7 +65,6 @@ def _get_view_widget(self, **kwargs):


class GroupByChartView(BaseChartView):

definitions = []
"""
These charts can display multiple series,
Expand Down Expand Up @@ -135,8 +132,6 @@ def __init__(self, **kwargs):
else:
self.label_columns[serie] = self._prettify_column(serie)



def get_group_by_class(self, definition):
"""
intantiates the processing class (Direct or Grouped) and returns it.
Expand All @@ -149,7 +144,6 @@ def get_group_by_class(self, definition):
formatter = {}
return self.ProcessClass([group_by], series, formatter)


def _get_chart_widget(self, filters=None,
order_column='',
order_direction='',
Expand Down Expand Up @@ -180,7 +174,7 @@ def _get_chart_widget(self, filters=None,
height=height,
value_columns=value_columns,
modelview_name=self.__class__.__name__,
**args)
**args)
return widgets

@expose('/chart/<group_by>')
Expand All @@ -197,13 +191,13 @@ def chart(self, group_by=0):
widgets = self._get_search_widget(form=form, widgets=widgets)
self.update_redirect()
return self.render_template(self.chart_template, route_base=self.route_base,
title=self.chart_title,
label_columns=self.label_columns,
definitions=self.definitions,
group_by_label=self.group_by_label,
height=self.height,
widgets=widgets,
appbuilder=self.appbuilder)
title=self.chart_title,
label_columns=self.label_columns,
definitions=self.definitions,
group_by_label=self.group_by_label,
height=self.height,
widgets=widgets,
appbuilder=self.appbuilder)


class DirectByChartView(GroupByChartView):
Expand Down Expand Up @@ -252,9 +246,9 @@ class CountryDirectChartView(DirectByChartView):
ProcessClass = DirectProcessData


#-------------------------------------------------------
# -------------------------------------------------------
# DEPRECATED SECTION
#-------------------------------------------------------
# -------------------------------------------------------

class BaseSimpleGroupByChartView(BaseChartView):
group_by_columns = []
Expand Down Expand Up @@ -286,7 +280,7 @@ def _get_chart_widget(self, filters=None,
chart_3d=self.chart_3d,
height=height,
value_columns=value_columns,
modelview_name = self.__class__.__name__,
modelview_name=self.__class__.__name__,
**args)
return widgets

Expand All @@ -305,7 +299,6 @@ def __init__(self, **kwargs):
else:
super(BaseSimpleDirectChartView, self).__init__(**kwargs)


def get_group_by_columns(self):
"""
returns the keys from direct_columns
Expand Down Expand Up @@ -336,7 +329,7 @@ def _get_chart_widget(self, filters=None,
chart_3d=self.chart_3d,
height=height,
value_columns=value_columns,
modelview_name = self.__class__.__name__,
modelview_name=self.__class__.__name__,
**args)
return widgets

Expand All @@ -362,13 +355,13 @@ def chart(self, group_by=''):
widgets = self._get_chart_widget(filters=self._filters, group_by=group_by)
widgets = self._get_search_widget(form=form, widgets=widgets)
return self.render_template(self.chart_template, route_base=self.route_base,
title=self.chart_title,
label_columns=self.label_columns,
group_by_columns=self.group_by_columns,
group_by_label=self.group_by_label,
height=self.height,
widgets=widgets,
appbuilder=self.appbuilder)
title=self.chart_title,
label_columns=self.label_columns,
group_by_columns=self.group_by_columns,
group_by_label=self.group_by_label,
height=self.height,
widgets=widgets,
appbuilder=self.appbuilder)


class TimeChartView(BaseSimpleGroupByChartView):
Expand All @@ -383,7 +376,6 @@ class TimeChartView(BaseSimpleGroupByChartView):
chart_template = 'appbuilder/general/charts/chart_time.html'
chart_type = 'ColumnChart'


def _get_chart_widget(self, filters=None,
order_column='',
order_direction='',
Expand Down Expand Up @@ -413,7 +405,6 @@ def _get_chart_widget(self, filters=None,
**args)
return widgets


@expose('/chart/<group_by>/<period>')
@expose('/chart/')
@has_access
Expand All @@ -430,12 +421,12 @@ def chart(self, group_by='', period=''):

widgets = self._get_search_widget(form=form, widgets=widgets)
return self.render_template(self.chart_template, route_base=self.route_base,
title=self.chart_title,
label_columns=self.label_columns,
group_by_columns=self.group_by_columns,
group_by_label=self.group_by_label,
widgets=widgets,
appbuilder=self.appbuilder)
title=self.chart_title,
label_columns=self.label_columns,
group_by_columns=self.group_by_columns,
group_by_label=self.group_by_label,
widgets=widgets,
appbuilder=self.appbuilder)


class DirectChartView(BaseSimpleDirectChartView):
Expand Down Expand Up @@ -479,12 +470,10 @@ def chart(self, group_by=''):
direct=direct)
widgets = self._get_search_widget(form=form, widgets=widgets)
return self.render_template(self.chart_template, route_base=self.route_base,
title=self.chart_title,
label_columns=self.label_columns,
group_by_columns=self.get_group_by_columns(),
group_by_label=self.group_by_label,
height=self.height,
widgets=widgets,
appbuilder=self.appbuilder)


title=self.chart_title,
label_columns=self.label_columns,
group_by_columns=self.get_group_by_columns(),
group_by_label=self.group_by_label,
height=self.height,
widgets=widgets,
appbuilder=self.appbuilder)
15 changes: 8 additions & 7 deletions flask_appbuilder/models/decorators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def renders(col_name):
"""
"""
Use this decorator to map your custom Model properties to actual
Model db properties. As an example::
Expand All @@ -18,9 +18,10 @@ class MyModelView(ModelView):
list_columns = ['name', 'my_custom']
"""
def wrap(f):
if not hasattr(f, '_col_name'):
f._col_name = col_name
return f
return wrap


def wrap(f):
if not hasattr(f, '_col_name'):
f._col_name = col_name
return f

return wrap
1 change: 1 addition & 0 deletions flask_appbuilder/models/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

log = logging.getLogger(__name__)


class BaseFilter(object):
"""
Base class for all data filters.
Expand Down
5 changes: 2 additions & 3 deletions flask_appbuilder/models/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

log = logging.getLogger(__name__)


def aggregate(label=''):
"""
Use this decorator to set a label for your aggregation functions on charts.
Expand Down Expand Up @@ -39,6 +40,7 @@ def aggregate_sum(items, col):
"""
return sum(getattr(item, col) for item in items)


@aggregate(_('Avg. of'))
def aggregate_avg(items, col):
"""
Expand Down Expand Up @@ -113,7 +115,6 @@ def _apply(self, data):
{"c": [{"v": self.get_format_group_col(grouped)}, {"v": aggregate_value}]})
return json_data


def apply(self, data):
data = sorted(data, key=self.get_group_col)
return [
Expand Down Expand Up @@ -232,8 +233,6 @@ def to_dict(self, data):
ret.append(row)
return ret



def to_json(self, data, labels=None):
"""
Will return a dict with Google JSON structure for charts
Expand Down
11 changes: 5 additions & 6 deletions flask_appbuilder/models/mixins.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import datetime
import logging

from sqlalchemy import Column, Integer, ForeignKey, DateTime, String, Boolean
from sqlalchemy.orm import relationship, backref, remote
from sqlalchemy import Column, Integer, ForeignKey, DateTime
from sqlalchemy.orm import relationship
import sqlalchemy.types as types
from sqlalchemy.ext.declarative import declared_attr
from .._compat import as_unicode

from flask import g


log = logging.getLogger(__name__)


Expand All @@ -31,7 +29,7 @@ def __init__(self, thumbnail_size=(20, 20, True), size=(100, 100, True), **kw):
types.TypeDecorator.__init__(self, **kw)
self.thumbnail_size = thumbnail_size
self.size = size


class AuditMixin(object):
"""
Expand Down Expand Up @@ -87,6 +85,7 @@ def id(cls):
"""
This is for retro compatibility
"""


class BaseMixin(object):
pass

0 comments on commit 3a2ea98

Please sign in to comment.