-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split redash/__init__.py to prevent import time side-effects.
- Loading branch information
Showing
11 changed files
with
112 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from flask import Flask | ||
from flask_sslify import SSLify | ||
from werkzeug.contrib.fixers import ProxyFix | ||
|
||
from . import mail, settings | ||
from .utils import routes | ||
|
||
|
||
class Redash(Flask): | ||
"""A custom Flask app for Redash""" | ||
def __init__(self, *args, **kwargs): | ||
kwargs.update({ | ||
'template_folder': settings.STATIC_ASSETS_PATH, | ||
'static_folder': settings.STATIC_ASSETS_PATH, | ||
'static_path': '/static', | ||
}) | ||
super(Redash, self).__init__(__name__, *args, **kwargs) | ||
# Make sure we get the right referral address even behind proxies like nginx. | ||
self.wsgi_app = ProxyFix(self.wsgi_app, settings.PROXIES_COUNT) | ||
# Handle the special case of the org slug | ||
self.url_map.converters['org_slug'] = routes.SlugConverter | ||
# Configure Redash using our settings | ||
self.config.from_object('redash.settings') | ||
|
||
|
||
def create_app(): | ||
from . import authentication, extensions, handlers, limiter, migrate | ||
from .destinations import import_destinations | ||
from .handlers import chrome_logger | ||
from .handlers.webpack import configure_webpack | ||
from .metrics.request import provision_app | ||
from .models import db, users | ||
from .query_runner import import_query_runners | ||
from .utils import sentry | ||
from .version_check import reset_new_version_status | ||
|
||
sentry.init() | ||
app = Redash() | ||
|
||
# Check and update the cached version for use by the client | ||
app.before_first_request(reset_new_version_status) | ||
|
||
# Load query runners and destinations | ||
import_query_runners(settings.QUERY_RUNNERS) | ||
import_destinations(settings.DESTINATIONS) | ||
|
||
if settings.ENFORCE_HTTPS: | ||
SSLify(app, skips=['ping']) | ||
|
||
provision_app(app) | ||
db.init_app(app) | ||
migrate.init_app(app, db) | ||
mail.init_app(app) | ||
authentication.init_app(app) | ||
limiter.init_app(app) | ||
handlers.init_app(app) | ||
configure_webpack(app) | ||
extensions.init_extensions(app) | ||
chrome_logger.init_app(app) | ||
users.init_app(app) | ||
|
||
return app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from werkzeug.routing import BaseConverter | ||
|
||
|
||
class SlugConverter(BaseConverter): | ||
def to_python(self, value): | ||
# This is ay workaround for when we enable multi-org and some files are being called by the index rule: | ||
# for path in settings.STATIC_ASSETS_PATHS: | ||
# full_path = safe_join(path, value) | ||
# if os.path.isfile(full_path): | ||
# raise ValidationError() | ||
|
||
return value | ||
|
||
def to_url(self, value): | ||
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from redash import create_app | ||
from redash.app import create_app | ||
|
||
app = create_app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters