Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed8dc195fb | ||
|
|
f2fdf0c123 | ||
|
|
b1c697c1de | ||
|
|
d687b0c047 | ||
|
|
ab8db72bd3 | ||
|
|
2326895768 |
16
CHANGELOG.md
16
CHANGELOG.md
@@ -42,4 +42,20 @@
|
|||||||
### Changed
|
### Changed
|
||||||
- Update `CHANGELOG.md`
|
- Update `CHANGELOG.md`
|
||||||
- Update `README.md`
|
- Update `README.md`
|
||||||
|
|
||||||
|
## 1.0.3
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Restored support to oldest Django versions
|
||||||
|
|
||||||
|
## 1.0.4
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fix problem of multiple service workers being registered over multiple URLs
|
||||||
|
|
||||||
|
## 1.0.5
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Updated manifest.json by adding scope parameter.
|
||||||
|
- Updated serviceworker.js add scope dynamic parameter
|
||||||
|
|
||||||
@@ -5,6 +5,7 @@ django-pwa
|
|||||||
[](https://codecov.io/gh/silviolleite/django-pwa)
|
[](https://codecov.io/gh/silviolleite/django-pwa)
|
||||||
[](https://pypi.org/project/django-pwa/)
|
[](https://pypi.org/project/django-pwa/)
|
||||||
[](https://pypi.org/project/django-pwa)
|
[](https://pypi.org/project/django-pwa)
|
||||||
|
[](https://pypi.org/project/django-pwa)
|
||||||
|
|
||||||
This Django app turns your project into a [progressive web app](https://developers.google.com/web/progressive-web-apps/). Navigating to your site on an Android phone will prompt you to add the app to your home screen.
|
This Django app turns your project into a [progressive web app](https://developers.google.com/web/progressive-web-apps/). Navigating to your site on an Android phone will prompt you to add the app to your home screen.
|
||||||
|
|
||||||
@@ -44,6 +45,7 @@ PWA_APP_DESCRIPTION = "My app description"
|
|||||||
PWA_APP_THEME_COLOR = '#0A0302'
|
PWA_APP_THEME_COLOR = '#0A0302'
|
||||||
PWA_APP_BACKGROUND_COLOR = '#ffffff'
|
PWA_APP_BACKGROUND_COLOR = '#ffffff'
|
||||||
PWA_APP_DISPLAY = 'standalone'
|
PWA_APP_DISPLAY = 'standalone'
|
||||||
|
PWA_APP_SCOPE = '/',
|
||||||
PWA_APP_ORIENTATION = 'any'
|
PWA_APP_ORIENTATION = 'any'
|
||||||
PWA_APP_START_URL = '/'
|
PWA_APP_START_URL = '/'
|
||||||
PWA_APP_ICONS = [
|
PWA_APP_ICONS = [
|
||||||
@@ -67,11 +69,11 @@ All settings are optional, and the app will work fine with its internal defaults
|
|||||||
|
|
||||||
Add the progressive web app URLs to urls.py:
|
Add the progressive web app URLs to urls.py:
|
||||||
```python
|
```python
|
||||||
from django.urls import path, include
|
from django.urls import url, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
...
|
...
|
||||||
path('', include('pwa.urls')), # You MUST use an empty string as the URL prefix
|
url('', include('pwa.urls')), # You MUST use an empty string as the URL prefix
|
||||||
...
|
...
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
@@ -172,7 +174,7 @@ Adding Your Own Service Worker
|
|||||||
To add service worker functionality, you'll want to create a `serviceworker.js` or similarly named template in a template directory, and then point at it using the PWA_SERVICE_WORKER_PATH variable (PWA_APP_FETCH_URL is passed through).
|
To add service worker functionality, you'll want to create a `serviceworker.js` or similarly named template in a template directory, and then point at it using the PWA_SERVICE_WORKER_PATH variable (PWA_APP_FETCH_URL is passed through).
|
||||||
|
|
||||||
```python
|
```python
|
||||||
PWA_SERVICE_WORKER_PATH = 'my_app/serviceworker.js'
|
PWA_SERVICE_WORKER_PATH = os.path.join(BASE_DIR, 'my_app', 'serviceworker.js')
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ from django.conf import settings
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
# Path to the service worker implementation. Default implementation is empty.
|
# Path to the service worker implementation. Default implementation is empty.
|
||||||
PWA_SERVICE_WORKER_PATH = getattr(settings, 'PWA_SERVICE_WORKER_PATH', 'serviceworker.js')
|
PWA_SERVICE_WORKER_PATH = getattr(settings, 'PWA_SERVICE_WORKER_PATH',
|
||||||
|
os.path.join(os.path.abspath(os.path.dirname(__file__)), 'templates',
|
||||||
|
'serviceworker.js'))
|
||||||
# App parameters to include in manifest.json and appropriate meta tags
|
# App parameters to include in manifest.json and appropriate meta tags
|
||||||
PWA_APP_NAME = getattr(settings, 'PWA_APP_NAME', 'MyApp')
|
PWA_APP_NAME = getattr(settings, 'PWA_APP_NAME', 'MyApp')
|
||||||
PWA_APP_DESCRIPTION = getattr(settings, 'PWA_APP_DESCRIPTION', 'My Progressive Web App')
|
PWA_APP_DESCRIPTION = getattr(settings, 'PWA_APP_DESCRIPTION', 'My Progressive Web App')
|
||||||
@@ -12,6 +13,7 @@ PWA_APP_ROOT_URL = getattr(settings, 'PWA_APP_ROOT_URL', '/')
|
|||||||
PWA_APP_THEME_COLOR = getattr(settings, 'PWA_APP_THEME_COLOR', '#000')
|
PWA_APP_THEME_COLOR = getattr(settings, 'PWA_APP_THEME_COLOR', '#000')
|
||||||
PWA_APP_BACKGROUND_COLOR = getattr(settings, 'PWA_APP_BACKGROUND_COLOR', '#fff')
|
PWA_APP_BACKGROUND_COLOR = getattr(settings, 'PWA_APP_BACKGROUND_COLOR', '#fff')
|
||||||
PWA_APP_DISPLAY = getattr(settings, 'PWA_APP_DISPLAY', 'standalone')
|
PWA_APP_DISPLAY = getattr(settings, 'PWA_APP_DISPLAY', 'standalone')
|
||||||
|
PWA_APP_SCOPE = getattr(settings, 'PWA_APP_SCOPE', '/')
|
||||||
PWA_APP_ORIENTATION = getattr(settings, 'PWA_APP_ORIENTATION', 'any')
|
PWA_APP_ORIENTATION = getattr(settings, 'PWA_APP_ORIENTATION', 'any')
|
||||||
PWA_APP_START_URL = getattr(settings, 'PWA_APP_START_URL', '/')
|
PWA_APP_START_URL = getattr(settings, 'PWA_APP_START_URL', '/')
|
||||||
PWA_APP_FETCH_URL = getattr(settings, 'PWA_APP_FETCH_URL', '/')
|
PWA_APP_FETCH_URL = getattr(settings, 'PWA_APP_FETCH_URL', '/')
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"description": {{ PWA_APP_DESCRIPTION|js }},
|
"description": {{ PWA_APP_DESCRIPTION|js }},
|
||||||
"start_url": {{ PWA_APP_START_URL|js }},
|
"start_url": {{ PWA_APP_START_URL|js }},
|
||||||
"display": {{ PWA_APP_DISPLAY|js }},
|
"display": {{ PWA_APP_DISPLAY|js }},
|
||||||
|
"scope": {{ PWA_APP_SCOPE|js }},
|
||||||
"orientation": {{ PWA_APP_ORIENTATION|js }},
|
"orientation": {{ PWA_APP_ORIENTATION|js }},
|
||||||
"background_color": {{ PWA_APP_BACKGROUND_COLOR|js }},
|
"background_color": {{ PWA_APP_BACKGROUND_COLOR|js }},
|
||||||
"theme_color": {{ PWA_APP_THEME_COLOR|js }},
|
"theme_color": {{ PWA_APP_THEME_COLOR|js }},
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
// Initialize the service worker
|
// Initialize the service worker
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.register('/serviceworker.js', {
|
navigator.serviceWorker.register('/serviceworker.js', {
|
||||||
scope: '.'
|
scope: '{{ PWA_APP_SCOPE }}'
|
||||||
}).then(function (registration) {
|
}).then(function (registration) {
|
||||||
// Registration was successful
|
// Registration was successful
|
||||||
console.log('django-pwa: ServiceWorker registration successful with scope: ', registration.scope);
|
console.log('django-pwa: ServiceWorker registration successful with scope: ', registration.scope);
|
||||||
|
|||||||
10
pwa/urls.py
10
pwa/urls.py
@@ -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
|
# Serve up serviceworker.js and manifest.json at the root
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('serviceworker.js', ServiceWorker.as_view(), name='serviceworker'),
|
url('^serviceworker.js$', service_worker, name='serviceworker'),
|
||||||
path('manifest.json', Manifest.as_view(), name='manifest'),
|
url('^manifest.json$', manifest, name='manifest'),
|
||||||
path('offline', OfflineView.as_view(), name='offline')
|
url('^offline/$', offline, name='offline')
|
||||||
]
|
]
|
||||||
|
|||||||
32
pwa/views.py
32
pwa/views.py
@@ -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
|
from . import app_settings
|
||||||
|
|
||||||
|
|
||||||
class ServiceWorker(TemplateView):
|
def service_worker(request):
|
||||||
content_type = 'application/javascript'
|
response = HttpResponse(open(app_settings.PWA_SERVICE_WORKER_PATH).read(), content_type='application/javascript')
|
||||||
template_name = app_settings.PWA_SERVICE_WORKER_PATH
|
return response
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
kwargs['PWA_APP_FETCH_URL'] = app_settings.PWA_APP_FETCH_URL
|
|
||||||
return super().get_context_data(**kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class Manifest(TemplateView):
|
def manifest(request):
|
||||||
content_type = 'application/json'
|
return render(request, 'manifest.json', {
|
||||||
template_name = 'manifest.json'
|
setting_name: getattr(app_settings, setting_name)
|
||||||
|
for setting_name in dir(app_settings)
|
||||||
def get_context_data(self, **kwargs):
|
if setting_name.startswith('PWA_')
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
class OfflineView(TemplateView):
|
def offline(request):
|
||||||
template_name = "offline.html"
|
return render(request, "offline.html")
|
||||||
|
|||||||
8
setup.py
8
setup.py
@@ -17,12 +17,12 @@ except RuntimeError:
|
|||||||
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
|
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
|
||||||
|
|
||||||
install_requirements = [
|
install_requirements = [
|
||||||
"django>=2",
|
"django>=1.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='django-pwa',
|
name='django-pwa',
|
||||||
version='1.0.2',
|
version='1.0.5',
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
install_requires=install_requirements,
|
install_requires=install_requirements,
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
@@ -35,6 +35,10 @@ setup(
|
|||||||
classifiers=[
|
classifiers=[
|
||||||
'Environment :: Web Environment',
|
'Environment :: Web Environment',
|
||||||
'Framework :: Django',
|
'Framework :: Django',
|
||||||
|
'Framework :: Django :: 1.8',
|
||||||
|
'Framework :: Django :: 1.9',
|
||||||
|
'Framework :: Django :: 1.10',
|
||||||
|
'Framework :: Django :: 1.11',
|
||||||
'Framework :: Django :: 2.0',
|
'Framework :: Django :: 2.0',
|
||||||
'Framework :: Django :: 2.1',
|
'Framework :: Django :: 2.1',
|
||||||
'Intended Audience :: Developers',
|
'Intended Audience :: Developers',
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class AppSettingsTest(TestCase):
|
|||||||
'PWA_APP_ROOT_URL',
|
'PWA_APP_ROOT_URL',
|
||||||
'PWA_APP_THEME_COLOR',
|
'PWA_APP_THEME_COLOR',
|
||||||
'PWA_APP_BACKGROUND_COLOR',
|
'PWA_APP_BACKGROUND_COLOR',
|
||||||
|
'PWA_APP_SCOPE',
|
||||||
'PWA_APP_DISPLAY',
|
'PWA_APP_DISPLAY',
|
||||||
'PWA_APP_ORIENTATION',
|
'PWA_APP_ORIENTATION',
|
||||||
'PWA_APP_START_URL',
|
'PWA_APP_START_URL',
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class CreateMetaTemplateTagTest(TestCase):
|
|||||||
'<script type="text/javascript">',
|
'<script type="text/javascript">',
|
||||||
"if ('serviceWorker' in navigator) {",
|
"if ('serviceWorker' in navigator) {",
|
||||||
"navigator.serviceWorker.register('/serviceworker.js', {",
|
"navigator.serviceWorker.register('/serviceworker.js', {",
|
||||||
"scope: '.'",
|
"scope: '/'",
|
||||||
"}).then(function (registration) {",
|
"}).then(function (registration) {",
|
||||||
"console.log('django-pwa: ServiceWorker registration successful with scope: ', registration.scope);",
|
"console.log('django-pwa: ServiceWorker registration successful with scope: ', registration.scope);",
|
||||||
"}, function (err) {",
|
"}, function (err) {",
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class ManifestTest(TestCase):
|
|||||||
'"description":',
|
'"description":',
|
||||||
'"start_url":',
|
'"start_url":',
|
||||||
'"display":',
|
'"display":',
|
||||||
|
'"scope":',
|
||||||
'"background_color":',
|
'"background_color":',
|
||||||
'"theme_color":',
|
'"theme_color":',
|
||||||
'"orientation":',
|
'"orientation":',
|
||||||
|
|||||||
8
tox.ini
8
tox.ini
@@ -1,7 +1,6 @@
|
|||||||
[tox]
|
[tox]
|
||||||
envlist =
|
envlist =
|
||||||
py35-django{20}
|
py35-django{18,19,110,111,20,21}
|
||||||
py35-django{21}
|
|
||||||
py36-django{20}
|
py36-django{20}
|
||||||
py36-django{21}
|
py36-django{21}
|
||||||
py37-django{20}
|
py37-django{20}
|
||||||
@@ -17,6 +16,11 @@ basepython =
|
|||||||
py36: python3.6
|
py36: python3.6
|
||||||
py37: python3.7
|
py37: python3.7
|
||||||
deps =
|
deps =
|
||||||
|
django18: django==1.8
|
||||||
|
django19: django==1.9
|
||||||
|
django110: django==1.10
|
||||||
|
django111: django==1.11
|
||||||
django20: Django==2.0
|
django20: Django==2.0
|
||||||
django21: Django==2.1
|
django21: Django==2.1
|
||||||
|
|
||||||
pypandoc==1.3.3
|
pypandoc==1.3.3
|
||||||
Reference in New Issue
Block a user