diff --git a/caravel/__init__.py b/caravel/__init__.py
index c3517f0c29..e424499b74 100644
--- a/caravel/__init__.py
+++ b/caravel/__init__.py
@@ -1,4 +1,8 @@
"""Package's main module!"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
import logging
import os
diff --git a/caravel/ascii_art.py b/caravel/ascii_art.py
index 4804469480..acb41ccf94 100644
--- a/caravel/ascii_art.py
+++ b/caravel/ascii_art.py
@@ -1,3 +1,8 @@
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
error = (
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n"+
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n"+
diff --git a/caravel/bin/caravel b/caravel/bin/caravel
index 5400b94957..5c59c08c7f 100755
--- a/caravel/bin/caravel
+++ b/caravel/bin/caravel
@@ -1,4 +1,8 @@
#!/usr/bin/env python
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
from datetime import datetime
import logging
diff --git a/caravel/config.py b/caravel/config.py
index 01876998da..33d244a97c 100644
--- a/caravel/config.py
+++ b/caravel/config.py
@@ -4,6 +4,11 @@ All configuration in this file can be overridden by providing a local_config
in your PYTHONPATH as there is a ``from local_config import *``
at the end of this file.
"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
import os
from flask_appbuilder.security.manager import AUTH_DB
from dateutil import tz
diff --git a/caravel/data/__init__.py b/caravel/data/__init__.py
index 7d1f069948..43ce7d92cb 100644
--- a/caravel/data/__init__.py
+++ b/caravel/data/__init__.py
@@ -1,4 +1,8 @@
"""Loads datasets, dashboards and slices in a new caravel instance"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
import gzip
import json
diff --git a/caravel/data/countries.py b/caravel/data/countries.py
index 663c7d5759..b725cc22ba 100644
--- a/caravel/data/countries.py
+++ b/caravel/data/countries.py
@@ -1,4 +1,8 @@
"""This module contains data related to countries and is used for geo mapping"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
countries = [
{
diff --git a/caravel/forms.py b/caravel/forms.py
index cfb59653df..159437adc4 100644
--- a/caravel/forms.py
+++ b/caravel/forms.py
@@ -1,4 +1,8 @@
"""Contains the logic to create cohesive forms on the explore view"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
from wtforms import (
Form, SelectMultipleField, SelectField, TextField, TextAreaField,
diff --git a/caravel/models.py b/caravel/models.py
index b4bcdd3f1e..a6063c6425 100644
--- a/caravel/models.py
+++ b/caravel/models.py
@@ -1,4 +1,8 @@
"""A collection of ORM sqlalchemy models for Caravel"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
from copy import deepcopy, copy
from collections import namedtuple
@@ -191,8 +195,8 @@ class Slice(Model, AuditMixinNullable):
slice_params['slice_name'] = self.slice_name
from werkzeug.urls import Href
href = Href(
- "/caravel/explore/{self.datasource_type}/"
- "{self.datasource_id}/".format(self=self))
+ "/caravel/explore/{obj.datasource_type}/"
+ "{obj.datasource_id}/".format(obj=self))
return href(slice_params)
@property
@@ -202,8 +206,8 @@ class Slice(Model, AuditMixinNullable):
@property
def slice_link(self):
url = self.slice_url
- return '{self.slice_name}'.format(
- url=url, self=self)
+ return '{obj.slice_name}'.format(
+ url=url, obj=self)
dashboard_slices = Table(
@@ -244,7 +248,7 @@ class Dashboard(Model, AuditMixinNullable):
return {}
def dashboard_link(self):
- return '{self.dashboard_title}'.format(self=self)
+ return '{obj.dashboard_title}'.format(obj=self)
@property
def json_data(self):
@@ -432,12 +436,12 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
@property
def perm(self):
return (
- "[{self.database}].[{self.table_name}]"
- "(id:{self.id})").format(self=self)
+ "[{obj.database}].[{obj.table_name}]"
+ "(id:{obj.id})").format(obj=self)
@property
def full_name(self):
- return "[{self.database}].[{self.table_name}]".format(self=self)
+ return "[{obj.database}].[{obj.table_name}]".format(obj=self)
@property
def dttm_cols(self):
@@ -472,11 +476,11 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
if self.default_endpoint:
return self.default_endpoint
else:
- return "/caravel/explore/{self.type}/{self.id}/".format(self=self)
+ return "/caravel/explore/{obj.type}/{obj.id}/".format(obj=self)
@property
def table_link(self):
- return '{self.table_name}'.format(self=self)
+ return '{obj.table_name}'.format(obj=self)
@property
def metrics_combo(self):
@@ -816,9 +820,9 @@ class DruidCluster(Model, AuditMixinNullable):
def refresh_datasources(self):
endpoint = (
- "http://{self.coordinator_host}:{self.coordinator_port}/"
- "{self.coordinator_endpoint}/datasources"
- ).format(self=self)
+ "http://{obj.coordinator_host}:{obj.coordinator_port}/"
+ "{obj.coordinator_endpoint}/datasources"
+ ).format(obj=self)
datasources = json.loads(requests.get(endpoint).text)
for datasource in datasources:
@@ -862,8 +866,8 @@ class DruidDatasource(Model, AuditMixinNullable, Queryable):
@property
def perm(self):
return (
- "[{self.cluster_name}].[{self.datasource_name}]"
- "(id:{self.id})").format(self=self)
+ "[{obj.cluster_name}].[{obj.datasource_name}]"
+ "(id:{obj.id})").format(obj=self)
@property
def url(self):
@@ -878,17 +882,17 @@ class DruidDatasource(Model, AuditMixinNullable, Queryable):
@property
def full_name(self):
return (
- "[{self.cluster_name}]."
- "[{self.datasource_name}]").format(self=self)
+ "[{obj.cluster_name}]."
+ "[{obj.datasource_name}]").format(obj=self)
def __repr__(self):
return self.datasource_name
@property
def datasource_link(self):
- url = "/caravel/explore/{self.type}/{self.id}/".format(self=self)
- return '{self.datasource_name}'.format(
- url=url, self=self)
+ url = "/caravel/explore/{obj.type}/{obj.id}/".format(obj=self)
+ return '{obj.datasource_name}'.format(
+ url=url, obj=self)
def get_metric_obj(self, metric_name):
return [
diff --git a/caravel/utils.py b/caravel/utils.py
index a67ea650f2..05fb325287 100644
--- a/caravel/utils.py
+++ b/caravel/utils.py
@@ -1,7 +1,10 @@
"""Utility functions used across Caravel"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
from datetime import datetime
-import hashlib
import functools
import json
import logging
@@ -133,43 +136,6 @@ class JSONEncodedDict(TypeDecorator):
return value
-class ColorFactory(object):
-
- """Used to generated arrays of colors server side"""
-
- BNB_COLORS = [
- # rausch hackb kazan babu lima beach barol
- '#ff5a5f', '#7b0051', '#007A87', '#00d1c1', '#8ce071', '#ffb400', '#b4a76c',
- '#ff8083', '#cc0086', '#00a1b3', '#00ffeb', '#bbedab', '#ffd266', '#cbc29a',
- '#ff3339', '#ff1ab1', '#005c66', '#00b3a5', '#55d12e', '#b37e00', '#988b4e',
- ]
-
- def __init__(self, hash_based=False):
- self.d = {}
- self.hash_based = hash_based
-
- def get(self, s):
- """Gets a color from a string and memoize the association
-
- >>> cf = ColorFactory()
- >>> cf.get('item_1')
- '#ff5a5f'
- >>> cf.get('item_2')
- '#7b0051'
- >>> cf.get('item_1')
- '#ff5a5f'
- """
- if self.hash_based:
- s = s.encode('utf-8')
- h = hashlib.md5(s)
- i = int(h.hexdigest(), 16)
- else:
- if s not in self.d:
- self.d[s] = len(self.d)
- i = self.d[s]
- return self.BNB_COLORS[i % len(self.BNB_COLORS)]
-
-
def init(caravel):
"""Inits the Caravel application with security roles and such"""
db = caravel.db
diff --git a/caravel/views.py b/caravel/views.py
index 267957c89d..8ab2fc8b29 100644
--- a/caravel/views.py
+++ b/caravel/views.py
@@ -1,4 +1,8 @@
"""Flask web views for Caravel"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
from datetime import datetime
import json
diff --git a/caravel/viz.py b/caravel/viz.py
index 20224dc446..d3b0f3f953 100644
--- a/caravel/viz.py
+++ b/caravel/viz.py
@@ -3,6 +3,10 @@
These objects represent the backend of all the visualizations that
Caravel can render.
"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
from collections import OrderedDict, defaultdict
from datetime import datetime, timedelta
@@ -409,7 +413,7 @@ class PivotTableViz(BaseViz):
na_rep='',
classes=(
"dataframe table table-striped table-bordered "
- "table-condensed table-hover"))
+ "table-condensed table-hover").split(" "))
class MarkupViz(BaseViz):