From 7c810dbd20ef394c073ec78c0c46380f471fff4d Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Fri, 5 Aug 2016 00:30:33 +0200 Subject: [PATCH] Miscellaneous style fixes spotted by landscape (#874) --- caravel/__init__.py | 6 +++--- caravel/config.py | 2 +- caravel/forms.py | 2 +- ...26819ee0e3_fix_wrong_constraint_on_table_columns.py | 2 +- caravel/models.py | 10 ++++------ caravel/utils.py | 5 ++--- caravel/views.py | 1 - 7 files changed, 12 insertions(+), 16 deletions(-) diff --git a/caravel/__init__.py b/caravel/__init__.py index 45fa4b71e9c4..b750b99842f5 100644 --- a/caravel/__init__.py +++ b/caravel/__init__.py @@ -24,9 +24,9 @@ app = Flask(__name__) app.config.from_object(CONFIG_MODULE) if not app.debug: - # In production mode, add log handler to sys.stderr. - app.logger.addHandler(logging.StreamHandler()) - app.logger.setLevel(logging.INFO) + # In production mode, add log handler to sys.stderr. + app.logger.addHandler(logging.StreamHandler()) + app.logger.setLevel(logging.INFO) db = SQLA(app) diff --git a/caravel/config.py b/caravel/config.py index 3780ca787a21..79c87d0a9215 100644 --- a/caravel/config.py +++ b/caravel/config.py @@ -37,7 +37,7 @@ SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/caravel.db' # this is for platform specific: "nt" is for windows, "posix" is *nix (including Mac) 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 = 'postgresql://root:password@localhost/myapp' diff --git a/caravel/forms.py b/caravel/forms.py index 6499747b7c67..c06565d23ae7 100755 --- a/caravel/forms.py +++ b/caravel/forms.py @@ -310,7 +310,7 @@ def __init__(self, viz): "description": _("Columns to display") }), 'druid_time_origin': (FreeFormSelectField, { - "label": _( "Origin"), + "label": _("Origin"), "choices": ( ('', _('default')), ('now', _('now')), diff --git a/caravel/migrations/versions/1226819ee0e3_fix_wrong_constraint_on_table_columns.py b/caravel/migrations/versions/1226819ee0e3_fix_wrong_constraint_on_table_columns.py index e5a9d4fe85de..ff7314e15774 100644 --- a/caravel/migrations/versions/1226819ee0e3_fix_wrong_constraint_on_table_columns.py +++ b/caravel/migrations/versions/1226819ee0e3_fix_wrong_constraint_on_table_columns.py @@ -11,7 +11,7 @@ down_revision = '956a063c52b3' from alembic import op -from caravel import db, models +from caravel import db from caravel.utils import generic_find_constraint_name import logging diff --git a/caravel/models.py b/caravel/models.py index 444a4da6b7e1..1a4468009e10 100644 --- a/caravel/models.py +++ b/caravel/models.py @@ -362,7 +362,6 @@ def explore_url(self): return "/caravel/explore/{obj.type}/{obj.id}/".format(obj=self) - class Database(Model, AuditMixinNullable): """An ORM object that stores Database related information""" @@ -536,7 +535,6 @@ class SqlaTable(Model, Queryable, AuditMixinNullable): 'database_id', 'schema', 'table_name', name='_customer_location_uc'),) - def __repr__(self): return self.table_name @@ -743,7 +741,7 @@ def query( # sqla qry = qry.limit(row_limit) 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 inner_select_exprs += [main_metric_expr] subq = select(inner_select_exprs) @@ -765,7 +763,7 @@ def query( # sqla sql = "{}".format( qry.compile( engine, compile_kwargs={"literal_binds": True},), - ) + ) df = pd.read_sql_query( sql=sql, con=engine @@ -1125,7 +1123,7 @@ def version_higher(v1, v2): def int_or_0(v): try: v = int(v) - except Exception as e: + except (TypeError, ValueError): v = 0 return v v1nums = [int_or_0(n) for n in v1.split('.')] @@ -1282,7 +1280,7 @@ def recursive_get_fields(_conf): if rejected_metrics: raise MetricPermException( "Access to the metrics denied: " + ', '.join(rejected_metrics) - ) + ) granularity = granularity or "all" if granularity != "all": diff --git a/caravel/utils.py b/caravel/utils.py index b4296c92eeef..9afdc3961511 100644 --- a/caravel/utils.py +++ b/caravel/utils.py @@ -10,7 +10,6 @@ import json import logging import numpy -import time import parsedatetime import sqlalchemy as sa @@ -300,7 +299,7 @@ def json_iso_dttm_ser(obj): obj = obj.isoformat() else: raise TypeError( - "Unserializable object {} of type {}".format(obj, type(obj)) + "Unserializable object {} of type {}".format(obj, type(obj)) ) return obj @@ -314,7 +313,7 @@ def json_int_dttm_ser(obj): obj = (obj - EPOCH).total_seconds() * 1000 else: raise TypeError( - "Unserializable object {} of type {}".format(obj, type(obj)) + "Unserializable object {} of type {}".format(obj, type(obj)) ) return obj diff --git a/caravel/views.py b/caravel/views.py index db4b3a02ba57..cdb796bcbd03 100755 --- a/caravel/views.py +++ b/caravel/views.py @@ -1331,7 +1331,6 @@ def sql_json(self): } return json.dumps(data, default=utils.json_int_dttm_ser, allow_nan=False) - @has_access @expose("/refresh_datasources/") def refresh_datasources(self):