Commit 8e9376a8 authored by okhin's avatar okhin

Adding a group type view

parent ae79abf4
Pipeline #738 passed with stages
in 1 minute and 9 seconds
from picampaign.organization.models import FeedbackCategory, Group
from picampaign.organization.models import FeedbackCategory, Group, GroupType
from rest_framework import serializers
......@@ -15,3 +15,8 @@ class GroupSerializer(serializers.ModelSerializer):
class Meta:
model = Group
fields = ('type', 'name', 'media')
class GroupTypeSerializer(serializers.ModelSerializer):
class Meta:
model = GroupType
fields = ('id', 'name')
......@@ -79,6 +79,29 @@ class CategoryViewSet(TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b'[{"id":1,"name":"Feedback"}]')
class GroupTypeViewSetTest(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
)
def test_grouptype_viewset(self):
client = APIClient()
response = client.get('/campaigns/%(cid)s/grouptypes/' % {'cid': self.campaign.id}, format='json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b'[{"id":1,"name":"comittee"}]')
class MockRequest(object):
pass
......
from rest_framework import viewsets
from rest_framework.response import Response
from picampaign.organization.models import FeedbackCategory, Organization
from picampaign.organization.serializers import CategorySerializer
from picampaign.organization.models import FeedbackCategory, Organization, GroupType
from picampaign.organization.serializers import CategorySerializer, GroupTypeSerializer
class CategoryViewSet(viewsets.ViewSet):
......@@ -15,3 +15,14 @@ class CategoryViewSet(viewsets.ViewSet):
categories = self.queryset.filter(organization_id=orga.id)
serializer = self.serializer_class(categories, many=True)
return Response(serializer.data)
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)
......@@ -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
from picampaign.organization.views import CategoryViewSet, GroupTypeViewSet
router = routers.SimpleRouter()
router.register(r'campaigns', CampaignViewSet)
......@@ -16,6 +16,7 @@ campaign_router.register(r'contacts', CampaignContactViewSet)
campaign_router.register(r'arguments', ArgumentaryViewSet)
campaign_router.register(r'categories', CategoryViewSet)
campaign_router.register(r'feedbacks', FeedbackViewSet)
campaign_router.register(r'grouptypes', GroupTypeViewSet)
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