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
28bcab73
Commit
28bcab73
authored
Feb 11, 2019
by
Okhin
Browse files
All phones if no filter + twitter and photo ad emails
parent
fa9c2b7d
Pipeline
#2433
passed with stages
in 2 minutes and 29 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
picampaign/campaign/serializers.py
View file @
28bcab73
...
...
@@ -31,13 +31,15 @@ class CampaignContactSerializer(serializers.HyperlinkedModelSerializer):
phone
=
PhoneSerializer
(
many
=
True
,
source
=
'contact.phones'
)
groups
=
GroupSerializer
(
many
=
True
,
source
=
'contact.groups'
)
contact_id
=
serializers
.
ReadOnlyField
(
source
=
'contact.id'
)
email
=
serializers
.
ReadOnlyField
(
source
=
'contact.email'
)
twitter
=
serializers
.
ReadOnlyField
(
source
=
'contact.twitter'
)
photo
=
serializers
.
ReadOnlyField
(
source
=
'contact.get_photo_url'
)
class
Meta
:
model
=
CampaignContact
fields
=
(
'id'
,
'weight'
,
'contact_id'
,
'full_name'
,
'first_name'
,
'last_name'
,
'phone'
,
'groups'
,
'photo'
)
'phone'
,
'groups'
,
'photo'
,
'email'
,
'twitter'
)
def
to_representation
(
self
,
instance
):
"""
...
...
@@ -49,8 +51,8 @@ class CampaignContactSerializer(serializers.HyperlinkedModelSerializer):
# We should have a filter parameter for the campaign
filter
=
campaign
.
phone_filter
if
filter
==
''
or
filter
is
None
:
# No filter, we
just
return
the first phon
e number
data
[
'phone'
]
=
dat
a
[
'phone'
]
[
0
]
[
'phone'
]
# No filter, we return
all th
e number
s
data
[
'phone'
]
=
[
a
[
'phone'
]
for
a
in
data
[
'phone'
]
]
return
data
else
:
for
phone
in
data
[
'phone'
]:
...
...
picampaign/campaign/test_serializers.py
View file @
28bcab73
...
...
@@ -57,7 +57,7 @@ class CampaignContactSerializerTest(TestCase):
contact
=
contact
)
serializer
=
CampaignContactSerializer
(
campaigncontact
)
self
.
assertEqual
(
serializer
.
to_representation
(
campaigncontact
)[
'phone'
],
contact
.
phones
.
first
().
phone
)
self
.
assertEqual
(
serializer
.
to_representation
(
campaigncontact
)[
'phone'
],
[
phone
.
phone
for
phone
in
contact
.
phones
.
all
()]
)
# Let's add a phone filter
campaign
.
phone_filter
=
'98'
self
.
assertEqual
(
serializer
.
to_representation
(
campaigncontact
)[
'phone'
],
contact
.
phones
.
last
().
phone
)
picampaign/campaign/test_views.py
View file @
28bcab73
...
...
@@ -46,7 +46,7 @@ class ViewSetTest(TestCase):
client
=
APIClient
()
response
=
client
.
get
(
'/campaigns/%(cid)d/contacts/'
%
{
'cid'
:
self
.
campaign
.
id
},
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'[{"id":1,"weight":0,"contact_id":1,"full_name":"Victor Hugo","first_name":"Victor","last_name":"Hugo","phone":"0123456789","groups":[],"photo":""}]'
)
self
.
assertEqual
(
response
.
content
,
b
'[{"id":1,"weight":0,"contact_id":1,"full_name":"Victor Hugo","first_name":"Victor","last_name":"Hugo","phone":
[
"0123456789"
]
,"groups":[],"photo":""
,"twitter":""
}]'
)
def
test_campaign_argumentary_viewset
(
self
):
client
=
APIClient
()
...
...
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