Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wagtail 6.3 #1161

Merged
merged 5 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
docker compose -f prod-docker-compose.yaml build
docker compose -f prod-docker-compose.yaml up -d
docker run --rm --network securedroporg_app curlimages/curl:7.80.0 -4 --retry 24 --retry-delay 5 --retry-all-errors http://app:8000/health/ok/
docker compose -f prod-docker-compose.yaml exec django /bin/bash -c "./manage.py createdevdata --no-download"
docker compose -f prod-docker-compose.yaml exec django /bin/bash -c "./manage.py createdevdata"
no_output_timeout: 5m

- run:
Expand Down
1 change: 1 addition & 0 deletions common/fixtures/devdata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"model": "wagtailcore.collection", "pk": 1, "fields": {"path": "0001", "depth": 1, "numchild": 1, "name": "Root"}}, {"model": "wagtailcore.collection", "pk": 2, "fields": {"path": "00010001", "depth": 2, "numchild": 0, "name": "Animals"}}, {"model": "auth.user", "pk": 1, "fields": {"password": "pbkdf2_sha256$600000$kx8DzpGJkP0nEG6wVed3y7$I969toMhIV/959lCM2Gf3PvmJ1cgj5YqqbEtOq+v/Z8=", "last_login": "2024-07-25T21:02:32.035Z", "is_superuser": true, "username": "test", "first_name": "", "last_name": "", "email": "[email protected]", "is_staff": true, "is_active": true, "date_joined": "2024-07-25T21:02:16.045Z", "groups": [], "user_permissions": []}}, {"model": "common.customimage", "pk": 1, "fields": {"collection": 2, "title": "Bat", "file": "original_images/Bat.jpg", "width": 1920, "height": 2880, "created_at": "2024-07-25T21:04:26.730Z", "uploaded_by_user": ["test"], "focal_point_x": null, "focal_point_y": null, "focal_point_width": null, "focal_point_height": null, "file_size": 694750, "file_hash": "77611f00f02085cd0d72344fd487c1fee8698dd8"}}, {"model": "common.customimage", "pk": 2, "fields": {"collection": 2, "title": "Bee", "file": "original_images/Bee.jpg", "width": 1920, "height": 2763, "created_at": "2024-07-25T21:04:27.015Z", "uploaded_by_user": ["test"], "focal_point_x": null, "focal_point_y": null, "focal_point_width": null, "focal_point_height": null, "file_size": 506073, "file_hash": "8c30ce2d47fd9278348175057c20c5a684ea6d44"}}, {"model": "common.customimage", "pk": 3, "fields": {"collection": 2, "title": "Orange and white butterfly", "file": "original_images/Butterfly1.jpg", "width": 1920, "height": 1202, "created_at": "2024-07-25T21:04:27.254Z", "uploaded_by_user": ["test"], "focal_point_x": null, "focal_point_y": null, "focal_point_width": null, "focal_point_height": null, "file_size": 395401, "file_hash": "918bd1a5405ae19f77c904682a7840227a8707a7"}}, {"model": "common.customimage", "pk": 4, "fields": {"collection": 2, "title": "Tiger swallowtail butterfly", "file": "original_images/Butterfly2.jpg", "width": 1920, "height": 1920, "created_at": "2024-07-25T21:04:27.593Z", "uploaded_by_user": ["test"], "focal_point_x": null, "focal_point_y": null, "focal_point_width": null, "focal_point_height": null, "file_size": 987922, "file_hash": "2f15f86f39c15065bb6e0b35d81465fe4bd4ef34"}}, {"model": "common.customimage", "pk": 5, "fields": {"collection": 2, "title": "Cat 1", "file": "original_images/Cat1.jpg", "width": 1920, "height": 1280, "created_at": "2024-07-25T21:04:27.743Z", "uploaded_by_user": ["test"], "focal_point_x": null, "focal_point_y": null, "focal_point_width": null, "focal_point_height": null, "file_size": 266960, "file_hash": "2b14c7df6f5a254cb36afa304a248f748c2b47b4"}}, {"model": "common.customimage", "pk": 6, "fields": {"collection": 2, "title": "Cows", "file": "original_images/Cows.jpg", "width": 1920, "height": 1280, "created_at": "2024-07-25T21:04:27.878Z", "uploaded_by_user": ["test"], "focal_point_x": null, "focal_point_y": null, "focal_point_width": null, "focal_point_height": null, "file_size": 211828, "file_hash": "6739faaed6a412045eaf19fd1b2ec135f66b622d"}}, {"model": "common.customimage", "pk": 7, "fields": {"collection": 2, "title": "Dog 1", "file": "original_images/Dog1.jpg", "width": 1920, "height": 1280, "created_at": "2024-07-25T21:04:28.048Z", "uploaded_by_user": ["test"], "focal_point_x": null, "focal_point_y": null, "focal_point_width": null, "focal_point_height": null, "file_size": 430534, "file_hash": "7e854d6d408a5e7ab74b4702febf21e618ab790a"}}, {"model": "common.customimage", "pk": 8, "fields": {"collection": 2, "title": "Hedgehog", "file": "original_images/Hedgehog.jpg", "width": 1920, "height": 2880, "created_at": "2024-07-25T21:04:28.401Z", "uploaded_by_user": ["test"], "focal_point_x": null, "focal_point_y": null, "focal_point_width": null, "focal_point_height": null, "file_size": 733684, "file_hash": "bb8e0bab06cd777acfb741284823e91ab877bc4c"}}, {"model": "common.customimage", "pk": 9, "fields": {"collection": 2, "title": "Jellyfish", "file": "original_images/Jellyfish.jpg", "width": 1920, "height": 2621, "created_at": "2024-07-25T21:04:28.692Z", "uploaded_by_user": ["test"], "focal_point_x": null, "focal_point_y": null, "focal_point_width": null, "focal_point_height": null, "file_size": 662525, "file_hash": "f2cf9f88aa80c8f284b9c455636d60c7f06475d9"}}, {"model": "common.customimage", "pk": 10, "fields": {"collection": 2, "title": "Pig 1", "file": "original_images/Pig1.jpg", "width": 1920, "height": 2560, "created_at": "2024-07-25T21:04:29.027Z", "uploaded_by_user": ["test"], "focal_point_x": null, "focal_point_y": null, "focal_point_width": null, "focal_point_height": null, "file_size": 1020197, "file_hash": "aee3b8bcc5378d4ad651c8e56556769675088bc0"}}, {"model": "common.customimage", "pk": 11, "fields": {"collection": 2, "title": "Red Panda", "file": "original_images/RedPanda.jpg", "width": 1920, "height": 1280, "created_at": "2024-07-25T21:04:29.207Z", "uploaded_by_user": ["test"], "focal_point_x": null, "focal_point_y": null, "focal_point_width": null, "focal_point_height": null, "file_size": 423331, "file_hash": "e1e653999ac9eeb722f2071f5dd1d7a6e6441bcf"}}, {"model": "common.customimage", "pk": 12, "fields": {"collection": 2, "title": "Squirrel", "file": "original_images/Squirrel.jpg", "width": 1920, "height": 1280, "created_at": "2024-07-25T21:04:29.388Z", "uploaded_by_user": ["test"], "focal_point_x": null, "focal_point_y": null, "focal_point_width": null, "focal_point_height": null, "file_size": 560578, "file_hash": "e4f0f622b4ece26744873f0d3ec056632fb609cb"}}]
Binary file added common/fixtures/media/original_images/Bat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added common/fixtures/media/original_images/Bee.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 22 additions & 49 deletions common/management/commands/createdevdata.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import requests
import time
import os

