viewsets.py 843 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
from rest_framework import viewsets

from mailinglists import services
from mailinglists.api.permissions import MailingListPermission
from mailinglists.api.serializers import MailingListSerializer
from mailinglists.models import MailingList


class MailingListViewset(viewsets.ReadOnlyModelViewSet):
Joren Vrancken's avatar
Joren Vrancken committed
10
11
    """Viewswet class for mailing lists."""

12
13
14
15
16
    permission_classes = [MailingListPermission]
    queryset = MailingList.objects.all()
    serializer_class = MailingListSerializer

    def list(self, request, *args, **kwargs):
Joren Vrancken's avatar
Joren Vrancken committed
17
        """Return response with a list of serialized mailing lists."""
18
19
20
21
22
        response = super().list(request, *args, **kwargs)
        automatic_lists = services.get_automatic_lists()
        if automatic_lists is not None:
            response.data = list(response.data) + automatic_lists
        return response