Skip to content

Commit

Permalink
Merge pull request #1 from airbnb/master
Browse files Browse the repository at this point in the history
update from master
  • Loading branch information
bnpysse committed May 17, 2016
2 parents 7b10759 + 4738b01 commit 58ad2e2
Show file tree
Hide file tree
Showing 64 changed files with 3,267 additions and 564 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*.pyc
changelog.sh
babel
.DS_Store
.coverage
_build
Expand Down
1,044 changes: 882 additions & 162 deletions CHANGELOG.md

Large diffs are not rendered by default.

46 changes: 41 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ npm run dev

Tests can then be run with:

./run_unit_tests.sh
./run_tests.sh

Lint the project with:

Expand All @@ -159,12 +159,12 @@ Generate the documentation with:
cd docs && ./build.sh

## CSS Themes
As part of the npm build process, CSS for Caravel is compiled from ```Less```, a dynamic stylesheet language.
As part of the npm build process, CSS for Caravel is compiled from `Less`, a dynamic stylesheet language.

It's possible to customize or add your own theme to Caravel, either by overriding CSS rules or preferably
by modifying the Less variables or files in ```assets/stylesheets/less/```.
by modifying the Less variables or files in `assets/stylesheets/less/`.

The ```variables.less``` and ```bootswatch.less``` files that ship with Caravel are derived from
The `variables.less` and `bootswatch.less` files that ship with Caravel are derived from
[Bootswatch](https://bootswatch.com) and thus extend Bootstrap. Modify variables in these files directly, or
swap them out entirely with the equivalent files from other Bootswatch (themes)[https://github.com/thomaspark/bootswatch.git]

Expand All @@ -179,7 +179,43 @@ meets these guidelines:
as part of the same PR. Doc string are often sufficient, make
sure to follow the sphinx compatible standards.
3. The pull request should work for Python 2.6, 2.7, and ideally python 3.3.
`from __future__ import ` will be required in every `.py` file soon.
``from __future__ import`` will be required in every `.py` file soon.
4. Code will be reviewed by re running the unittests, flake8 and syntax
should be as rigorous as the core Python project.
5. Please rebase and resolve all conflicts before submitting.


## Tranlations

We use [Babel](http://babel.pocoo.org/en/latest/) to translate Caravel. The
key is to instrument the strings that need translation using
`from flask.ext.babelpkg import lazy_gettext as _`. Once this is imported in
a module, all you have to do is to `_("Wrap your strings")` using the
underscore `_` "function".

To enable changing language in your environment, you can simply add the
`LANGUAGES` parameter to your `caravel_config.py`. Having more than one
options here will add a language selection dropdown on the right side of the
navigation bar.

LANGUAGES = {
'en': {'flag': 'us', 'name': 'English'},
'fr': {'flag': 'fr', 'name': 'French'},
'zh': {'flag': 'cn', 'name': 'Chinese'},
}

As per the [Flask AppBuilder documentation] about translation, to create a
new language dictionary, run the following command:

pybabel init -i ./babel/messages.pot -d caravel/translations -l es

Then it's a matter of running the statement bellow to gather all stings that
need translation

fabmanager babel-extract --target caravel/translations/

You can then translate the strings gathered in files located under
`caravel/translation`, where there's one per language. For the translations
to take effect, they need to be compiled using this command:

fabmanager babel-compile --target caravel/translations/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Caravel
[![PyPI version](https://badge.fury.io/py/caravel.svg)](https://badge.fury.io/py/caravel)
[![Coverage Status](https://coveralls.io/repos/airbnb/caravel/badge.svg?branch=master&service=github)](https://coveralls.io/github/airbnb/caravel?branch=master)
[![Code Health](https://landscape.io/github/airbnb/caravel/master/landscape.svg?style=flat)](https://landscape.io/github/airbnb/caravel/master)
[![PyPI](https://img.shields.io/pypi/pyversions/caravel.svg?maxAge=2592000)](https://pypi.python.org/pypi/caravel)
[![Requirements Status](https://requires.io/github/airbnb/caravel/requirements.svg?branch=master)](https://requires.io/github/airbnb/caravel/requirements/?branch=master)
[![Join the chat at https://gitter.im/airbnb/caravel](https://badges.gitter.im/airbnb/caravel.svg)](https://gitter.im/airbnb/caravel?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Documentation](https://img.shields.io/badge/docs-airbnb.io-blue.svg)](http://airbnb.io/caravel/)
Expand Down Expand Up @@ -89,7 +90,8 @@ Resources
-------------
* [Caravel Google Group](https://groups.google.com/forum/#!forum/airbnb_caravel)
* [Gitter (live chat) Channel](https://gitter.im/airbnb/caravel)
* [Docker image](https://hub.docker.com/r/kochalex/caravel/) (community contributed)
* [Docker image 1](https://hub.docker.com/r/kochalex/caravel/)
[Docker image 2](https://hub.docker.com/r/amancevice/caravel/) (community contributed)
* [Slides from Strata (March 2016)](https://drive.google.com/open?id=0B5PVE0gzO81oOVJkdF9aNkJMSmM)


Expand Down
5 changes: 0 additions & 5 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ List of TODO items for Caravel
* **Dashboard URL filters:** `{dash_url}#fltin__fieldname__value1,value2`
* **Default slice:** choose a default slice for the dataset instead of
default endpoint
* **refresh freq**: specifying the refresh frequency of a dashboard and
specific slices within it, some randomization would be nice
* **Widget sets / chart grids:** a way to have all charts support making
a series of charts and putting them in a grid. The same way that you
can groupby for series, you could chart by. The form field set would be
Expand All @@ -27,8 +25,6 @@ List of TODO items for Caravel
some visualizations as annotations. An example of a layer might be
"holidays" or "site outages", ...
* **Slack integration** - TBD
* **Sexy Viz Selector:** the visualization selector should be a nice large
modal with nice thumbnails for each one of the viz
* **Comments:** allow for people to comment on slices and dashes


Expand All @@ -37,7 +33,6 @@ List of TODO items for Caravel
* CREATE VIEW button from SQL editor
* Test button for when editing SQL expression
* Slider form element
* datasource in explore mode could be a dropdown
* [druid] Allow for post aggregations (ratios!)
* in/notin filters autocomplete (druid)

Expand Down
4 changes: 4 additions & 0 deletions babel/babel.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ignore: caravel/assets/node_modules/**]
[python: caravel/**.py]
[jinja2: caravel/**/templates/**.html]
encoding = utf-8
117 changes: 117 additions & 0 deletions babel/messages.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Translations template for Caravel.
# Copyright (C) 2016 ORGANIZATION
# This file is distributed under the same license as the Caravel project.
# Maxime Beauchemin <maximebeauchemin @ gmail.com>, 2016.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2016-05-02 00:21-0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.3.4\n"

#: caravel/models.py:564
msgid ""
"Datetime column not provided as part table configuration and is required "
"by this type of chart"
msgstr ""

#: caravel/models.py:1153
msgid "No data was returned."
msgstr ""

#: caravel/views.py:116
msgid ""
"Whether to make this column available as a [Time Granularity] option, "
"column has to be DATETIME or DATETIME-like"
msgstr ""

#: caravel/views.py:215
msgid "Databases"
msgstr ""

#: caravel/views.py:217 caravel/views.py:261 caravel/views.py:284
msgid "Sources"
msgstr ""

#: caravel/views.py:260
msgid "Tables"
msgstr ""

#: caravel/views.py:282
msgid "Druid Clusters"
msgstr ""

#: caravel/views.py:313
msgid "Slices"
msgstr ""

#: caravel/views.py:341
msgid ""
"This json object describes the positioning of the widgets in the "
"dashboard. It is dynamically generated when adjusting the widgets size "
"and positions by using drag & drop in the dashboard view"
msgstr ""

#: caravel/views.py:346
msgid ""
"The css for individual dashboards can be altered here, or in the "
"dashboard view where changes are immediately visible"
msgstr ""

#: caravel/views.py:367
msgid "Dashboards"
msgstr ""

#: caravel/views.py:392
msgid "Action Log"
msgstr ""

#: caravel/views.py:393
msgid "Security"
msgstr ""

#: caravel/views.py:430
msgid "Druid Datasources"
msgstr ""

#: caravel/views.py:514
msgid "The datasource seems to have been deleted"
msgstr ""

#: caravel/views.py:522
msgid "You don't seem to have access to this datasource"
msgstr ""

#: caravel/views.py:843
msgid "This view requires the `all_datasource_access` permission"
msgstr ""

#: caravel/views.py:954
msgid "CSS Templates"
msgstr ""

#: caravel/templates/appbuilder/navbar_right.html:34
msgid "Profile"
msgstr ""

#: caravel/templates/appbuilder/navbar_right.html:35
msgid "Logout"
msgstr ""

#: caravel/templates/appbuilder/navbar_right.html:40
msgid "Login"
msgstr ""

#: caravel/templates/caravel/welcome.html:8
#: caravel/templates/caravel/welcome.html:13
msgid "Welcome!"
msgstr ""

17 changes: 13 additions & 4 deletions caravel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import logging
import os
from logging.handlers import TimedRotatingFileHandler

from flask import Flask, redirect
from flask.ext.appbuilder import SQLA, AppBuilder, IndexView
Expand All @@ -20,10 +21,6 @@
APP_DIR = os.path.dirname(__file__)
CONFIG_MODULE = os.environ.get('CARAVEL_CONFIG', 'caravel.config')

# Logging configuration
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(name)s:%(message)s')
logging.getLogger().setLevel(logging.DEBUG)

app = Flask(__name__)
app.config.from_object(CONFIG_MODULE)
if not app.debug:
Expand All @@ -37,6 +34,18 @@

migrate = Migrate(app, db, directory=APP_DIR + "/migrations")

# Logging configuration
logging.basicConfig(format=app.config.get('LOG_FORMAT'))
logging.getLogger().setLevel(app.config.get('LOG_LEVEL'))

if app.config.get('ENABLE_TIME_ROTATE'):
logging.getLogger().setLevel(app.config.get('TIME_ROTATE_LOG_LEVEL'))
handler = TimedRotatingFileHandler(app.config.get('FILENAME'),
when=app.config.get('ROLLOVER'),
interval=app.config.get('INTERVAL'),
backupCount=app.config.get('BACKUP_COUNT'))
logging.getLogger().addHandler(handler)


class MyIndexView(IndexView):
@expose('/')
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added caravel/assets/images/viz_thumbnails/horizon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion caravel/assets/javascripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ require('./caravel-select2.js');
require('../node_modules/gridster/dist/jquery.gridster.min.css');
require('../node_modules/gridster/dist/jquery.gridster.min.js');

require('../stylesheets/dashboard.css');

var Dashboard = function (dashboardData) {
var dashboard = $.extend(dashboardData, {
filters: {},
Expand Down Expand Up @@ -92,7 +94,7 @@ var Dashboard = function (dashboardData) {
fetchAndRender();
},
refreshExcept: function (slice_id) {
var immune = this.metadata.filter_immune_slice || [];
var immune = this.metadata.filter_immune_slices || [];
this.slices.forEach(function (slice) {
if (slice.data.slice_id !== slice_id && immune.indexOf(slice.data.slice_id) === -1) {
slice.render();
Expand Down
1 change: 1 addition & 0 deletions caravel/assets/javascripts/explore.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require('../node_modules/bootstrap-toggle/js/bootstrap-toggle.min.js');

// css
require('../vendor/pygments.css');
require('../stylesheets/explore.css');
require('../node_modules/bootstrap-toggle/css/bootstrap-toggle.min.css');

var slice;
Expand Down
18 changes: 15 additions & 3 deletions caravel/assets/javascripts/modules/caravel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var $ = require('jquery');
var jQuery = $;
var d3 = require('d3');
var Mustache = require('mustache');

// vis sources
var sourceMap = {
Expand All @@ -26,7 +27,9 @@ var sourceMap = {
table: 'table.js',
word_cloud: 'word_cloud.js',
world_map: 'world_map.js',
treemap: 'treemap.js'
treemap: 'treemap.js',
cal_heatmap: 'cal_heatmap.js',
horizon: 'horizon.js'
};

var color = function () {
Expand All @@ -48,6 +51,7 @@ var color = function () {
var seen = {};
return function (s) {
if (!s) { return; }
s = String(s);
// next line is for caravel series that should have the same color
s = s.replace('---', '');
if (seen[s] === undefined) {
Expand Down Expand Up @@ -214,6 +218,13 @@ var px = (function () {
getWidgetHeader: function () {
return this.container.parents("li.widget").find(".chart-header");
},
render_template: function (s) {
var context = {
width: this.width,
height: this.height
};
return Mustache.render(s, context);
},
jsonEndpoint: function () {
var parser = document.createElement('a');
parser.href = data.json_endpoint;
Expand Down Expand Up @@ -301,6 +312,7 @@ var px = (function () {
},
bindResizeToWindowResize: function () {
var resizeTimer;
var slice = this;
$(window).on('resize', function (e) {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function () {
Expand All @@ -314,7 +326,7 @@ var px = (function () {
}
this.force = force;
token.find("img.loading").show();
container.css('height', slice.height());
container.css('height', this.height());
dttm = 0;
timer = setInterval(stopwatch, 10);
$('#timer').removeClass('btn-danger btn-success');
Expand All @@ -323,7 +335,7 @@ var px = (function () {
},
resize: function () {
token.find("img.loading").show();
container.css('height', slice.height());
container.css('height', this.height());
this.viz.render();
this.viz.resize();
},
Expand Down
Loading

0 comments on commit 58ad2e2

Please sign in to comment.