Fix AAPBRecords access_level¶
This is a quick data fix for a bad default value when creating the AAPBRecordsBlock property for access_level.
This shouldn't have to be run again, but is provided in case it is useful!
Why?¶
When creating The access_level value, It was initially set to a tuple, of (value, label), just like the data in the ChoiceBlock. However, it needed to be just the value only.
Migrating the database back and reapplying the migration left the default values in the database, so this manual fix was needed.
Usage¶
Open a python shell in your Wagtail environment:
python manage.py shell
Then run the following:
In [ ]:
Copied!
from ov_collections.models import Collection, AAPB_BLOCK_TYPES
from ov_collections.models import Collection, AAPB_BLOCK_TYPES
In [ ]:
Copied!
for collection in Collection.objects.all():
for content in collection.content:
if content.block_type in AAPB_BLOCK_TYPES:
if type(content.value['access_level']) is tuple:
print('fixing', collection.title)
content.value.update({'access_level': 'online'})
collection.save()
for collection in Collection.objects.all():
for content in collection.content:
if content.block_type in AAPB_BLOCK_TYPES:
if type(content.value['access_level']) is tuple:
print('fixing', collection.title)
content.value.update({'access_level': 'online'})
collection.save()
In [ ]:
Copied!
from exhibits.models import ExhibitPage
for page in ExhibitPage.objects.all():
for content in page.body:
if content.block_type in AAPB_BLOCK_TYPES:
if type(content.value['access_level']) is tuple:
print('fixing', page.title)
content.value.update({'access_level': 'online'})
page.save()
from exhibits.models import ExhibitPage
for page in ExhibitPage.objects.all():
for content in page.body:
if content.block_type in AAPB_BLOCK_TYPES:
if type(content.value['access_level']) is tuple:
print('fixing', page.title)
content.value.update({'access_level': 'online'})
page.save()
In [ ]:
Copied!
for collection in Collection.objects.all():
for content in collection.content:
if content.block_type == 'image':
print(content.value)
for collection in Collection.objects.all():
for content in collection.content:
if content.block_type == 'image':
print(content.value)
In [ ]:
Copied!
from exhibits.models import ExhibitPage
for page in ExhibitPage.objects.all():
for content in page.body:
if content.block_type == 'image':
print(page.id, content)
from exhibits.models import ExhibitPage
for page in ExhibitPage.objects.all():
for content in page.body:
if content.block_type == 'image':
print(page.id, content)