forked from Princeton-CDH/cdh-web
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Populate event feed images from the pre-v4-migration thumbnails
- Loading branch information
1 parent
2cd1aea
commit 1c79715
Showing
2 changed files
with
339 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
{ | ||
"214": null, | ||
"215": null, | ||
"216": null, | ||
"217": null, | ||
"218": null, | ||
"219": null, | ||
"220": null, | ||
"221": null, | ||
"222": null, | ||
"223": 561, | ||
"224": null, | ||
"225": null, | ||
"226": null, | ||
"227": null, | ||
"228": null, | ||
"229": null, | ||
"230": null, | ||
"231": null, | ||
"232": null, | ||
"233": null, | ||
"234": null, | ||
"235": null, | ||
"236": null, | ||
"237": null, | ||
"238": null, | ||
"239": null, | ||
"240": null, | ||
"241": null, | ||
"242": 574, | ||
"243": 575, | ||
"244": 494, | ||
"245": null, | ||
"246": null, | ||
"247": null, | ||
"248": 527, | ||
"249": null, | ||
"250": 520, | ||
"251": 563, | ||
"252": null, | ||
"253": null, | ||
"254": null, | ||
"255": null, | ||
"256": 460, | ||
"257": 576, | ||
"258": 573, | ||
"259": 525, | ||
"260": null, | ||
"261": null, | ||
"262": 561, | ||
"263": 559, | ||
"264": 568, | ||
"265": 465, | ||
"266": 513, | ||
"267": 547, | ||
"268": 544, | ||
"269": 490, | ||
"270": 558, | ||
"271": 524, | ||
"272": 499, | ||
"273": 458, | ||
"274": 548, | ||
"275": 496, | ||
"276": 493, | ||
"277": 509, | ||
"278": 572, | ||
"279": 571, | ||
"280": 570, | ||
"281": 571, | ||
"282": 572, | ||
"283": 510, | ||
"284": 537, | ||
"285": 572, | ||
"286": 549, | ||
"287": 571, | ||
"288": 554, | ||
"289": 570, | ||
"290": 237, | ||
"291": 572, | ||
"292": 508, | ||
"293": 572, | ||
"294": 545, | ||
"295": 5, | ||
"296": 469, | ||
"297": 505, | ||
"298": 512, | ||
"299": 514, | ||
"300": 511, | ||
"301": null, | ||
"302": 569, | ||
"303": 478, | ||
"304": 569, | ||
"305": null, | ||
"306": 486, | ||
"307": 462, | ||
"308": 512, | ||
"309": 512, | ||
"310": 480, | ||
"311": null, | ||
"312": 127, | ||
"313": 466, | ||
"314": 478, | ||
"315": 237, | ||
"316": 105, | ||
"317": 232, | ||
"318": 539, | ||
"319": 530, | ||
"320": 543, | ||
"321": 493, | ||
"322": 459, | ||
"323": 492, | ||
"324": 530, | ||
"325": 536, | ||
"326": 530, | ||
"327": 535, | ||
"328": 502, | ||
"329": 457, | ||
"330": 67, | ||
"331": 489, | ||
"332": 530, | ||
"333": 530, | ||
"334": null, | ||
"335": 67, | ||
"336": 67, | ||
"337": 536, | ||
"338": 511, | ||
"339": 530, | ||
"340": 552, | ||
"341": 501, | ||
"342": 109, | ||
"343": 109, | ||
"344": 109, | ||
"345": 109, | ||
"346": 109, | ||
"347": 109, | ||
"348": 109, | ||
"349": 50, | ||
"350": null, | ||
"351": 483, | ||
"352": null, | ||
"353": null, | ||
"354": 123, | ||
"355": 59, | ||
"356": 59, | ||
"357": 59, | ||
"358": null, | ||
"359": 481, | ||
"360": 474, | ||
"361": null, | ||
"362": 531, | ||
"363": null, | ||
"364": 533, | ||
"365": 542, | ||
"366": 541, | ||
"367": 541, | ||
"368": 540, | ||
"369": 546, | ||
"370": 479, | ||
"371": 560, | ||
"372": 555, | ||
"373": 639, | ||
"374": 556, | ||
"375": 538, | ||
"376": 503, | ||
"377": 523, | ||
"378": 504, | ||
"379": 495, | ||
"380": 534, | ||
"381": 514, | ||
"382": 109, | ||
"383": 67, | ||
"384": 526, | ||
"385": 536, | ||
"386": 67, | ||
"387": 553, | ||
"388": 532, | ||
"389": 566, | ||
"390": 567, | ||
"391": 526, | ||
"617": 756, | ||
"618": 760, | ||
"623": 763, | ||
"625": 766, | ||
"626": 767, | ||
"627": 769, | ||
"635": 109, | ||
"656": 815, | ||
"657": 815, | ||
"658": 815, | ||
"659": 815, | ||
"660": 815, | ||
"661": 819, | ||
"680": 853, | ||
"688": 864, | ||
"689": 865, | ||
"702": 864, | ||
"703": 884, | ||
"704": 884, | ||
"705": 884, | ||
"706": 884, | ||
"707": 884, | ||
"708": 884, | ||
"717": 864, | ||
"723": 908, | ||
"724": 907, | ||
"726": 864, | ||
"731": 923, | ||
"738": 67, | ||
"744": 864, | ||
"746": 933, | ||
"747": 934, | ||
"753": 956, | ||
"754": 959, | ||
"756": 963, | ||
"781": 1008, | ||
"782": 538, | ||
"789": 1023, | ||
"793": 1044, | ||
"795": 1032, | ||
"799": 1060, | ||
"800": 1064, | ||
"803": 842, | ||
"805": 1083, | ||
"810": 1068, | ||
"815": 1092, | ||
"816": 1032, | ||
"820": 1090, | ||
"824": 861, | ||
"825": 1093, | ||
"826": 780, | ||
"827": 616, | ||
"830": 1068, | ||
"831": 996, | ||
"832": 842, | ||
"833": 1093, | ||
"835": 1097, | ||
"837": 863, | ||
"839": 863, | ||
"840": 863, | ||
"841": 1097, | ||
"842": 1097, | ||
"844": 892, | ||
"852": 1108, | ||
"856": 1068, | ||
"857": 996, | ||
"858": 1067, | ||
"862": 996, | ||
"865": 1124, | ||
"884": 1008, | ||
"885": 1194, | ||
"886": 1097, | ||
"887": 748, | ||
"888": 1189, | ||
"892": 1212, | ||
"893": 1218, | ||
"894": 150, | ||
"903": 1211, | ||
"914": 842, | ||
"915": 1068, | ||
"919": 1237, | ||
"920": 1233, | ||
"921": 1236, | ||
"922": 1235, | ||
"923": 1250, | ||
"924": 1244, | ||
"925": 1253, | ||
"926": 1245, | ||
"927": 1270, | ||
"928": 1093, | ||
"930": 1259, | ||
"933": 765, | ||
"937": 1260, | ||
"940": 1093, | ||
"941": 1266, | ||
"942": 1277, | ||
"943": 1276, | ||
"944": 1264 | ||
} |
61 changes: 61 additions & 0 deletions
61
cdhweb/events/management/commands/populate_event_thumbnails.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from django.core.management.base import BaseCommand | ||
import json | ||
from pathlib import Path | ||
from cdhweb.events.models import Event | ||
from wagtail.images.models import Image | ||
|
||
|
||
class Command(BaseCommand): | ||
def handle(self, *args, **options): | ||
""" | ||
Update event images from the v3 version of the site | ||
We renamed/replaced the image fields on the Events | ||
for v4, but didn't make a migration to transfer the | ||
data -- this command populates any events that still | ||
have unset images to those from the latest database | ||
dump we have (approx 2024-04-25) -- see | ||
`image-mapping.json` | ||
Mapping prepared with | ||
``` | ||
image_mapping = {e.page_ptr_id: e.thumbnail_id for e in Event.objects.filter(thumbnail__isnull=False)} | ||
``` | ||
""" | ||
mapping_path = Path(__file__).parent / "image-mapping.json" | ||
image_mapping = json.load(open(mapping_path)) | ||
for page_id, thumbnail_id in image_mapping.items(): | ||
if not thumbnail_id: | ||
continue | ||
|
||
event = Event.objects.filter(page_ptr_id=page_id).first() | ||
if not event: | ||
self.stderr.write( | ||
f"Event page missing for page_id {page_id}", | ||
style_func=self.style.WARNING, | ||
) | ||
continue | ||
|
||
thumbnail = Image.objects.filter(pk=thumbnail_id).first() | ||
if not thumbnail: | ||
self.stderr.write( | ||
f"Image ({thumbnail_id=}) missing for page {event.title}({page_id=})", | ||
style_func=self.style.WARNING, | ||
) | ||
continue | ||
|
||
if event.feed_image is None: | ||
event.feed_image = thumbnail | ||
self.stdout.write( | ||
f"Page {event.title}({page_id=}) updated with feed image {thumbnail.title}({thumbnail_id})", | ||
style_func=self.style.SUCCESS, | ||
) | ||
|
||
if event.image is None: | ||
event.image = thumbnail | ||
self.stdout.write( | ||
f"Page {event.title}({page_id=}) updated with hero image {thumbnail.title}({thumbnail_id})", | ||
style_func=self.style.SUCCESS, | ||
) | ||
|
||
event.save() |