from wagtail.models import Page, Site
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth.models import User
from django.core.files.base import ContentFile
from django.core.files.storage import FileSystemStorage, default_storage
from django.core.management import call_command
from django.core.files.images import ImageFile
from django.core.management.base import BaseCommand
from django.db import transaction
from django.core import management
import factory
import wagtail_factories

from common.models import SocialSharingSEOSettings, CustomImage
from common.factories import CustomImageFactory
from home.models import HomePage
from home.tests.factories import HomePageFactory

Expand All @@ -22,12 +19,6 @@ class Command(BaseCommand):
help = 'Creates data appropriate for development'

def add_arguments(self, parser):
parser.add_argument(
'--no-download',
action='store_false',
dest='download_images',
help='Download external images',
)
parser.add_argument(
'--delete',
action='store_true',
Expand All @@ -36,21 +27,18 @@ def add_arguments(self, parser):
help='Delete homepage and child pages before creating new data.',
)

def fetch_image(self, width, height, collection, category):
url = f'https://source.unsplash.com/{width}x{height}?{category}'
response = requests.get(url, timeout=5)
if response and response.content:
CustomImageFactory(
file__from_file=ContentFile(response.content),
file_size=len(response.content),
width=width,
height=height,
collection=collection,
)
else:
return False
time.sleep(0.2)
return True
def _copy_files(self, local_storage, path):
"""
Recursively copy files from local_storage to default_storage.
"""
directories, file_names = local_storage.listdir(path)
print(directories)
print(file_names)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleanup: print calls can be removed.

for directory in directories:
self._copy_files(local_storage, path + directory + "/")
for file_name in file_names:
with local_storage.open(path + file_name) as file_:
default_storage.save(path + file_name, file_)

@transaction.atomic
def handle(self, *args, **options):
Expand Down Expand Up @@ -93,28 +81,13 @@ def handle(self, *args, **options):
site.save()

