2017-10-27 23:29:07 -04:00
|
|
|
from django.http import JsonResponse
|
2017-10-28 00:05:54 -04:00
|
|
|
from django.urls import reverse
|
2017-10-27 23:29:07 -04:00
|
|
|
from favicon.models import FaviconImg
|
|
|
|
from lemoncurry import utils
|
2017-10-28 00:05:54 -04:00
|
|
|
from lemoncurry.theme import color
|
2017-10-27 23:29:07 -04:00
|
|
|
from urllib.parse import urljoin
|
2017-10-28 00:05:54 -04:00
|
|
|
from textwrap import shorten
|
2017-10-27 23:29:07 -04:00
|
|
|
|
|
|
|
|
|
|
|
def manifest(request):
|
2017-10-28 00:05:54 -04:00
|
|
|
base = utils.origin(request)
|
|
|
|
start_url = reverse('home:index') + '?utm_source=homescreen'
|
|
|
|
|
2017-10-27 23:29:07 -04:00
|
|
|
app = {
|
2017-10-28 21:12:39 -04:00
|
|
|
'name': request.site.name,
|
|
|
|
'short_name': shorten(request.site.name, width=20, placeholder=''),
|
2017-10-28 00:05:54 -04:00
|
|
|
|
|
|
|
'display': 'browser',
|
|
|
|
'start_url': urljoin(base, start_url),
|
|
|
|
|
|
|
|
'background_color': color(0),
|
|
|
|
'theme_color': color(2),
|
2017-10-27 23:29:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
rels = ('shortcut icon', 'apple-touch-icon')
|
|
|
|
icons = FaviconImg.objects.filter(
|
|
|
|
faviconFK__isFavicon=True,
|
|
|
|
rel__in=rels,
|
|
|
|
).order_by('size')
|
|
|
|
app['icons'] = [{
|
|
|
|
'type': 'image/png',
|
2017-10-28 00:05:54 -04:00
|
|
|
'sizes': '{0}x{0}'.format(icon.size),
|
|
|
|
'src': urljoin(base, icon.faviconImage.url),
|
2017-10-27 23:29:07 -04:00
|
|
|
} for icon in icons]
|
|
|
|
|
|
|
|
return JsonResponse(app, content_type='application/manifest+json')
|