Miscellaneous style fixes spotted by landscape (#874)

This commit is contained in:
Riccardo Magliocchetti 2016-08-05 00:30:33 +02:00 committed by Maxime Beauchemin
parent 82a8e6316f
commit 7c810dbd20
7 changed files with 12 additions and 16 deletions

View File

@ -24,9 +24,9 @@ CONFIG_MODULE = os.environ.get('CARAVEL_CONFIG', 'caravel.config')
app = Flask(__name__) app = Flask(__name__)
app.config.from_object(CONFIG_MODULE) app.config.from_object(CONFIG_MODULE)
if not app.debug: if not app.debug:
# In production mode, add log handler to sys.stderr. # In production mode, add log handler to sys.stderr.
app.logger.addHandler(logging.StreamHandler()) app.logger.addHandler(logging.StreamHandler())
app.logger.setLevel(logging.INFO) app.logger.setLevel(logging.INFO)
db = SQLA(app) db = SQLA(app)

View File

@ -37,7 +37,7 @@ SECRET_KEY = '\2\1thisismyscretkey\1\2\e\y\y\h' # noqa
SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/caravel.db' SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/caravel.db'
# this is for platform specific: "nt" is for windows, "posix" is *nix (including Mac) # this is for platform specific: "nt" is for windows, "posix" is *nix (including Mac)
if os.name == "nt": if os.name == "nt":
SQLALCHEMY_DATABASE_URI = 'sqlite:///c:\\tmp\\caravel.db' SQLALCHEMY_DATABASE_URI = 'sqlite:///c:\\tmp\\caravel.db'
# SQLALCHEMY_DATABASE_URI = 'mysql://myapp@localhost/myapp' # SQLALCHEMY_DATABASE_URI = 'mysql://myapp@localhost/myapp'
# SQLALCHEMY_DATABASE_URI = 'postgresql://root:password@localhost/myapp' # SQLALCHEMY_DATABASE_URI = 'postgresql://root:password@localhost/myapp'

View File

@ -310,7 +310,7 @@ class FormFactory(object):
"description": _("Columns to display") "description": _("Columns to display")
}), }),
'druid_time_origin': (FreeFormSelectField, { 'druid_time_origin': (FreeFormSelectField, {
"label": _( "Origin"), "label": _("Origin"),
"choices": ( "choices": (
('', _('default')), ('', _('default')),
('now', _('now')), ('now', _('now')),

View File

@ -11,7 +11,7 @@ revision = '1226819ee0e3'
down_revision = '956a063c52b3' down_revision = '956a063c52b3'
from alembic import op from alembic import op
from caravel import db, models from caravel import db
from caravel.utils import generic_find_constraint_name from caravel.utils import generic_find_constraint_name
import logging import logging

View File

@ -362,7 +362,6 @@ class Queryable(object):
return "/caravel/explore/{obj.type}/{obj.id}/".format(obj=self) return "/caravel/explore/{obj.type}/{obj.id}/".format(obj=self)
class Database(Model, AuditMixinNullable): class Database(Model, AuditMixinNullable):
"""An ORM object that stores Database related information""" """An ORM object that stores Database related information"""
@ -536,7 +535,6 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
'database_id', 'schema', 'table_name', 'database_id', 'schema', 'table_name',
name='_customer_location_uc'),) name='_customer_location_uc'),)
def __repr__(self): def __repr__(self):
return self.table_name return self.table_name
@ -743,7 +741,7 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
qry = qry.limit(row_limit) qry = qry.limit(row_limit)
if timeseries_limit and groupby: if timeseries_limit and groupby:
# some sql dialects require for order by expressions # some sql dialects require for order by expressions
# to also be in the select clause # to also be in the select clause
inner_select_exprs += [main_metric_expr] inner_select_exprs += [main_metric_expr]
subq = select(inner_select_exprs) subq = select(inner_select_exprs)
@ -765,7 +763,7 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
sql = "{}".format( sql = "{}".format(
qry.compile( qry.compile(
engine, compile_kwargs={"literal_binds": True},), engine, compile_kwargs={"literal_binds": True},),
) )
df = pd.read_sql_query( df = pd.read_sql_query(
sql=sql, sql=sql,
con=engine con=engine
@ -1125,7 +1123,7 @@ class DruidDatasource(Model, AuditMixinNullable, Queryable):
def int_or_0(v): def int_or_0(v):
try: try:
v = int(v) v = int(v)
except Exception as e: except (TypeError, ValueError):
v = 0 v = 0
return v return v
v1nums = [int_or_0(n) for n in v1.split('.')] v1nums = [int_or_0(n) for n in v1.split('.')]
@ -1282,7 +1280,7 @@ class DruidDatasource(Model, AuditMixinNullable, Queryable):
if rejected_metrics: if rejected_metrics:
raise MetricPermException( raise MetricPermException(
"Access to the metrics denied: " + ', '.join(rejected_metrics) "Access to the metrics denied: " + ', '.join(rejected_metrics)
) )
granularity = granularity or "all" granularity = granularity or "all"
if granularity != "all": if granularity != "all":

View File

@ -10,7 +10,6 @@ import functools
import json import json
import logging import logging
import numpy import numpy
import time
import parsedatetime import parsedatetime
import sqlalchemy as sa import sqlalchemy as sa
@ -300,7 +299,7 @@ def json_iso_dttm_ser(obj):
obj = obj.isoformat() obj = obj.isoformat()
else: else:
raise TypeError( raise TypeError(
"Unserializable object {} of type {}".format(obj, type(obj)) "Unserializable object {} of type {}".format(obj, type(obj))
) )
return obj return obj
@ -314,7 +313,7 @@ def json_int_dttm_ser(obj):
obj = (obj - EPOCH).total_seconds() * 1000 obj = (obj - EPOCH).total_seconds() * 1000
else: else:
raise TypeError( raise TypeError(
"Unserializable object {} of type {}".format(obj, type(obj)) "Unserializable object {} of type {}".format(obj, type(obj))
) )
return obj return obj

View File

@ -1331,7 +1331,6 @@ class Caravel(BaseCaravelView):
} }
return json.dumps(data, default=utils.json_int_dttm_ser, allow_nan=False) return json.dumps(data, default=utils.json_int_dttm_ser, allow_nan=False)
@has_access @has_access
@expose("/refresh_datasources/") @expose("/refresh_datasources/")
def refresh_datasources(self): def refresh_datasources(self):