summaryrefslogtreecommitdiffstats
path: root/core/views.py
blob: 889fa27fa0edb7c192b41ad2a578dcbcb51304a5 (plain)
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
58
59
from django.http import JsonResponse
from django.templatetags.static import static
from django.views.generic import TemplateView, View

from activities.views.timelines import Home
from users.models import Identity


def homepage(request):
    if request.user.is_authenticated:
        return Home.as_view()(request)
    else:
        return LoggedOutHomepage.as_view()(request)


class LoggedOutHomepage(TemplateView):

    template_name = "index.html"

    def get_context_data(self):
        return {
            "identities": Identity.objects.filter(
                local=True,
                discoverable=True,
            ).order_by("-created")[:20],
        }


class AppManifest(View):
    """
    Serves a PWA manifest file. This is a view as we want to drive some
    items from settings.
    """

    def get(self, request):
        return JsonResponse(
            {
                "$schema": "https://json.schemastore.org/web-manifest-combined.json",
                "name": "Takahē",
                "short_name": "Takahē",
                "start_url": "/",
                "display": "standalone",
                "background_color": "#26323c",
                "theme_color": "#26323c",
                "description": "An ActivityPub server",
                "icons": [
                    {
                        "src": static("img/icon-128.png"),
                        "sizes": "128x128",
                        "type": "image/png",
                    },
                    {
                        "src": static("img/icon-1024.png"),
                        "sizes": "1024x1024",
                        "type": "image/png",
                    },
                ],
            }
        )