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
35a4b69f
Commit
35a4b69f
authored
Jan 11, 2017
by
okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding the groups view
parent
8e9376a8
Pipeline
#740
passed with stages
in 1 minute and 7 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
+1
-1
picampaign/organization/tests.py
picampaign/organization/tests.py
+27
-0
picampaign/organization/views.py
picampaign/organization/views.py
+14
-2
picampaign/urls.py
picampaign/urls.py
+2
-1
No files found.
picampaign/organization/serializers.py
View file @
35a4b69f
...
...
@@ -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
:
...
...
picampaign/organization/tests.py
View file @
35a4b69f
...
...
@@ -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
(
...
...
picampaign/organization/views.py
View file @
35a4b69f
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
)
picampaign/urls.py
View file @
35a4b69f
...
...
@@ -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
=
[
...
...
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