From 8de631329f461da8063bb4e6e9525ee71740f620 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Fri, 20 May 2022 11:29:53 +0100 Subject: [PATCH 1/3] Vary revision ForeignKey --- wagtail_localize/compat.py | 6 ++++++ wagtail_localize/models.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/wagtail_localize/compat.py b/wagtail_localize/compat.py index 8560b449..c2e7ef14 100644 --- a/wagtail_localize/compat.py +++ b/wagtail_localize/compat.py @@ -60,3 +60,9 @@ def get_snippet_delete_url(snippet): "wagtailsnippets:delete", args=[snippet._meta.app_label, snippet._meta.model_name, quote(snippet.pk)], ) + + +def get_revision_model(): + if WAGTAIL_VERSION >= (4, 0): + return "wagtailcore.Revision" + return "wagtailcore.PageRevision" diff --git a/wagtail_localize/models.py b/wagtail_localize/models.py index aa35f85b..dbae9e7a 100644 --- a/wagtail_localize/models.py +++ b/wagtail_localize/models.py @@ -49,7 +49,7 @@ from wagtail.core.utils import find_available_slug from wagtail.snippets.models import get_snippet_models -from .compat import DATE_FORMAT, get_snippet_edit_url +from .compat import DATE_FORMAT, get_revision_model, get_snippet_edit_url from .fields import copy_synchronised_fields from .locales.components import LocaleComponentModelForm, register_locale_component from .segments import ( @@ -1362,7 +1362,7 @@ class TranslationLog(models.Model): ) created_at = models.DateTimeField(auto_now_add=True) page_revision = models.ForeignKey( - "wagtailcore.PageRevision", + get_revision_model(), on_delete=models.SET_NULL, null=True, blank=True, From 1f2441b52dac9e4b15f5045f40f14e0dfd0d8bf0 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Fri, 20 May 2022 11:49:03 +0100 Subject: [PATCH 2/3] Update GitHub Action setup * cancels olde in-progress jobs for the same branch/PR * uses newer actions versions * adds tox caching --- .github/workflows/test.yml | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ea720f3..03d081c6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,15 +8,20 @@ on: pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + + jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - name: Set up Python 3.8 - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: '3.8' - uses: pre-commit/action@v2.0.3 @@ -43,14 +48,20 @@ jobs: django: '3.2' wagtail: '3.0' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: ${{ matrix.python }} - name: Install Tox run: | python -m pip install tox + - name: Cache tox environments + id: cache-tox + uses: actions/cache@v3 + with: + path: .tox + key: tox-${{ hashFiles('setup.py') }}-py${{ matrix.python }}-dj${{ matrix.django }}-w${{ matrix.wagtail }}-sqlite - name: Test run: | tox @@ -108,14 +119,20 @@ jobs: options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: ${{ matrix.python }} - name: Install Tox run: | python -m pip install tox + - name: Cache tox environments + id: cache-tox + uses: actions/cache@v3 + with: + path: .tox + key: tox-${{ hashFiles('setup.py') }}-py${{ matrix.python }}-dj${{ matrix.django }}-w${{ matrix.wagtail }}-postgres - name: Test run: | tox @@ -131,9 +148,9 @@ jobs: python: ['3.8'] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: ${{ matrix.python }} - name: Install dependencies From 2924c390d33359c713154aad1c20f16c7acb137e Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Fri, 20 May 2022 11:58:52 +0100 Subject: [PATCH 3/3] Update makefile --- Makefile | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index fdec7c2c..87b9400f 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,47 @@ -npm_deps: +# ---------------------------------------------------------------------------- +# Self-Documented Makefile +# ref: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html +# ---------------------------------------------------------------------------- +.PHONY: help +.DEFAULT_GOAL := help + +help: ## โ‰๏ธ - Display help comments for each make command + @grep -E '^[0-9a-zA-Z_-]+:.*? .*$$' \ + $(MAKEFILE_LIST) \ + | awk 'BEGIN { FS=":.*?## " }; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' \ + | sort + +npm_deps: ## ๐Ÿงฐ - Install npm dependencies npm install -build: npm_deps +build: npm_deps ## ๐Ÿงฐ - Build front-end assets npm run build -dev: npm_deps +dev: npm_deps ## ๐Ÿงฐ - Build front-end assets and watch for changes in development mode npm run start -messages: +messages: ## ๐Ÿ”จ - Make messages node ./scripts/extract-translatable-strings.js cd wagtail_localize && python ../testmanage.py makemessages --locale=en -fetch-translations: +fetch-translations: ## ๐Ÿ”จ - Fetch new translations ./scripts/fetch-translations.sh -compile-messages: +compile-messages: ## ๐Ÿ”จ - Compile messages cd wagtail_localize && python ../testmanage.py compilemessages + +translations: build messages fetch-translations compile-messages ## ๐ŸŒ - Prepare translations + +clean: ## ๐Ÿ—‘๏ธ - Remove __pycache__ and test artifacts + @echo "๐Ÿ—‘๏ธ - Removing __pycache__ and test artifacts" + find . -name ".tox" -prune -o -type d -name "__pycache__" -exec rm -r {} + + +package-setup: + @echo "๐Ÿ“ฆ - Packaging for PyPI" + python3 setup.py clean --all sdist bdist_wheel + +package: clean package-setup ## ๐Ÿ“ฆ - Package for PyPI + +test: ## ๐Ÿงช - Run test suite + @echo "๐Ÿงช - Running test suite" + tox