-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathviews.py
57 lines (49 loc) · 2.02 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from django.http import JsonResponse
from django.shortcuts import get_object_or_404, redirect
from django.utils import translation
from django.utils.translation import gettext_lazy as _
from django.views import View
from django.views.generic import TemplateView
from .models import ManifestSettings
class ServiceWorkerView(TemplateView):
template_name = "sw.js"
content_type = "application/javascript"
name = "sw.js"
def get_manifest(request):
language = translation.get_language()
manifest = get_object_or_404(ManifestSettings, language=language)
response = {
"name": manifest.name,
"short_name": manifest.short_name,
"scope": manifest.scope,
"background_color": manifest.background_color,
"theme_color": manifest.theme_color,
"description": manifest.description,
"lang": manifest.language,
"start_url": manifest.start_url,
"display": manifest.display,
"icons": [
{
"src": f"{manifest.icon_96_96.file.url}",
"type": f"image/{manifest.icon_96_96.title.split('.')[1]}",
"sizes": f"{manifest.icon_96_96.height}x{manifest.icon_96_96.width}",
},
{
"src": f"{manifest.icon_512_512.file.url}",
"type": f"image/{manifest.icon_512_512.title.split('.')[1]}",
"sizes": f"{manifest.icon_512_512.height}x{manifest.icon_512_512.width}",
},
{
"src": f"{manifest.icon_192_192.file.url}",
"type": f"image/{manifest.icon_192_192.title.split('.')[1]}",
"sizes": f"{manifest.icon_192_192.height}x{manifest.icon_192_192.width}",
"purpose": "any maskable",
},
],
}
http_response = JsonResponse(response)
http_response['Content-Disposition'] = 'attachment; filename="manifest.json"'
return http_response
class LogoutRedirectHackView(View):
def get(self, request):
return redirect(f'/{request.LANGUAGE_CODE}/')