Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
campaign
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
La Quadrature du Net
piphone
campaign
Commits
8e9376a8
Commit
8e9376a8
authored
Jan 11, 2017
by
okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding a group type view
parent
ae79abf4
Pipeline
#738
passed with stages
in 1 minute and 9 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
4 deletions
+44
-4
picampaign/organization/serializers.py
picampaign/organization/serializers.py
+6
-1
picampaign/organization/tests.py
picampaign/organization/tests.py
+23
-0
picampaign/organization/views.py
picampaign/organization/views.py
+13
-2
picampaign/urls.py
picampaign/urls.py
+2
-1
No files found.
picampaign/organization/serializers.py
View file @
8e9376a8
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'
)
picampaign/organization/tests.py
View file @
8e9376a8
...
...
@@ -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
...
...
picampaign/organization/views.py
View file @
8e9376a8
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
)
picampaign/urls.py
View file @
8e9376a8
...
...
@@ -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
=
[
...
...
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