views.py 1.54 KB
Newer Older
1
2
3
4
from rest_framework import views
from rest_framework.response import Response

from dynamic_preferences.api import serializers
5
from dynamic_preferences.api import viewsets as preferences_viewsets
6
7
from dynamic_preferences.registries import global_preferences_registry

8
9
10
from funkwhale_api.common import preferences

from . import nodeinfo
11
12
from . import stats

13

14
15
16
17
18
NODEINFO_2_CONTENT_TYPE = (
    'application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8'  # noqa
)


19
20
21
22
class AdminSettings(preferences_viewsets.GlobalPreferencesViewSet):
    pagination_class = None


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class InstanceSettings(views.APIView):
    permission_classes = []
    authentication_classes = []

    def get(self, request, *args, **kwargs):
        manager = global_preferences_registry.manager()
        manager.all()
        all_preferences = manager.model.objects.all().order_by(
            'section', 'name'
        )
        api_preferences = [
            p
            for p in all_preferences
            if getattr(p.preference, 'show_in_api', False)
        ]
        data = serializers.GlobalPreferenceSerializer(
            api_preferences, many=True).data
        return Response(data, status=200)
41
42


43
class NodeInfo(views.APIView):
44
45
46
47
    permission_classes = []
    authentication_classes = []

    def get(self, request, *args, **kwargs):
48
49
50
        if not preferences.get('instance__nodeinfo_enabled'):
            return Response(status=404)
        data = nodeinfo.get()
51
52
        return Response(
            data, status=200, content_type=NODEINFO_2_CONTENT_TYPE)