Commit ae459065 authored by okhin's avatar okhin

Switching to a URLField for photos

parent 35a4b69f
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-01-19 10:36
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('contact', '0007_auto_20160808_1404'),
]
operations = [
migrations.AlterField(
model_name='contact',
name='photo',
field=models.URLField(blank=True, max_length=500),
),
]
...@@ -9,7 +9,7 @@ class Contact(models.Model): ...@@ -9,7 +9,7 @@ class Contact(models.Model):
birthdate = models.DateField(blank=True, null=True) birthdate = models.DateField(blank=True, null=True)
twitter = models.CharField(max_length=64, blank=True) twitter = models.CharField(max_length=64, blank=True)
mail = models.CharField(max_length=255, blank=True) mail = models.CharField(max_length=255, blank=True)
photo = models.ImageField(upload_to='contacts/photos', blank=True) photo = models.URLField(max_length=500, blank=True)
def __str__(self): def __str__(self):
return _(u'%(firstname)s %(lastname)s') % {'firstname': self.first_name, return _(u'%(firstname)s %(lastname)s') % {'firstname': self.first_name,
...@@ -30,7 +30,7 @@ class Contact(models.Model): ...@@ -30,7 +30,7 @@ class Contact(models.Model):
def get_photo_url(self): def get_photo_url(self):
if self.photo: if self.photo:
return self.photo.url return self.photo
return '' return ''
class Phone(models.Model): class Phone(models.Model):
......
...@@ -5,9 +5,6 @@ from django.core.files import File ...@@ -5,9 +5,6 @@ from django.core.files import File
from picampaign.contact.models import Contact, Phone from picampaign.contact.models import Contact, Phone
class MockImageField(object):
url = 'http://example.com/photo1.jpg'
class ContactMethodsTest(TestCase): class ContactMethodsTest(TestCase):
def test_full_name(self): def test_full_name(self):
contact = Contact(first_name='Victor', last_name='Hugo') contact = Contact(first_name='Victor', last_name='Hugo')
...@@ -44,7 +41,7 @@ class ContactMethodsTest(TestCase): ...@@ -44,7 +41,7 @@ class ContactMethodsTest(TestCase):
last_name='Ugo', last_name='Ugo',
) )
self.assertEqual(contact.get_photo_url(), '') self.assertEqual(contact.get_photo_url(), '')
contact.photo = MockImageField() contact.photo = 'http://example.com/photo1.jpg'
self.assertEqual(contact.get_photo_url(), 'http://example.com/photo1.jpg') self.assertEqual(contact.get_photo_url(), 'http://example.com/photo1.jpg')
class PhoneTest(TestCase): class PhoneTest(TestCase):
......
...@@ -97,6 +97,10 @@ class Importer(models.Model): ...@@ -97,6 +97,10 @@ class Importer(models.Model):
updated_contact['twitter'] = ''.join(['@', website['url'].split('/')[-1]]) updated_contact['twitter'] = ''.join(['@', website['url'].split('/')[-1]])
break break
# Let's retrieve the photo URL
if 'photo' in import_contact:
updated_contact['photo'] = import_contact['photo']
# Let's update_or_create the contact # Let's update_or_create the contact
contact, updated = Contact.objects.update_or_create(first_name=import_contact['first_name'], contact, updated = Contact.objects.update_or_create(first_name=import_contact['first_name'],
last_name=import_contact['last_name'], last_name=import_contact['last_name'],
......
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