views.py 2.03 KB
Newer Older
1
2
from rest_framework import viewsets
from rest_framework.response import Response
Aymeric Barantal's avatar
Aymeric Barantal committed
3

okhin's avatar
okhin committed
4
5
6
7
8
9
from picampaign.organization.models import (FeedbackCategory, Organization,
                                            GroupType, Group)
from picampaign.organization.serializers import (CategorySerializer,
                                                GroupTypeSerializer,
                                                GroupSerializer,
                                                OrganizationSerializer)
10
11
12
13
14
15
16


class CategoryViewSet(viewsets.ViewSet):

    queryset = FeedbackCategory.objects.all()
    serializer_class = CategorySerializer

17
18
19
    def list(self, request, campaign_pk):
        orga = Organization.objects.filter(campaigns__id=campaign_pk)[0]
        categories = self.queryset.filter(organization_id=orga.id)
20
21
        serializer = self.serializer_class(categories, many=True)
        return Response(serializer.data)
okhin's avatar
okhin committed
22
23
24
25
26
27
28
29
30
31
32

class GroupTypeViewSet(viewsets.ViewSet):

    queryset = GroupType.objects.all()
    serializer_class = GroupTypeSerializer

    def list(self, request, campaign_pk):
        orga = Organization.objects.filter(campaigns__id=campaign_pk)[0]
        grouptype = self.queryset.filter(organization_id=orga.id)
        serializer = self.serializer_class(grouptype, many=True)
        return Response(serializer.data)
okhin's avatar
okhin committed
33
34
35
36
37
38
39
40
41
42
43
44

class GroupViewSet(viewsets.ViewSet):

    queryset = Group.objects.all()
    serializer_class = GroupSerializer

    def list(self, request, campaign_pk):
        orga = Organization.objects.filter(campaigns__id=campaign_pk)[0]
        groups = self.queryset.filter(type__organization_id=orga.id)
        serializer = self.serializer_class(groups, many=True)
        return Response(serializer.data)

okhin's avatar
okhin committed
45
46
47
48
49
50
51
52
53
54
class OrganizationViewSet(viewsets.ViewSet):

    queryset = Organization.objects.all()
    serializer_class = OrganizationSerializer

    def list(self, request, campaign_pk):
        orga = Organization.objects.filter(campaigns__id=campaign_pk)[0]
        serializer = self.serializer_class(orga)
        return Response(serializer.data)