-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathviews.py
More file actions
76 lines (62 loc) · 2.28 KB
/
Copy pathviews.py
File metadata and controls
76 lines (62 loc) · 2.28 KB
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
from django.http import HttpResponse
from django.shortcuts import render
import jwt
from django.contrib.auth.decorators import login_required
METABASE_SITE_URL = "localhost:3000"
METABASE_SECRET_KEY = "a1c0952f3ff361f1e7dd8433a0a50689a004317a198ecb0a67ba90c73c27a958"
def get_token(payload):
return jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256").decode('utf8')
def index(request):
return render(request,
'user_stats/index.html',
{})
def signed_public_dashboard(request):
payload = {
"resource": {"dashboard": 1},
"params": {
}
}
iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + get_token(payload) + "#bordered=true"
return render(request,
'user_stats/signed_public_dashboard.html',
{'iframeUrl': iframeUrl})
@login_required
def signed_chart(request, user_id):
payload = {
"resource": {"question": 2},
"params": {
"person_id": user_id
}
}
iframeUrl = METABASE_SITE_URL + "/embed/question/" + get_token(payload) + "#bordered=true"
if request.user.is_superuser:
# always show admins user stats
return render(request,
'user_stats/signed_chart.html',
{'iframeUrl': iframeUrl})
elif request.user.id == user_id:
return render(request,
'user_stats/signed_chart.html',
{'iframeUrl': iframeUrl})
else:
return HttpResponse("You're not allowed to look at user %s." % user_id)
@login_required
def signed_dashboard(request, user_id):
payload = {
"resource": {"dashboard": 2},
"params": {
"id": user_id
}
}
iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + get_token(payload) + "#bordered=true"
if request.user.is_superuser:
# always show admins user stats
return render(request,
'user_stats/signed_dashboard.html',
{'iframeUrl': iframeUrl})
elif request.user.id == user_id:
return render(request,
'user_stats/signed_dashboard.html',
{'iframeUrl': iframeUrl})
else:
return HttpResponse("You're not allowed to look at user %s." % user_id)