[FEAT] Enable PWA functionality

This commit is contained in:
2023-01-20 17:46:21 +00:00
parent 0d03678674
commit e15de01cfa
8 changed files with 82 additions and 4 deletions

View File

@@ -146,6 +146,7 @@ THIRD_PARTY_APPS = [
'post_office', 'post_office',
'bootstrap_datepicker_plus', 'bootstrap_datepicker_plus',
'hijack', 'hijack',
'pwa',
] ]
FIRST_PARTY_APPS = [ FIRST_PARTY_APPS = [
@@ -348,9 +349,17 @@ CONSTANCE_CONFIG = {
'RELATIONSHIP_FORM_HELP': ( 'RELATIONSHIP_FORM_HELP': (
'', '',
'Help text to display at the top of relationship forms.'), 'Help text to display at the top of relationship forms.'),
'DEPLOYMENT_URL': ( 'SITE_URL': (
'http://localhost', 'http://localhost',
'URL at which this mapper tool is accessible - do NOT include a trailing forward slash'), 'URL at which this mapper tool is accessible - do NOT include a trailing forward slash'),
'SITE_ICON': (
'icon.png',
'Site icon',
'image_field'),
'SITE_ICON_192x192': (
'icon-192x192.png',
'Site icon',
'image_field'),
'PARENT_PROJECT_NAME': ( 'PARENT_PROJECT_NAME': (
'', '',
'Parent project name'), 'Parent project name'),
@@ -449,7 +458,9 @@ CONSTANCE_CONFIG_FIELDSETS = {
'RELATIONSHIP_FORM_HELP', 'RELATIONSHIP_FORM_HELP',
), ),
'Deployment': ( 'Deployment': (
'DEPLOYMENT_URL', 'SITE_URL',
'SITE_ICON',
'SITE_ICON_192x192',
), ),
} # yapf: disable } # yapf: disable
@@ -503,6 +514,40 @@ BOOTSTRAP_DATEPICKER_PLUS = {
} }
} }
# PWA settings
PWA_SERVICE_WORKER_PATH = BASE_DIR.joinpath('static/js', 'serviceworker.js')
PWA_APP_NAME = 'networkmapper'
PWA_APP_DESCRIPTION = "Network Mapper"
PWA_APP_THEME_COLOR = '#000000'
PWA_APP_BACKGROUND_COLOR = '#ffffff'
PWA_APP_DISPLAY = 'standalone'
PWA_APP_SCOPE = '/'
PWA_APP_ORIENTATION = 'any'
PWA_APP_START_URL = '/'
PWA_APP_STATUS_BAR_COLOR = 'default'
PWA_APP_ICONS = [
{
'src': 'media/icon-192x192.png',
'sizes': '160x160'
}
]
PWA_APP_ICONS_APPLE = [
{
'src': 'media/icon-192x192.png',
'sizes': '160x160'
}
]
PWA_APP_SPLASH_SCREEN = [
{
'src': 'media/icon.png',
'media': '(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)'
}
]
PWA_APP_DIR = 'ltr'
PWA_APP_LANG = 'en-GB'
# Database default automatic primary key # Database default automatic primary key
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

View File

@@ -0,0 +1,24 @@
var staticCacheName = "djangopwa-v1";
self.addEventListener("install", function (event) {
event.waitUntil(
caches.open(staticCacheName).then(function (cache) {
return cache.addAll([""]);
})
);
});
self.addEventListener("fetch", function (event) {
var requestUrl = new URL(event.request.url);
if (requestUrl.origin === location.origin) {
if (requestUrl.pathname === "/") {
event.respondWith(caches.match(""));
return;
}
}
event.respondWith(
caches.match(event.request).then(function (response) {
return response || fetch(event.request);
})
);
});

View File

@@ -6,6 +6,11 @@
{% endif %} {% endif %}
<html lang="{{ LANGUAGE_CODE|default:'en_us' }}"> <html lang="{{ LANGUAGE_CODE|default:'en_us' }}">
{% load pwa %}
{% progressive_web_app_meta %}
<link rel="manifest" href="manifest.json">
<head> <head>
<!-- Required meta tags --> <!-- Required meta tags -->
<meta charset="utf-8"> <meta charset="utf-8">

View File

@@ -54,4 +54,7 @@ urlpatterns = [
path('', path('',
include('activities.urls')), include('activities.urls')),
path('',
include('pwa.urls')),
] # yapf: disable ] # yapf: disable

BIN
media/icon-192x192.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

BIN
media/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -7,8 +7,8 @@
"created": "2020-04-27T12:13:30.448Z", "created": "2020-04-27T12:13:30.448Z",
"last_updated": "2020-04-27T14:45:27.152Z", "last_updated": "2020-04-27T14:45:27.152Z",
"subject": "Welcome to {{config.PROJECT_LONG_NAME}}", "subject": "Welcome to {{config.PROJECT_LONG_NAME}}",
"content": "Dear user,\r\n\r\nWelcome to {{ config.PROJECT_LONG_NAME }}. You can set your password at {{ config.DEPLOYMENT_URL }}/password_reset/.\r\n\r\nThanks,\r\n\r\nThe {{ config.PROJECT_SHORT_NAME }} team", "content": "Dear user,\r\n\r\nWelcome to {{ config.PROJECT_LONG_NAME }}. You can set your password at {{ config.SITE_URL }}/password_reset/.\r\n\r\nThanks,\r\n\r\nThe {{ config.PROJECT_SHORT_NAME }} team",
"html_content": "<h1>{{ config.PROJECT_LONG_NAME }}</h1><br/><p>Dear user,</p><br/><p>Welcome to {{ config.PROJECT_LONG_NAME }}. You can set your password <a href='{{ config.DEPLOYMENT_URL }}/password_reset/'>here</a>.</p><br/><p>Thanks,</p><p>The {{ config.PROJECT_SHORT_NAME }} team</p>", "html_content": "<h1>{{ config.PROJECT_LONG_NAME }}</h1><br/><p>Dear user,</p><br/><p>Welcome to {{ config.PROJECT_LONG_NAME }}. You can set your password <a href='{{ config.SITE_URL }}/password_reset/'>here</a>.</p><br/><p>Thanks,</p><p>The {{ config.PROJECT_SHORT_NAME }} team</p>",
"language": "", "language": "",
"default_template": null "default_template": null
} }

View File

@@ -12,6 +12,7 @@ django-filter==22.1
django-hijack==3.2.6 django-hijack==3.2.6
django-picklefield==3.1 django-picklefield==3.1
django-post-office==3.6.3 django-post-office==3.6.3
django-pwa==1.1.0
django-select2==8.0.0 django-select2==8.0.0
django-settings-export==1.2.1 django-settings-export==1.2.1
djangorestframework==3.14.0 djangorestframework==3.14.0