# IMAGES
icon_collection = wagtail_factories.CollectionFactory(name='Icons')

if options.get('download_images', True):
self.stdout.write('Fetching images')
self.stdout.flush()
image_fail = False
for i in range(15):
if not self.fetch_image(500, 500, icon_collection, 'animals'):
image_fail = True
if image_fail:
self.stdout.write(self.style.NOTICE('NOTICE: Some images failed to save'))
else:
self.stdout.write(self.style.SUCCESS('OK'))
else:
faker = factory.faker.Faker._get_faker(locale='en-US')
for i in range(20):
CustomImageFactory.create(
file__width=500,
file__height=500,
file__color=faker.safe_color_name(),
collection=icon_collection,
)
fixtures_dir = os.path.join("common", "fixtures")
fixture_file = os.path.join(fixtures_dir, "devdata.json")
self.stdout.write("Copying media files...")
local_storage = FileSystemStorage(os.path.join(fixtures_dir, "media"))
self._copy_files(local_storage, "")
call_command("loaddata", fixture_file, verbosity=4)
print(CustomImage.objects.all())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleanup: print call can be removed.


management.call_command('createblogdata', '10')
management.call_command('createdirectory', '10')
Expand Down
2 changes: 1 addition & 1 deletion common/management/commands/tests/test_createdevdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_createdevdata_works(self):
"""
# Write stdout to /dev/null so as not to clutter the output from the tests
with open(os.devnull, 'w') as devnull:
management.call_command('createdevdata', '--delete', '--no-download', stdout=devnull)
management.call_command('createdevdata', '--delete', stdout=devnull)

# We expect `createdevdata` to also make a superuser
self.client.force_login(User.objects.filter(is_superuser=True).first())
Expand Down
18 changes: 18 additions & 0 deletions common/migrations/0010_customimage_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.17 on 2024-12-27 13:13

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('common', '0009_alter_customimage_file_alter_customrendition_file'),
]

operations = [
migrations.AddField(
model_name='customimage',
name='description',
field=models.CharField(blank=True, default='', max_length=255, verbose_name='description'),
),
]
40 changes: 19 additions & 21 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ django==4.2.17 \
# django-taggit
# django-treebeard
# djangorestframework
# laces
# wagtail
# wagtailmedia
django-anymail[mailgun]==9.0 \
Expand All @@ -232,9 +233,9 @@ django-filter==23.5 \
# via
# -r requirements.txt
# wagtail
django-modelcluster==6.1 \
--hash=sha256:3b1791638046c73ae7415327cf54bfa0adad9d89d342a5b86d0ec29a2504e067 \
--hash=sha256:8ce72635db4b90b34993afda5021ed8676ef94f1d4c607466d0f8d3f676c5b64
django-modelcluster==6.4 \
--hash=sha256:0102d00e6b884721ba21e32edb716548e0dead7880e130aa2e04854bd384a42f \
--hash=sha256:839b0ddb4a1a6f5fc7d9f2f029614a84350b41315bdb80a9c8b755baaa2297f2
# via
# -r requirements.txt
# wagtail
Expand All @@ -251,9 +252,9 @@ django-storages[google]==1.13.2 \
--hash=sha256:31dc5a992520be571908c4c40d55d292660ece3a55b8141462b4e719aa38eab3 \
--hash=sha256:cbadd15c909ceb7247d4ffc503f12a9bec36999df8d0bef7c31e57177d512688
# via -r requirements.txt
django-taggit==3.1.0 \
--hash=sha256:543218ac346fbe02a65733e0341c91b57a3e0f7a41568966b26f1cea9edc4805 \
--hash=sha256:c8f2e4eae387939089b3d75d1d8649e008880970c068ce9d0e82f87fd5e29508
django-taggit==6.1.0 \
--hash=sha256:ab776264bbc76cb3d7e49e1bf9054962457831bd21c3a42db9138b41956e4cf0 \
--hash=sha256:c4d1199e6df34125dd36db5eb0efe545b254dec3980ce5dd80e6bab3e78757c3
# via
# -r requirements.txt
# wagtail
Expand Down Expand Up @@ -440,12 +441,6 @@ gunicorn==23.0.0 \
--hash=sha256:ec400d38950de4dfd418cff8328b2c8faed0edb0d517d3394e457c317908ca4d \
--hash=sha256:f014447a0101dc57e294f6c18ca6b40227a4c90e9bdb586042628030cba004ec
# via -r requirements.txt
html5lib==1.1 \
--hash=sha256:0d78f8fde1c230e99fe37986a60526d7049ed4bf8a9fadbad5f00e22e58e041d \
--hash=sha256:b2e5b40261e20f354d198eae92afc10d750afb487ed5e50f9c4eaf07c184146f
# via
# -r requirements.txt
# wagtail
idna==3.7 \
--hash=sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc \
--hash=sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0
Expand All @@ -472,6 +467,12 @@ l18n==2021.3 \
# via
# -r requirements.txt
# wagtail
laces==0.1.1 \
--hash=sha256:ae2c575b9aaa46154e5518c61c9f86f5a9478f753a51e9c5547c7d275d361242 \
--hash=sha256:e45159c46f6adca33010d34e9af869e57201b70675c6dc088e919b16c89456a4
# via
# -r requirements.txt
# wagtail
lxml==4.9.3 \
--hash=sha256:05186a0f1346ae12553d66df1cfce6f251589fea3ad3da4f3ef4e34b2d58c6a3 \
--hash=sha256:075b731ddd9e7f68ad24c635374211376aa05a281673ede86cbe1d1b3455279d \
Expand Down Expand Up @@ -907,7 +908,6 @@ pytz==2022.7.1 \
--hash=sha256:78f4f37d8198e0627c5f1143240bb0206b8691d8d7ac6d78fee88b78733f8c4a
# via
# -r requirements.txt
# django-modelcluster
# l18n
pyyaml==6.0.1 \
--hash=sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5 \
Expand Down Expand Up @@ -1064,7 +1064,6 @@ six==1.16.0 \
# asttokens
# bleach
# google-auth
# html5lib
# l18n
# python-dateutil
# requests-file
Expand Down Expand Up @@ -1132,9 +1131,9 @@ vcrpy==4.2.1 \
--hash=sha256:7cd3e81a2c492e01c281f180bcc2a86b520b173d2b656cb5d89d99475423e013 \
--hash=sha256:efac3e2e0b2af7686f83a266518180af7a048619b2f696e7bad9520f5e2eac09
# via -r dev-requirements.in
wagtail==5.2.6 \
--hash=sha256:133ec00787d83ab7fa06255641aa855e7fd75f07d04af473bd98fe782c736595 \
--hash=sha256:5497eecf8ffef7996e2ac348e90444deac71e54d3334eca27683c29da8754550
wagtail==6.3.1 \
--hash=sha256:93876cc7a3bfcfff4c0393949562cbf249f244c4ca653d58a2dbab737f455715 \
--hash=sha256:d7d4e4fcb5edb4a5d0aaff5de72eaf33a51e4fa26c2d3a57801c58c4da35b209
# via
# -r requirements.txt
# wagtail-autocomplete
Expand Down Expand Up @@ -1167,15 +1166,14 @@ webencodings==0.5.1 \
# via
# -r requirements.txt
# bleach
# html5lib
# tinycss2
whitenoise==6.4.0 \
--hash=sha256:599dc6ca57e48929dfeffb2e8e187879bfe2aed0d49ca419577005b7f2cc930b \
--hash=sha256:a02d6660ad161ff17e3042653c8e3f5ecbb2a2481a006bde125b9efb9a30113a
# via -r requirements.txt
willow[heif]==1.6.2 \
--hash=sha256:957a4af8a7733e116a65eca34da11afe3fd52ffdb397494c8823901c25863787 \
--hash=sha256:e2d0450fd78ab19052d0478b888ef163e3264e8dcd1af002dd691458db98056f
willow[heif]==1.9.0 \
--hash=sha256:11a13097cffe501898cd434bb5761fb6cdbdb774a7853094cb56a4ba57cbbff7 \
--hash=sha256:ffac1406275ae30b60e7c6cbd1245f0bc359d1b5731002b18a712aaf424a5102
# via
# -r requirements.txt
# wagtail
Expand Down
2 changes: 1 addition & 1 deletion directory/tests/factories/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Meta:
class Params:
with_images = factory.Trait(
organization_logo=factory.Iterator(
CustomImage.objects.filter(collection__name='Icons')
CustomImage.objects.filter(collection__name='Animals')
)
)

Expand Down
2 changes: 1 addition & 1 deletion marketing/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Meta:

class Params:
with_image = Trait(
icon=Iterator(CustomImage.objects.filter(collection__name='Icons'))
icon=Iterator(CustomImage.objects.filter(collection__name='Animals'))
)

title = Faker('sentence')
Expand Down
4 changes: 2 additions & 2 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bleach>=4.1.0
Django>=4.2.17,<4.3
django-anymail[mailgun]>=1.4
django-modelcluster>=6.1
django-modelcluster>=6.2.1
django-settings-export
django-storages[google]
django-webpack-loader
Expand All @@ -16,7 +16,7 @@ python-json-logger
structlog
tldextract
tinycss2
wagtail>=5.2.6,<5.3
wagtail>=6.3.1,<6.4
wagtail-factories>=4.1.0
wagtail-metadata>=5.0.0
wagtail-autocomplete>=0.11.0
Expand Down
Loading