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

Wagtail upgrade #362

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.11
- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.2.2 python -
- name: Install Python dependencies
Expand All @@ -58,7 +58,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.11
- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.2.2 python -
- name: Install Python dependencies
Expand Down
2 changes: 1 addition & 1 deletion .gitpod.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ FROM gitpod/workspace-full

RUN sudo apt-get update && sudo rm -rf /var/lib/apt/lists/*

ARG PYTHON_VERSION=3.9.14
ARG PYTHON_VERSION=3.11.6
RUN pyenv install ${PYTHON_VERSION} && pyenv global ${PYTHON_VERSION}
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN npm run build
# ones becase they use a different C compiler. Debian images also come with
# all useful packages required for image manipulation out of the box. They
# however weigh a lot, approx. up to 1.5GiB per built image.
FROM python:3.9 as production
FROM python:3.11 as production

ARG POETRY_HOME=/opt/poetry
ARG POETRY_INSTALL_ARGS="--without dev"
Expand All @@ -38,8 +38,8 @@ WORKDIR /app
# * PATH - Make sure that Poetry is on the PATH, along with our venv
# * PYTHONUNBUFFERED - This is useful so Python does not hold any messages
# from being output.
# https://docs.python.org/3.9/using/cmdline.html#envvar-PYTHONUNBUFFERED
# https://docs.python.org/3.9/using/cmdline.html#cmdoption-u
# https://docs.python.org/3.11/using/cmdline.html#envvar-PYTHONUNBUFFERED
# https://docs.python.org/3.11/using/cmdline.html#cmdoption-u
# * DJANGO_SETTINGS_MODULE - default settings used in the container.
# * PORT - default port used. Please match with EXPOSE.
# Heroku will ignore EXPOSE and only set PORT variable. PORT variable is
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ We assume that you have basic knowledge of Node/Webpack and Python/Django/Wagtai
#### Dependencies

- Git
- Python >= 3.9
- Python >= 3.11
- Poetry >= 1.2.2
- Node (see `.nvmrc` for version)

Expand All @@ -35,7 +35,7 @@ Run:

python -V

Confirm that the output is showing version Python 3.9 (or higher). If not, you may have multiple versions of Python installed on your system and will need to switch to the appropriate version when creating the virtual environment.
Confirm that the output is showing version Python 3.11 (or higher). If not, you may have multiple versions of Python installed on your system and will need to switch to the appropriate version when creating the virtual environment.

With the Python version output confirmed, [install Poetry](https://python-poetry.org/docs).

Expand Down
1 change: 0 additions & 1 deletion apps/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from . import monkey_patches # noqa
5 changes: 5 additions & 0 deletions apps/core/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
class CoreConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "apps.core"

def ready(self):
from .monkey_patches import patch_copy_for_translation_action

patch_copy_for_translation_action()
4 changes: 2 additions & 2 deletions apps/core/blocks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.utils.translation import gettext as _
from wagtail.core import blocks
from wagtail.core.blocks import RichTextBlock
from wagtail import blocks
from wagtail.blocks import RichTextBlock


class TextBlock(RichTextBlock):
Expand Down
2 changes: 1 addition & 1 deletion apps/core/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf import settings
from django.utils import timezone
from faker import Faker
from wagtail.core.models import Locale, Page, Site
from wagtail.models import Locale, Page, Site

from apps.core.models import ContentPage, HomePage

Expand Down
2 changes: 1 addition & 1 deletion apps/core/management/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from django.db.migrations.operations import AlterModelOptions
from django.db.models import Field, FileField
from django.db.models.fields.related import RelatedField
from wagtail.core.fields import StreamField
from wagtail.fields import StreamField

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion apps/core/models/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.template import Context, Template
from django.utils.text import slugify
from wagtail.admin.panels import FieldPanel
from wagtail.core.fields import StreamField
from wagtail.fields import StreamField
from wagtail.models import Page

from apps.core.models.feedback import Feedback
Expand Down
2 changes: 1 addition & 1 deletion apps/core/models/home.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models
from wagtail.admin.panels import FieldPanel
from wagtail.core.fields import StreamField
from wagtail.fields import StreamField
from wagtail.models import Page

from ..blocks import HOME_BLOCKS
Expand Down
9 changes: 6 additions & 3 deletions apps/monkey_patches.py → apps/core/monkey_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

logger = logging.getLogger(__name__)

logger.warning("Monkey patching `CopyPageForTranslationAction._copy_for_translation`")


# flake8: noqa: C901
@transaction.atomic
Expand Down Expand Up @@ -82,4 +80,9 @@ def process_child_object(
)


CopyPageForTranslationAction._copy_for_translation = _copy_for_translation
def patch_copy_for_translation_action():
logger.warning(
"Monkey patching `CopyPageForTranslationAction._copy_for_translation`"
)

CopyPageForTranslationAction._copy_for_translation = _copy_for_translation
2 changes: 1 addition & 1 deletion apps/core/templatetags/core_tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import template
from django.utils.translation import get_language
from wagtail.core.models import Page
from wagtail.models import Page

from apps.core.models import FooterContent, HomePage

Expand Down
2 changes: 1 addition & 1 deletion apps/core/tests/test_header.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.template import Context, Template
from django.test import TestCase
from django.utils import translation
from wagtail.core.models import Page
from wagtail.models import Page

from apps.core.factories import HomePageFactory

Expand Down
4 changes: 3 additions & 1 deletion apps/core/tests/test_locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def test_can_access_account_settings(self):

def test_redirect_to_default_language_if_no_translation_available(self):
language_code = "de-CH"
response = self.client.get("/", HTTP_ACCEPT_LANGUAGE=language_code, follow=True)
response = self.client.get(
"/", headers={"accept-language": language_code}, follow=True
)
self.assertEqual(response.status_code, HTTPStatus.OK)
self.assertRedirects(response, "/en-latest/")
2 changes: 1 addition & 1 deletion apps/core/tests/test_management_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.core.management import call_command
from django.test import TestCase
from wagtail.core.models import Page
from wagtail.models import Page


class TestBuildFixtures(TestCase):
Expand Down
33 changes: 33 additions & 0 deletions apps/custom_media/migrations/0003_wagtail_42.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.1.2 on 2023-10-30 14:44

from django.db import migrations
import wagtail.images.models


class Migration(migrations.Migration):

dependencies = [
("custom_media", "0002_initial"),
]

operations = [
migrations.AlterField(
model_name="customimage",
name="file",
field=wagtail.images.models.WagtailImageField(
height_field="height",
upload_to=wagtail.images.models.get_upload_to,
verbose_name="file",
width_field="width",
),
),
migrations.AlterField(
model_name="customrendition",
name="file",
field=wagtail.images.models.WagtailImageField(
height_field="height",
upload_to=wagtail.images.models.get_rendition_upload_to,
width_field="width",
),
),
]
24 changes: 24 additions & 0 deletions apps/custom_media/migrations/0004_django_42.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.6 on 2023-10-31 11:31

from django.db import migrations
import wagtail.images.models


class Migration(migrations.Migration):

dependencies = [
("custom_media", "0003_wagtail_42"),
]

operations = [
migrations.AlterField(
model_name="customrendition",
name="file",
field=wagtail.images.models.WagtailImageField(
height_field="height",
storage=wagtail.images.models.get_rendition_storage,
upload_to=wagtail.images.models.get_rendition_upload_to,
width_field="width",
),
),
]
14 changes: 11 additions & 3 deletions apps/guide/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.contrib.modeladmin",
"wagtail.contrib.search_promotions",
"wagtail.embeds",
"wagtail.sites",
"wagtail.users",
Expand Down Expand Up @@ -193,7 +194,6 @@
USE_I18N = True
WAGTAIL_I18N_ENABLED = True

USE_L10N = True

USE_TZ = True

Expand Down Expand Up @@ -292,7 +292,15 @@
# ManifestStaticFilesStorage is recommended in production, to prevent outdated
# JavaScript / CSS assets being served from cache (e.g. after a Wagtail upgrade).
# See https://docs.djangoproject.com/en/4.0/ref/contrib/staticfiles/#manifeststaticfilesstorage # noqa
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}


STATIC_ROOT = BASE_DIR / "static"
STATIC_URL = "/static/"
Expand Down Expand Up @@ -351,7 +359,7 @@
INSTALLED_APPS = INSTALLED_APPS + ["storages"]

# https://docs.djangoproject.com/en/stable/ref/settings/#default-file-storage
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
STORAGES["default"] = {"BACKEND": "storages.backends.s3boto3.S3Boto3Storage"}

AWS_STORAGE_BUCKET_NAME = env["AWS_STORAGE_BUCKET_NAME"]

Expand Down
4 changes: 3 additions & 1 deletion apps/guide/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"]

# Use non-manifest static files in tests, to avoid the need to run `collectstatic`
STATICFILES_STORAGE = "whitenoise.storage.CompressedStaticFilesStorage"
STORAGES["staticfiles"] = { # noqa: F405
"BACKEND": "whitenoise.storage.CompressedStaticFilesStorage"
}
2 changes: 1 addition & 1 deletion apps/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from rest_framework import serializers
from rest_framework.decorators import api_view
from rest_framework.response import Response
from wagtail.contrib.search_promotions.models import Query
from wagtail.models import Locale, Page
from wagtail.search.models import Query


def search(request):
Expand Down
Loading