Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
piphone
campaign
Commits
bce2c38c
Commit
bce2c38c
authored
Jan 31, 2017
by
okhin
Browse files
Adding a view for organizations
parent
72d15ff6
Pipeline
#821
passed with stages
in 50 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
picampaign/organization/serializers.py
View file @
bce2c38c
from
picampaign.organization.models
import
FeedbackCategory
,
Group
,
GroupType
from
picampaign.organization.models
import
FeedbackCategory
,
Group
,
GroupType
,
Organization
from
rest_framework
import
serializers
...
...
@@ -16,7 +16,14 @@ class GroupSerializer(serializers.ModelSerializer):
model
=
Group
fields
=
(
'id'
,
'type'
,
'name'
,
'media'
)
class
GroupTypeSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
GroupType
fields
=
(
'id'
,
'name'
)
class
OrganizationSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Organization
fields
=
(
'id'
,
'name'
,
'description'
,
'website'
,
'logo'
,)
picampaign/organization/tests.py
View file @
bce2c38c
...
...
@@ -56,6 +56,25 @@ class FeedbackCategoryTest(TestCase):
)
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
):
def
setUp
(
self
):
self
.
organization
=
Organization
.
objects
.
create
(
...
...
picampaign/organization/views.py
View file @
bce2c38c
from
rest_framework
import
viewsets
from
rest_framework.response
import
Response
from
picampaign.organization.models
import
FeedbackCategory
,
Organization
,
GroupType
,
Group
from
picampaign.organization.serializers
import
CategorySerializer
,
GroupTypeSerializer
,
GroupSerializer
from
picampaign.organization.models
import
(
FeedbackCategory
,
Organization
,
GroupType
,
Group
)
from
picampaign.organization.serializers
import
(
CategorySerializer
,
GroupTypeSerializer
,
GroupSerializer
,
OrganizationSerializer
)
class
CategoryViewSet
(
viewsets
.
ViewSet
):
...
...
@@ -38,3 +42,13 @@ class GroupViewSet(viewsets.ViewSet):
serializer
=
self
.
serializer_class
(
groups
,
many
=
True
)
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
)
picampaign/urls.py
View file @
bce2c38c
...
...
@@ -5,7 +5,8 @@ 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
,
GroupViewSet
from
picampaign.organization.views
import
(
CategoryViewSet
,
GroupTypeViewSet
,
GroupViewSet
,
OrganizationViewSet
)
router
=
routers
.
SimpleRouter
()
router
.
register
(
r
'campaigns'
,
CampaignViewSet
)
...
...
@@ -18,6 +19,7 @@ campaign_router.register(r'categories', CategoryViewSet)
campaign_router
.
register
(
r
'feedbacks'
,
FeedbackViewSet
)
campaign_router
.
register
(
r
'grouptypes'
,
GroupTypeViewSet
)
campaign_router
.
register
(
r
'groups'
,
GroupViewSet
)
campaign_router
.
register
(
r
'organization'
,
OrganizationViewSet
)
urlpatterns
=
[
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment