Skip to content

Update django examples #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions django/embedded_analytics/embedded_analytics/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'allauth.account.middleware.AccountMiddleware',
]

ROOT_URLCONF = 'embedded_analytics.urls'
Expand Down
8 changes: 4 additions & 4 deletions django/embedded_analytics/embedded_analytics/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import include, url
from django.urls import re_path, include
from django.contrib import admin

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^accounts/', include('allauth.urls')),
url(r'^', include('user_stats.urls'))
re_path(r'^admin/', admin.site.urls),
re_path(r'^accounts/', include('allauth.urls')),
re_path(r'^', include('user_stats.urls'))
]
6 changes: 3 additions & 3 deletions django/embedded_analytics/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Django==1.11.29
django-allauth==0.30.0
PyJWT==1.4.2
Django==5.2
django-allauth==65.7
PyJWT==2.10
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1>Embedding charts with signed parameters</h1>
}
}

token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256").decode('utf8')
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256")

iframeUrl = METABASE_SITE_URL + "/embed/question/" + token + "#bordered=true"
</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1>Embedding dashboards with signed parameters</h1>
}
}

token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256").decode('utf8')
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256")

iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true"
</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h1>Signed dashboards without parameters</h1>
}
}

token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256").decode('utf8')
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256")

iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true"
</pre>
Expand Down
10 changes: 5 additions & 5 deletions django/embedded_analytics/user_stats/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.conf.urls import url
from django.urls import re_path

from . import views

urlpatterns = [
url(r'^signed_chart/(?P<user_id>[0-9]+)/$', views.signed_chart, name='signed_chart'),
url(r'^signed_dashboard/(?P<user_id>[0-9]+)/$', views.signed_dashboard, name='signed_dashboard'),
url(r'^signed_public_dashboard/$', views.signed_public_dashboard, name='signed_public_dashboard'),
url(r'^$', views.index, name='index'),
re_path(r'^signed_chart/(?P<user_id>[0-9]+)/$', views.signed_chart, name='signed_chart'),
re_path(r'^signed_dashboard/(?P<user_id>[0-9]+)/$', views.signed_dashboard, name='signed_dashboard'),
re_path(r'^signed_public_dashboard/$', views.signed_public_dashboard, name='signed_public_dashboard'),
re_path(r'^$', views.index, name='index'),
]
2 changes: 1 addition & 1 deletion django/embedded_analytics/user_stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
METABASE_SECRET_KEY = "a1c0952f3ff361f1e7dd8433a0a50689a004317a198ecb0a67ba90c73c27a958"

def get_token(payload):
return jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256").decode('utf8')
return jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256")

def index(request):
return render(request,
Expand Down
2 changes: 1 addition & 1 deletion django/minimal_example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<body>
<h1>Embed {{ title }}</h1>
<iframe
src="{{iframeUrl}}"
src="{{ iframe_url }}"
frameborder="1"
width="800"
height="600"
Expand Down
10 changes: 5 additions & 5 deletions django/minimal_example/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import os
import time

from django.conf.urls import url
from django.urls import re_path
from django.http import HttpResponse
from django.template.loader import render_to_string

Expand All @@ -37,15 +37,15 @@ def home(request):
'exp': round(time.time()) + (60 * 10)
}
token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm='HS256')
iframeUrl = METABASE_SITE_URL + '/embed/question/' + token + '#bordered=true&titled=true'
iframe_url = METABASE_SITE_URL + '/embed/question/' + token + '#bordered=true&titled=true'

html = render_to_string('index.html', {
'title': 'Embedding Metabase',
'iframeUrl': iframeUrl
'iframe_url': iframe_url
})
return HttpResponse(html)


urlpatterns = [
url(r'^$', home, name='homepage')
re_path(r'^$', home, name='homepage')
]
2 changes: 1 addition & 1 deletion html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<body>
<h1>Metabase Embedding</h1>
<iframe
src="http://localhost:3000/public/question/7f0c3c4b-173e-452c-810f-ccb3fc4482a3"
src="http://localhost:3000/public/dashboard/e104be98-2ea1-4dce-abff-aa3cfeddfe40"
frameborder="1"
width="600"
height="400"
Expand Down