Skip to content

Commit ab095fc

Browse files
committed
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
1 parent c83dae5 commit ab095fc

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

ietf/person/migrations/0011_populate_photos.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def photo_name(person,thumb=False):
1515

1616
def forward(apps,schema_editor):
1717
Person = apps.get_model('person','Person')
18-
images_dir = os.path.join(settings.PHOTOS_DIR,settings.PHOTO_URL_PREFIX)
18+
images_dir = settings.PHOTOS_DIR
1919
image_filenames = []
2020
for (dirpath, dirnames, filenames) in os.walk(images_dir):
2121
image_filenames.extend(filenames)
@@ -24,16 +24,22 @@ def forward(apps,schema_editor):
2424
for person in Person.objects.all():
2525
dirty = False
2626
if photo_name(person,thumb=False) in image_basenames:
27-
person.photo = image_filenames[image_basenames.index(photo_name(person,thumb=False))]
27+
person.photo = os.path.join(settings.PHOTO_URL_PREFIX, image_filenames[image_basenames.index(photo_name(person,thumb=False))])
2828
dirty = True
2929
if photo_name(person,thumb=True) in image_basenames:
30-
person.photo_thumb = image_filenames[image_basenames.index(photo_name(person,thumb=True))]
30+
person.photo_thumb = os.path.join(settings.PHOTO_URL_PREFIX, image_filenames[image_basenames.index(photo_name(person,thumb=True))])
3131
dirty = True
3232
if dirty:
3333
person.save()
3434

3535
def reverse(apps, schema_editor):
36-
pass
36+
Person = apps.get_model('person','Person')
37+
for person in Person.objects.filter(photo__gt=''):
38+
person.photo = None
39+
person.save()
40+
for person in Person.objects.filter(photo_thumb__gt=''):
41+
person.photo_thumb = None
42+
person.save()
3743

3844
class Migration(migrations.Migration):
3945

0 commit comments

Comments
 (0)