Commit 28bcab73 authored by okhin's avatar okhin 🚴

All phones if no filter + twitter and photo ad emails

parent fa9c2b7d
Pipeline #2433 passed with stages
in 2 minutes and 29 seconds
...@@ -31,13 +31,15 @@ class CampaignContactSerializer(serializers.HyperlinkedModelSerializer): ...@@ -31,13 +31,15 @@ class CampaignContactSerializer(serializers.HyperlinkedModelSerializer):
phone = PhoneSerializer(many=True, source='contact.phones') phone = PhoneSerializer(many=True, source='contact.phones')
groups = GroupSerializer(many=True, source='contact.groups') groups = GroupSerializer(many=True, source='contact.groups')
contact_id = serializers.ReadOnlyField(source='contact.id') 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') photo = serializers.ReadOnlyField(source='contact.get_photo_url')
class Meta: class Meta:
model = CampaignContact model = CampaignContact
fields = ('id', 'weight', 'contact_id', fields = ('id', 'weight', 'contact_id',
'full_name', 'first_name', 'last_name', 'full_name', 'first_name', 'last_name',
'phone', 'groups', 'photo') 'phone', 'groups', 'photo', 'email', 'twitter')
def to_representation(self, instance): def to_representation(self, instance):
""" """
...@@ -49,8 +51,8 @@ class CampaignContactSerializer(serializers.HyperlinkedModelSerializer): ...@@ -49,8 +51,8 @@ class CampaignContactSerializer(serializers.HyperlinkedModelSerializer):
# We should have a filter parameter for the campaign # We should have a filter parameter for the campaign
filter = campaign.phone_filter filter = campaign.phone_filter
if filter == '' or filter is None: if filter == '' or filter is None:
# No filter, we just return the first phone number # No filter, we return all the numbers
data['phone'] = data['phone'][0]['phone'] data['phone'] = [a['phone'] for a in data['phone']]
return data return data
else: else:
for phone in data['phone']: for phone in data['phone']:
......
...@@ -57,7 +57,7 @@ class CampaignContactSerializerTest(TestCase): ...@@ -57,7 +57,7 @@ class CampaignContactSerializerTest(TestCase):
contact=contact contact=contact
) )
serializer = CampaignContactSerializer(campaigncontact) 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 # Let's add a phone filter
campaign.phone_filter='98' campaign.phone_filter='98'
self.assertEqual(serializer.to_representation(campaigncontact)['phone'], contact.phones.last().phone) self.assertEqual(serializer.to_representation(campaigncontact)['phone'], contact.phones.last().phone)
...@@ -46,7 +46,7 @@ class ViewSetTest(TestCase): ...@@ -46,7 +46,7 @@ class ViewSetTest(TestCase):
client = APIClient() client = APIClient()
response = client.get('/campaigns/%(cid)d/contacts/' % {'cid': self.campaign.id}, format='json') response = client.get('/campaigns/%(cid)d/contacts/' % {'cid': self.campaign.id}, format='json')
self.assertEqual(response.status_code, 200) 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): def test_campaign_argumentary_viewset(self):
client = APIClient() client = APIClient()
......
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