Commit bce2c38c authored by okhin's avatar okhin

Adding a view for organizations

parent 72d15ff6
Pipeline #821 passed with stages
in 50 seconds
from picampaign.organization.models import FeedbackCategory, Group, GroupType from picampaign.organization.models import FeedbackCategory, Group, GroupType, Organization
from rest_framework import serializers from rest_framework import serializers
...@@ -16,7 +16,14 @@ class GroupSerializer(serializers.ModelSerializer): ...@@ -16,7 +16,14 @@ class GroupSerializer(serializers.ModelSerializer):
model = Group model = Group
fields = ('id', 'type', 'name', 'media') fields = ('id', 'type', 'name', 'media')
class GroupTypeSerializer(serializers.ModelSerializer): class GroupTypeSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = GroupType model = GroupType
fields = ('id', 'name') fields = ('id', 'name')
class OrganizationSerializer(serializers.ModelSerializer):
class Meta:
model = Organization
fields = ('id', 'name', 'description', 'website', 'logo',)
...@@ -56,6 +56,25 @@ class FeedbackCategoryTest(TestCase): ...@@ -56,6 +56,25 @@ class FeedbackCategoryTest(TestCase):
) )
self.assertEqual(str(feedbackcategory), feedbackcategory.name) self.assertEqual(str(feedbackcategory), feedbackcategory.name)
class OrganizationViewSet(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
)
def test_organization_viewset(self):
client = APIClient()
response = client.get('/campaigns/%(cid)s/organization/' % {'cid': self.campaign.id}, format='json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b'{"id":1,"name":"Majestic 12","description":"","website":"","logo":null}')
class CategoryViewSet(TestCase): class CategoryViewSet(TestCase):
def setUp(self): def setUp(self):
self.organization = Organization.objects.create( self.organization = Organization.objects.create(
......
from rest_framework import viewsets from rest_framework import viewsets
from rest_framework.response import Response from rest_framework.response import Response
from picampaign.organization.models import FeedbackCategory, Organization, GroupType, Group from picampaign.organization.models import (FeedbackCategory, Organization,
from picampaign.organization.serializers import CategorySerializer, GroupTypeSerializer, GroupSerializer GroupType, Group)
from picampaign.organization.serializers import (CategorySerializer,
GroupTypeSerializer,
GroupSerializer,
OrganizationSerializer)
class CategoryViewSet(viewsets.ViewSet): class CategoryViewSet(viewsets.ViewSet):
...@@ -38,3 +42,13 @@ class GroupViewSet(viewsets.ViewSet): ...@@ -38,3 +42,13 @@ class GroupViewSet(viewsets.ViewSet):
serializer = self.serializer_class(groups, many=True) serializer = self.serializer_class(groups, many=True)
return Response(serializer.data) return Response(serializer.data)
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)
...@@ -5,7 +5,8 @@ from rest_framework_nested import routers ...@@ -5,7 +5,8 @@ from rest_framework_nested import routers
from picampaign.campaign.views import (CampaignViewSet, CampaignContactViewSet, from picampaign.campaign.views import (CampaignViewSet, CampaignContactViewSet,
ArgumentaryViewSet) ArgumentaryViewSet)
from picampaign.feedback.views import FeedbackViewSet from picampaign.feedback.views import FeedbackViewSet
from picampaign.organization.views import CategoryViewSet, GroupTypeViewSet, GroupViewSet from picampaign.organization.views import (CategoryViewSet, GroupTypeViewSet,
GroupViewSet, OrganizationViewSet)
router = routers.SimpleRouter() router = routers.SimpleRouter()
router.register(r'campaigns', CampaignViewSet) router.register(r'campaigns', CampaignViewSet)
...@@ -18,6 +19,7 @@ campaign_router.register(r'categories', CategoryViewSet) ...@@ -18,6 +19,7 @@ campaign_router.register(r'categories', CategoryViewSet)
campaign_router.register(r'feedbacks', FeedbackViewSet) campaign_router.register(r'feedbacks', FeedbackViewSet)
campaign_router.register(r'grouptypes', GroupTypeViewSet) campaign_router.register(r'grouptypes', GroupTypeViewSet)
campaign_router.register(r'groups', GroupViewSet) campaign_router.register(r'groups', GroupViewSet)
campaign_router.register(r'organization', OrganizationViewSet)
urlpatterns = [ 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