Adding from __future__ imports (#288)

* Adding from __future__ imports

* fixes

* Fixing doctests

* Removing unused ColorFactory (in js now)

* linting
This commit is contained in:
Maxime Beauchemin 2016-04-07 08:39:08 -07:00
parent 90a3b9f2c4
commit bcca840f01
11 changed files with 67 additions and 59 deletions

View File

@ -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

View File

@ -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"+

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 = [
{

View File

@ -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,

View File

@ -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 '<a href="{url}">{self.slice_name}</a>'.format(
url=url, self=self)
return '<a href="{url}">{obj.slice_name}</a>'.format(
url=url, obj=self)
dashboard_slices = Table(
@ -244,7 +248,7 @@ class Dashboard(Model, AuditMixinNullable):
return {}
def dashboard_link(self):
return '<a href="{self.url}">{self.dashboard_title}</a>'.format(self=self)
return '<a href="{obj.url}">{obj.dashboard_title}</a>'.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 '<a href="{self.explore_url}">{self.table_name}</a>'.format(self=self)
return '<a href="{obj.explore_url}">{obj.table_name}</a>'.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 '<a href="{url}">{self.datasource_name}</a>'.format(
url=url, self=self)
url = "/caravel/explore/{obj.type}/{obj.id}/".format(obj=self)
return '<a href="{url}">{obj.datasource_name}</a>'.format(
url=url, obj=self)
def get_metric_obj(self, metric_name):
return [

View File

@ -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

View File

@ -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

View File

@ -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):