From ab095fca5b94318faff0b752419112ee349e8b7b Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Thu, 2 Jun 2016 19:20:34 +0000 Subject: [PATCH] MOdified the 0011_populate_photos migration to set photo thumbnail values which include the photos dirname under the media_root. Added a reverse migration, for easier testing from a clean state. - Legacy-Id: 11264 --- ietf/person/migrations/0011_populate_photos.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ietf/person/migrations/0011_populate_photos.py b/ietf/person/migrations/0011_populate_photos.py index 2887dcbeb..c47895ffa 100644 --- a/ietf/person/migrations/0011_populate_photos.py +++ b/ietf/person/migrations/0011_populate_photos.py @@ -15,7 +15,7 @@ def photo_name(person,thumb=False): def forward(apps,schema_editor): Person = apps.get_model('person','Person') - images_dir = os.path.join(settings.PHOTOS_DIR,settings.PHOTO_URL_PREFIX) + images_dir = settings.PHOTOS_DIR image_filenames = [] for (dirpath, dirnames, filenames) in os.walk(images_dir): image_filenames.extend(filenames) @@ -24,16 +24,22 @@ def forward(apps,schema_editor): for person in Person.objects.all(): dirty = False if photo_name(person,thumb=False) in image_basenames: - person.photo = image_filenames[image_basenames.index(photo_name(person,thumb=False))] + person.photo = os.path.join(settings.PHOTO_URL_PREFIX, image_filenames[image_basenames.index(photo_name(person,thumb=False))]) dirty = True if photo_name(person,thumb=True) in image_basenames: - person.photo_thumb = image_filenames[image_basenames.index(photo_name(person,thumb=True))] + person.photo_thumb = os.path.join(settings.PHOTO_URL_PREFIX, image_filenames[image_basenames.index(photo_name(person,thumb=True))]) dirty = True if dirty: person.save() def reverse(apps, schema_editor): - pass + Person = apps.get_model('person','Person') + for person in Person.objects.filter(photo__gt=''): + person.photo = None + person.save() + for person in Person.objects.filter(photo_thumb__gt=''): + person.photo_thumb = None + person.save() class Migration(migrations.Migration):