-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restored support to oldest Django versions
- Loading branch information
1 parent
053afe1
commit 2326895
Showing
6 changed files
with
37 additions
and
33 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
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,10 +1,10 @@ | ||
from django.urls import path | ||
from django.conf.urls import url | ||
|
||
from .views import Manifest, ServiceWorker, OfflineView | ||
from .views import manifest, service_worker, offline | ||
|
||
# Serve up serviceworker.js and manifest.json at the root | ||
urlpatterns = [ | ||
path('serviceworker.js', ServiceWorker.as_view(), name='serviceworker'), | ||
path('manifest.json', Manifest.as_view(), name='manifest'), | ||
path('offline', OfflineView.as_view(), name='offline') | ||
url('^serviceworker.js$', service_worker, name='serviceworker'), | ||
url('^manifest.json$', manifest, name='manifest'), | ||
url('^offline/$', offline, name='offline') | ||
] |
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,27 +1,21 @@ | ||
from django.views.generic.base import TemplateView | ||
from django.http import HttpResponse | ||
from django.shortcuts import render | ||
|
||
from . import app_settings | ||
|
||
|
||
class ServiceWorker(TemplateView): | ||
content_type = 'application/javascript' | ||
template_name = app_settings.PWA_SERVICE_WORKER_PATH | ||
|
||
def get_context_data(self, **kwargs): | ||
kwargs['PWA_APP_FETCH_URL'] = app_settings.PWA_APP_FETCH_URL | ||
return super().get_context_data(**kwargs) | ||
def service_worker(request): | ||
response = HttpResponse(open(app_settings.PWA_SERVICE_WORKER_PATH).read(), content_type='application/javascript') | ||
return response | ||
|
||
|
||
class Manifest(TemplateView): | ||
content_type = 'application/json' | ||
template_name = 'manifest.json' | ||
|
||
def get_context_data(self, **kwargs): | ||
for setting_name in dir(app_settings): | ||
if setting_name.startswith('PWA_'): | ||
kwargs[setting_name] = getattr(app_settings, setting_name) | ||
return super().get_context_data(**kwargs) | ||
def manifest(request): | ||
return render(request, 'manifest.json', { | ||
setting_name: getattr(app_settings, setting_name) | ||
for setting_name in dir(app_settings) | ||
if setting_name.startswith('PWA_') | ||
}) | ||
|
||
|
||
class OfflineView(TemplateView): | ||
template_name = "offline.html" | ||
def offline(request): | ||
return render(request, "offline.html") |
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