diff --git a/combo/apps/pwa/migrations/0004_pwasettings_application_icon.py b/combo/apps/pwa/migrations/0004_pwasettings_application_icon.py new file mode 100644 index 00000000..453d4759 --- /dev/null +++ b/combo/apps/pwa/migrations/0004_pwasettings_application_icon.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.12 on 2019-01-04 19:36 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('pwa', '0003_pwanavigationentry'), + ] + + operations = [ + migrations.AddField( + model_name='pwasettings', + name='application_icon', + field=models.FileField(blank=True, help_text='Should be a square of at least 512\xd7512 pixels.', null=True, upload_to=b'pwa', verbose_name='Application Icon'), + ), + ] diff --git a/combo/apps/pwa/models.py b/combo/apps/pwa/models.py index 8f53df5f..47070827 100644 --- a/combo/apps/pwa/models.py +++ b/combo/apps/pwa/models.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -* +# # combo - content management system # Copyright (C) 2015-2018 Entr'ouvert # @@ -33,6 +35,13 @@ from combo import utils class PwaSettings(models.Model): + APPLICATION_ICON_SIZES = ['%sx%s' % (x, x) for x in (48, 96, 192, 256, 512)] + application_icon = models.FileField( + verbose_name=_('Application Icon'), + help_text=_(u'Should be a square of at least 512×512 pixels.'), + upload_to='pwa', + blank=True, + null=True) offline_text = RichTextField( verbose_name=_('Offline Information Text'), default=_('You are currently offline.'), diff --git a/combo/apps/pwa/templates/combo/manifest.json b/combo/apps/pwa/templates/combo/manifest.json index 1fd85fe8..bbb71d3d 100644 --- a/combo/apps/pwa/templates/combo/manifest.json +++ b/combo/apps/pwa/templates/combo/manifest.json @@ -1,4 +1,4 @@ -{% load static %}{ +{% load static thumbnail %}{ "name": "{% firstof global_title "Compte Citoyen" %}", "short_name": "{% firstof global_title "Compte Citoyen" %}", "start_url": "{% firstof pwa_start_url "/" %}", @@ -8,6 +8,17 @@ {% endif %} {% block icons %} "icons": [ + {% if pwa_settings.application_icon %} + {% for icon_size in pwa_settings.APPLICATION_ICON_SIZES %} + { + "sizes": "{{ icon_size }}", + {% thumbnail pwa_settings.application_icon icon_size crop='center' format='PNG' as im %} + "src": "{{ site_base }}{{ im.url }}", + {% endthumbnail %} + "type": "image/png" + }{% if not forloop.last %},{% endif %} + {% endfor %} + {% else %} {% for icon_size in icon_sizes %} { "sizes": "{{ icon_size }}x{{ icon_size }}", @@ -15,6 +26,7 @@ "type": "image/png" }{% if not forloop.last %},{% endif %} {% endfor %} + {% endif %} ], {% endblock %} {% block extra %} diff --git a/combo/apps/pwa/templates/combo/pwa/manager_home.html b/combo/apps/pwa/templates/combo/pwa/manager_home.html index 1d709b41..d9d2d1cb 100644 --- a/combo/apps/pwa/templates/combo/pwa/manager_home.html +++ b/combo/apps/pwa/templates/combo/pwa/manager_home.html @@ -1,5 +1,5 @@ {% extends "combo/pwa/manager_base.html" %} -{% load i18n static %} +{% load i18n thumbnail %} {% block content %}