1 Commits

Author SHA1 Message Date
Embrace
2326895768 Restored support to oldest Django versions 2019-02-01 10:16:52 -02:00
6 changed files with 37 additions and 33 deletions

View File

@@ -5,6 +5,7 @@ django-pwa
[![codecov](https://codecov.io/gh/silviolleite/django-pwa/branch/master/graph/badge.svg)](https://codecov.io/gh/silviolleite/django-pwa)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/django-pwa.svg)](https://pypi.org/project/django-pwa/)
[![PyPI - Downloads](https://img.shields.io/pypi/v/django-pwa.svg)](https://pypi.org/project/django-pwa)
[![PyPI - Downloads](https://img.shields.io/pypi/djversions/django-pwa.svg)](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.
@@ -67,11 +68,11 @@ All settings are optional, and the app will work fine with its internal defaults
Add the progressive web app URLs to urls.py:
```python
from django.urls import path, include
from django.urls import url, include
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 +173,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).
```python
PWA_SERVICE_WORKER_PATH = 'my_app/serviceworker.js'
PWA_SERVICE_WORKER_PATH = os.path.join(BASE_DIR, 'my_app', 'serviceworker.js')
```

View File

@@ -3,8 +3,9 @@ from django.conf import settings
import os
# 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
PWA_APP_NAME = getattr(settings, 'PWA_APP_NAME', 'MyApp')
PWA_APP_DESCRIPTION = getattr(settings, 'PWA_APP_DESCRIPTION', 'My Progressive Web App')

View File

@@ -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')
]

View File

@@ -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")

View File

@@ -17,12 +17,12 @@ except RuntimeError:
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
install_requirements = [
"django>=2",
"django>=1.8",
]
setup(
name='django-pwa',
version='1.0.2',
version='1.0.3',
packages=find_packages(),
install_requires=install_requirements,
include_package_data=True,
@@ -35,6 +35,10 @@ setup(
classifiers=[
'Environment :: Web Environment',
'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.1',
'Intended Audience :: Developers',

View File

@@ -1,7 +1,6 @@
[tox]
envlist =
py35-django{20}
py35-django{21}
py35-django{18,19,110,111,20,21}
py36-django{20}
py36-django{21}
py37-django{20}
@@ -17,6 +16,11 @@ basepython =
py36: python3.6
py37: python3.7
deps =
django18: django==1.8
django19: django==1.9
django110: django==1.10
django111: django==1.11
django20: Django==2.0
django21: Django==2.1
pypandoc==1.3.3