-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuperset_config.py
executable file
·164 lines (128 loc) · 4.64 KB
/
superset_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import os
from flask import Flask, redirect, session
from flask_appbuilder import expose, IndexView
from superset.superset_typing import FlaskResponse
from superset.extensions import appbuilder
from datetime import timedelta
from mapa_view.views import mapa_bp
from tools_view.views import ToolsView
FAVICONS = [{"href": "https://argob.github.io/poncho/plantillas/paginas-de-argentina/img/favicon.ico"}]
# mapbox api
MAPBOX_API_KEY = os.getenv('MAPBOX_API_KEY')
# cache config
CACHE_CONFIG = {
'CACHE_TYPE': 'RedisCache',
'CACHE_DEFAULT_TIMEOUT': 300,
'CACHE_KEY_PREFIX': 'superset_',
'CACHE_REDIS_HOST': 'redis',
'CACHE_REDIS_PORT': 6379,
'CACHE_REDIS_DB': 1,
'CACHE_REDIS_URL': 'redis://redis:6379/1'
}
FILTER_STATE_CACHE_CONFIG = {
'CACHE_TYPE': 'RedisCache',
'CACHE_DEFAULT_TIMEOUT': 86400,
'CACHE_KEY_PREFIX': 'superset_filter_',
'CACHE_REDIS_URL': 'redis://redis:6379/2'
}
EXPLORE_FORM_DATA_CACHE_CONFIG = {
'CACHE_TYPE': 'RedisCache',
'CACHE_DEFAULT_TIMEOUT': 86400,
'CACHE_KEY_PREFIX': 'superset_form_',
'CACHE_REDIS_URL': 'redis://redis:6379/3'
}
# database
SQLALCHEMY_DATABASE_URI = \
f'postgresql+psycopg2://{os.getenv("POSTGRES_USER")}:{os.getenv("POSTGRES_PASSWORD")}@postgres:5432/superset'
SQLALCHEMY_TRACK_MODIFICATIONS = True
SECRET_KEY = os.getenv("SECRET_KEY")
# language options
BABEL_DEFAULT_LOCALE = "es"
BABEL_DEFAULT_FOLDER = "superset/translations"
LANGUAGES = {
"es": {"flag": "ar", "name": "Spanish"},
}
# Config custom para nginx
ENABLE_PROXY_FIX=True
PROXY_FIX_CONFIG = {"x_for": 1, "x_proto": 1, "x_host": 1, "x_port": 1, "x_prefix": 0}
HTTP_HEADERS = {'X-Frame-Options': 'ALLOWALL'}
# custom path público
BLUEPRINTS = [
mapa_bp,
]
# redirect al dashboard base
WELCOME_PAGE_REDIRECT_DEFAULT="/mapa"
WELCOME_PAGE_REDIRECT_ADMIN="/dashboard/list/"
WELCOME_PAGE_REDIRECT_BY_ROLE = {
"Alpha": "/dashboard/list/",
"Gamma": "/superset/dashboard/86/",
"externo": "/superset/dashboard/86/",
"Usuario": "/superset/dashboard/86/",
"Externo": "/superset/dashboard/86/",
}
# Change welcome page
# https://stackoverflow.com/a/69930056/1760643
class SupersetDashboardIndexView(IndexView):
@expose("/")
def index(self) -> FlaskResponse:
# from superset.views.base import is_user_admin
from superset import security_manager
user_roles = security_manager.get_user_roles()
# if is_user_admin():
# return redirect(WELCOME_PAGE_REDIRECT_ADMIN)
# else:
for role in user_roles:
role_name = role.name
if role_name in WELCOME_PAGE_REDIRECT_BY_ROLE:
return redirect(WELCOME_PAGE_REDIRECT_BY_ROLE[role_name])
return redirect(WELCOME_PAGE_REDIRECT_DEFAULT)
FAB_INDEX_VIEW = f"{SupersetDashboardIndexView.__module__}.{SupersetDashboardIndexView.__name__}"
# set up max age of session to 24 hours
def make_session_permanent():
'''
Enable maxAge for the cookie 'session'
'''
session.permanent = True
# set up max age of session to 365 days
PERMANENT_SESSION_LIFETIME = timedelta(days=365)
def FLASK_APP_MUTATOR(app: Flask) -> None:
app.before_request_funcs.setdefault(None, []).append(make_session_permanent)
# tools view
appbuilder.add_view_no_menu(ToolsView())
# base url
# This is for internal use, you can keep http
WEBDRIVER_BASEURL="http://superset:8088"
# This is the link sent to the recipient, change to your domain eg. https://superset.mydomain.com
WEBDRIVER_BASEURL_USER_FRIENDLY=os.getenv('SUPERSET_URL')
# app title
APP_NAME = 'Mapa de Inversión Social - Ministerio de Desarrollo Social'
# no registration
AUTH_USER_REGISTRATION = False
# map controls
ENABLE_JAVASCRIPT_CONTROLS = True
# Feature flags
FEATURE_FLAGS = {
"VERSIONED_EXPORT": True,
"DASHBOARD_RBAC": True,
"ENABLE_JAVASCRIPT_CONTROLS": True,
"EMBEDDED_SUPERSET": True,
"GENERIC_CHART_AXES": True,
"DISABLE_LEGACY_DATASOURCE_EDITOR": False,
}
PUBLIC_ROLE_LIKE = "vistaPublica"
WTF_CSRF_ENABLED = False
CSV_EXPORT = {"encoding": "cp1252", "sep": ";", "decimal": ","}
# Dashboard embedding
GUEST_ROLE_NAME = "vistaPublica"
GUEST_TOKEN_JWT_SECRET = "q8u32wiodhjakl12uas"
GUEST_TOKEN_JWT_ALGO = "HS256"
GUEST_TOKEN_HEADER_NAME = "X-GuestToken"
GUEST_TOKEN_JWT_EXP_SECONDS = 300 # 5 minutes
HTML_SANITIZATION = False
# Override the default d3 locale format
D3_FORMAT = {
"decimal": ",", # - decimal place string (e.g., ".").
"thousands": ".", # - group separator string (e.g., ",").
"grouping": [3], # - array of group sizes (e.g., [3]), cycled as needed.
"currency": ["$", ""] # - currency prefix/suffix strings (e.g., ["$", ""])
}