-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
static.py
62 lines (52 loc) · 1.97 KB
/
static.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
import hashlib
import json
from flask import render_template, send_from_directory, current_app
from flask_login import current_user, login_required
from redash import settings, __version__, redis_connection
from redash.wsgi import app
from redash.version_check import get_latest_version
@app.route('/admin/<anything>/<whatever>')
@app.route('/admin/<anything>')
@app.route('/dashboard/<anything>')
@app.route('/alerts')
@app.route('/alerts/<pk>')
@app.route('/queries')
@app.route('/data_sources')
@app.route('/data_sources/<pk>')
@app.route('/users')
@app.route('/users/<pk>')
@app.route('/queries/<query_id>')
@app.route('/queries/<query_id>/<anything>')
@app.route('/personal')
@app.route('/')
@login_required
def index(**kwargs):
email_md5 = hashlib.md5(current_user.email.lower()).hexdigest()
gravatar_url = "https://www.gravatar.com/avatar/%s?s=40" % email_md5
user = {
'gravatar_url': gravatar_url,
'id': current_user.id,
'name': current_user.name,
'email': current_user.email,
'groups': current_user.groups,
'permissions': current_user.permissions
}
client_config = {
'clientSideMetrics': settings.CLIENT_SIDE_METRICS,
'allowScriptsInUserInput': settings.ALLOW_SCRIPTS_IN_USER_INPUT,
'highChartsTurboThreshold': settings.HIGHCHARTS_TURBO_THRESHOLD,
'dateFormat': settings.DATE_FORMAT,
'dateTimeFormat': "{0} HH:mm".format(settings.DATE_FORMAT),
'newVersionAvailable': get_latest_version(),
'version': __version__
}
return render_template("index.html", user=json.dumps(user), name=settings.NAME,
client_config=json.dumps(client_config),
analytics=settings.ANALYTICS)
@app.route('/<path:filename>')
def send_static(filename):
if current_app.debug:
cache_timeout = 0
else:
cache_timeout = None
return send_from_directory(settings.STATIC_ASSETS_PATH, filename, cache_timeout=cache_timeout)