Commit 35a4b69f authored by okhin's avatar okhin

Adding the groups view

parent 8e9376a8
Pipeline #740 passed with stages
in 1 minute and 7 seconds
......@@ -14,7 +14,7 @@ class GroupSerializer(serializers.ModelSerializer):
class Meta:
model = Group
fields = ('type', 'name', 'media')
fields = ('id', 'type', 'name', 'media')
class GroupTypeSerializer(serializers.ModelSerializer):
class Meta:
......
......@@ -79,6 +79,33 @@ class CategoryViewSet(TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b'[{"id":1,"name":"Feedback"}]')
class GroupViewSetTest(TestCase):
def setUp(self):
self.organization = Organization.objects.create(
name='Majestic 12',
sip_key='majestic-12'
)
self.campaign = Campaign.objects.create(
title='Test Campaign',
start_date='2000-01-01',
end_date='2100-12-31',
organization=self.organization
)
self.grouptype = GroupType.objects.create(
name='comittee',
organization = self.organization
)
self.group = Group.objects.create(
name="INTA",
type=self.grouptype
)
def test_grouptype_viewset(self):
client = APIClient()
response = client.get('/campaigns/%(cid)s/groups/' % {'cid': self.campaign.id}, format='json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b'[{"id":1,"type":"comittee","name":"INTA","media":""}]')
class GroupTypeViewSetTest(TestCase):
def setUp(self):
self.organization = Organization.objects.create(
......
from rest_framework import viewsets
from rest_framework.response import Response
from picampaign.organization.models import FeedbackCategory, Organization, GroupType
from picampaign.organization.serializers import CategorySerializer, GroupTypeSerializer
from picampaign.organization.models import FeedbackCategory, Organization, GroupType, Group
from picampaign.organization.serializers import CategorySerializer, GroupTypeSerializer, GroupSerializer
class CategoryViewSet(viewsets.ViewSet):
......@@ -26,3 +26,15 @@ class GroupTypeViewSet(viewsets.ViewSet):
grouptype = self.queryset.filter(organization_id=orga.id)
serializer = self.serializer_class(grouptype, many=True)
return Response(serializer.data)
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)
......@@ -5,7 +5,7 @@ from rest_framework_nested import routers
from picampaign.campaign.views import (CampaignViewSet, CampaignContactViewSet,
ArgumentaryViewSet)
from picampaign.feedback.views import FeedbackViewSet
from picampaign.organization.views import CategoryViewSet, GroupTypeViewSet
from picampaign.organization.views import CategoryViewSet, GroupTypeViewSet, GroupViewSet
router = routers.SimpleRouter()
router.register(r'campaigns', CampaignViewSet)
......@@ -17,6 +17,7 @@ campaign_router.register(r'arguments', ArgumentaryViewSet)
campaign_router.register(r'categories', CategoryViewSet)
campaign_router.register(r'feedbacks', FeedbackViewSet)
campaign_router.register(r'grouptypes', GroupTypeViewSet)
campaign_router.register(r'groups', GroupViewSet)
urlpatterns = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment