From f92f89361f9487702c5020adb205eaaeb2b39438 Mon Sep 17 00:00:00 2001 From: Julian Baumann Date: Mon, 13 Nov 2023 15:00:28 +0100 Subject: [PATCH] update wagtail to v4.2.4 (#413) Co-authored-by: Paula K --- myhpi/core/markdown/extensions.py | 37 ++------ myhpi/core/models.py | 6 +- myhpi/core/wagtail_hooks.py | 2 +- myhpi/polls/models.py | 4 +- myhpi/search/views.py | 2 +- myhpi/static/js/admin/easymde_custom.js | 4 +- myhpi/tests/test_markdown_extensions.py | 30 ------ myhpi/urls.py | 2 +- poetry.lock | 118 ++++++------------------ pyproject.toml | 6 +- 10 files changed, 47 insertions(+), 164 deletions(-) diff --git a/myhpi/core/markdown/extensions.py b/myhpi/core/markdown/extensions.py index 2e51d4da..0a662433 100644 --- a/myhpi/core/markdown/extensions.py +++ b/myhpi/core/markdown/extensions.py @@ -1,13 +1,11 @@ import re -import markdown from django.core.exceptions import ObjectDoesNotExist from django.utils.translation import gettext_lazy as _ -from markdown import Extension +from markdown import Extension, util from markdown.inlinepatterns import LinkInlineProcessor from markdown.preprocessors import Preprocessor -from wagtail.core.models import Page -from wagtail.images.models import Image +from wagtail.models import Page class MinutesBasePreprocessor(Preprocessor): @@ -147,40 +145,22 @@ def decrease(self, match): class InternalLinkPattern(LinkInlineProcessor): def handleMatch(self, m, data=None): - el = markdown.util.etree.Element("a") + el = util.etree.Element("a") try: el.set("href", self.url(m.group("id"))) - el.text = markdown.util.AtomicString(m.group("title")) + el.text = util.AtomicString(m.group("title")) except ObjectDoesNotExist: - el.text = markdown.util.AtomicString(_("[missing link]")) + el.text = util.AtomicString(_("[missing link]")) return el, m.start(0), m.end(0) def url(self, id): return Page.objects.get(id=id).localized.get_url() + @staticmethod def default_pattern(): return r"\[(?P[^\[]+)\]\(page:(?P<id>\d+)\)" -class ImagePattern(LinkInlineProcessor): - def handleMatch(self, m, data=None): - el = markdown.util.etree.Element("img") - try: - el.set("src", self.url(m.group("id"))) - el.set("alt", markdown.util.AtomicString(m.group("title"))) - el.set("class", "rendered-image") - except ObjectDoesNotExist: - el = markdown.util.etree.Element("span") - el.text = markdown.util.AtomicString(_("[missing image]")) - return el, m.start(0), m.end(0) - - def url(self, id): - return Image.objects.get(id=id).get_rendition("width-800").url - - def default_pattern(): - return r"!\[(?P<title>[^\[]+)\]\(image:(?P<id>\d+)\)" - - class MinuteExtension(Extension): def extendMarkdown(self, md): md.registerExtension(self) @@ -195,8 +175,3 @@ def extendMarkdown(self, md): "InternalLinkPattern", 200, ) - md.inlinePatterns.register( - ImagePattern(ImagePattern.default_pattern(), md), - "ImagePattern", - 200, - ) diff --git a/myhpi/core/models.py b/myhpi/core/models.py index 34e529c6..b7e418ce 100644 --- a/myhpi/core/models.py +++ b/myhpi/core/models.py @@ -10,10 +10,10 @@ from modelcluster.contrib.taggit import ClusterTaggableManager from modelcluster.fields import ParentalKey, ParentalManyToManyField from taggit.models import ItemBase, TagBase -from wagtail.admin.edit_handlers import FieldPanel, PublishingPanel from wagtail.admin.forms import WagtailAdminPageForm -from wagtail.core.models import Page, Site +from wagtail.admin.panels import FieldPanel, PublishingPanel from wagtail.documents.models import Document +from wagtail.models import Page, Site from wagtail.search import index from wagtail.snippets.models import register_snippet @@ -195,7 +195,7 @@ class Minutes(BasePage): FieldPanel("date"), FieldPanel("moderator"), FieldPanel("author"), - FieldPanel("participants", widget=UserSelectWidget), + FieldPanel("participants", widget=UserSelectWidget({"data-width": "100%"})), FieldPanel("labels"), FieldPanel("body"), FieldPanel("guests"), diff --git a/myhpi/core/wagtail_hooks.py b/myhpi/core/wagtail_hooks.py index f523131d..398e1324 100644 --- a/myhpi/core/wagtail_hooks.py +++ b/myhpi/core/wagtail_hooks.py @@ -5,8 +5,8 @@ from django.db.models import Q from django.templatetags.static import static from django.utils.html import format_html +from wagtail import hooks from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register -from wagtail.core import hooks from myhpi.core.models import ( AbbreviationExplanation, diff --git a/myhpi/polls/models.py b/myhpi/polls/models.py index d43680d4..bcc6f401 100644 --- a/myhpi/polls/models.py +++ b/myhpi/polls/models.py @@ -6,8 +6,8 @@ from django.db.models import F, Sum from django.shortcuts import redirect from modelcluster.fields import ParentalKey -from wagtail.admin.edit_handlers import FieldPanel, InlinePanel -from wagtail.core.models import Orderable, Page +from wagtail.admin.panels import FieldPanel, InlinePanel +from wagtail.models import Orderable, Page from wagtail.search import index from myhpi.core.markdown.fields import CustomMarkdownField diff --git a/myhpi/search/views.py b/myhpi/search/views.py index 1abf9d02..183508bb 100644 --- a/myhpi/search/views.py +++ b/myhpi/search/views.py @@ -1,7 +1,7 @@ from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.db.models import Q from django.template.response import TemplateResponse -from wagtail.core.models import Page +from wagtail.models import Page from wagtail.search.models import Query from myhpi.core.models import BasePage diff --git a/myhpi/static/js/admin/easymde_custom.js b/myhpi/static/js/admin/easymde_custom.js index 1ba2f49a..f3d7277a 100644 --- a/myhpi/static/js/admin/easymde_custom.js +++ b/myhpi/static/js/admin/easymde_custom.js @@ -68,8 +68,8 @@ window.wagtailMarkdown.options = { url: "/admin/images/chooser/", onload: IMAGE_CHOOSER_MODAL_ONLOAD_HANDLERS, responses: { - imageChosen: function (t) { - editor.codemirror.replaceSelection("![" + t.title + "](image:" + t.id + ")"); + chosen: function (t) { + editor.codemirror.replaceSelection("![" + t.title + "](image:" + t.id + ",class=rendered-image,filter=width-800)"); } }, diff --git a/myhpi/tests/test_markdown_extensions.py b/myhpi/tests/test_markdown_extensions.py index 2a418063..c4eabd8c 100644 --- a/myhpi/tests/test_markdown_extensions.py +++ b/myhpi/tests/test_markdown_extensions.py @@ -1,13 +1,8 @@ import re -from typing import Collection import django from django.test import TestCase from django.utils.translation import activate -from wagtail.core.models import Page -from wagtail.images.models import Image - -from myhpi.core.markdown.extensions import ImagePattern django.setup() @@ -103,28 +98,3 @@ def test_internal_link_preprocessor(self): text = f"[Page title](page:{test_page.id})" el, _, _ = ilp.handleMatch(re.match(ilp.pattern, text)) self.assertEqual(el.attrib["href"], test_page.localized.get_url()) - - def test_image_pattern(self): - activate("en") - from django.core.files.uploadedfile import SimpleUploadedFile - - ip = ImagePattern(ImagePattern.default_pattern()) - - image_file = SimpleUploadedFile( - name="test_image.jpg", - content=open("myhpi/tests/files/test_image.jpg", "rb").read(), - content_type="image/jpeg", - ) - - image = Image.objects.create( - title="Test image", - file=image_file, - ) - - text = f"![Alt text](image:{image.id})" - invalid_text = "![Alt text](image:1234567890)" - el, _, _ = ip.handleMatch(re.match(ip.pattern, text)) - self.assertEqual(el.attrib["src"], image.get_rendition("width-800").url) - - el, _, _ = ip.handleMatch(re.match(ip.pattern, invalid_text)) - self.assertEqual(el.text, "[missing image]") diff --git a/myhpi/urls.py b/myhpi/urls.py index 2e4e5c3b..f6b91adf 100644 --- a/myhpi/urls.py +++ b/myhpi/urls.py @@ -6,8 +6,8 @@ from django.contrib.auth import views as auth_views from django.urls import include, path, reverse_lazy from django.views.generic import RedirectView +from wagtail import urls as wagtail_urls from wagtail.admin import urls as wagtailadmin_urls -from wagtail.core import urls as wagtail_urls from wagtail.documents import urls as wagtaildocs_urls from myhpi.search import views as search_views diff --git a/poetry.lock b/poetry.lock index edba7a54..6a764378 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. [[package]] name = "anyascii" @@ -1387,32 +1387,6 @@ files = [ {file = "sqlparse-0.4.2.tar.gz", hash = "sha256:0c00730c74263a94e5a9919ade150dfc3b19c574389985446148402998287dae"}, ] -[[package]] -name = "tablib" -version = "3.2.1" -description = "Format agnostic tabular data library (XLS, JSON, YAML, CSV)" -optional = false -python-versions = ">=3.7" -files = [ - {file = "tablib-3.2.1-py3-none-any.whl", hash = "sha256:870d7e688f738531a14937a055e8bba404fbc388e77d4d500b2c904075d1019c"}, - {file = "tablib-3.2.1.tar.gz", hash = "sha256:a57f2770b8c225febec1cb1e65012a69cf30dd28be810e0ff98d024768c7d0f1"}, -] - -[package.dependencies] -openpyxl = {version = ">=2.6.0", optional = true, markers = "extra == \"xlsx\""} -xlrd = {version = "*", optional = true, markers = "extra == \"xls\""} -xlwt = {version = "*", optional = true, markers = "extra == \"xls\""} - -[package.extras] -all = ["markuppy", "odfpy", "openpyxl (>=2.6.0)", "pandas", "pyyaml", "tabulate", "xlrd", "xlwt"] -cli = ["tabulate"] -html = ["markuppy"] -ods = ["odfpy"] -pandas = ["pandas"] -xls = ["xlrd", "xlwt"] -xlsx = ["openpyxl (>=2.6.0)"] -yaml = ["pyyaml"] - [[package]] name = "telepath" version = "0.2" @@ -1523,76 +1497,78 @@ testing = ["coverage (>=6.2)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7 [[package]] name = "wagtail" -version = "3.0.3" +version = "4.2.4" description = "A Django content management system." optional = false python-versions = ">=3.7" files = [ - {file = "wagtail-3.0.3-py3-none-any.whl", hash = "sha256:111ed9a0a6ff26d5d881d52deb4bf52b627d79a53c43829611752dbb68a9192f"}, - {file = "wagtail-3.0.3.tar.gz", hash = "sha256:23b3e541401355ea183372582050ea52b049c956dd5b506197f957bb68423ab3"}, + {file = "wagtail-4.2.4-py3-none-any.whl", hash = "sha256:93e8d39a14a44099ca620e46613a3a2319b1d10c622dc7f0ff8658807b18190c"}, + {file = "wagtail-4.2.4.tar.gz", hash = "sha256:4bf146194e1725cd4305bf1998f507d46f587e207d609bc2ec73a6c5cce04410"}, ] [package.dependencies] anyascii = ">=0.1.5" -beautifulsoup4 = ">=4.8,<4.10" -Django = ">=3.2,<4.1" -django-filter = ">=2.2,<22" +beautifulsoup4 = ">=4.8,<4.12" +Django = ">=3.2,<4.2" +django-filter = ">=2.2,<23" django-modelcluster = ">=6.0,<7.0" django-permissionedforms = ">=0.1,<1.0" -django-taggit = ">=2.0,<3.0" +django-taggit = ">=2.0,<4.0" django-treebeard = ">=4.5.1,<5.0" djangorestframework = ">=3.11.1,<4.0" draftjs-exporter = ">=2.1.5,<3.0" html5lib = ">=0.999,<2" l18n = ">=2018.5" +openpyxl = ">=3.0.10,<4.0" Pillow = ">=4.0.0,<10.0.0" requests = ">=2.11.1,<3.0" -tablib = {version = ">=0.14.0", extras = ["xls", "xlsx"]} telepath = ">=0.1.1,<1" Willow = ">=1.4,<1.5" -xlsxwriter = ">=1.2.8,<4.0" [package.extras] -docs = ["Sphinx (>=1.5.2)", "myst-parser (==0.17.0)", "pyenchant (>=3.1.1,<4)", "sphinx-autobuild (>=0.6.0)", "sphinx-wagtail-theme (==5.1.1)", "sphinxcontrib-spelling (>=5.4.0,<6)"] -testing = ["Jinja2 (>=3.0,<3.2)", "azure-mgmt-cdn (>=5.1,<6.0)", "azure-mgmt-frontdoor (>=0.3,<0.4)", "black (==22.3.0)", "boto3 (>=1.16,<1.17)", "coverage (>=3.7.0)", "curlylint (==0.13.1)", "django-pattern-library (>=0.7,<0.8)", "djhtml (==1.4.13)", "doc8 (==0.8.1)", "elasticsearch (>=5.0,<6.0)", "flake8 (>=3.6.0)", "flake8-assertive (==2.0.0)", "flake8-blind-except (==0.1.1)", "flake8-comprehensions (==3.8.0)", "flake8-print (==5.0.0)", "freezegun (>=0.3.8)", "isort (==5.6.4)", "openpyxl (>=2.6.4)", "polib (>=1.1,<2.0)", "python-dateutil (>=2.7)", "pytz (>=2014.7)"] +docs = ["Sphinx (>=1.5.2)", "myst-parser (==0.18.1)", "pyenchant (>=3.1.1,<4)", "sphinx-autobuild (>=0.6.0)", "sphinx-copybutton (>=0.5,<1.0)", "sphinx-wagtail-theme (==6.0.0)", "sphinxcontrib-spelling (>=5.4.0,<6)"] +testing = ["Jinja2 (>=3.0,<3.2)", "azure-mgmt-cdn (>=12.0,<13.0)", "azure-mgmt-frontdoor (>=1.0,<1.1)", "black (==22.3.0)", "boto3 (>=1.16,<1.17)", "coverage (>=3.7.0)", "curlylint (==0.13.1)", "django-pattern-library (>=0.7,<0.8)", "djhtml (==1.4.13)", "doc8 (==0.8.1)", "elasticsearch (>=5.0,<6.0)", "flake8 (>=3.6.0)", "flake8-assertive (==2.0.0)", "flake8-blind-except (==0.1.1)", "flake8-comprehensions (==3.8.0)", "flake8-print (==5.0.0)", "freezegun (>=0.3.8)", "isort (==5.6.4)", "polib (>=1.1,<2.0)", "python-dateutil (>=2.7)", "pytz (>=2014.7)", "semgrep (==1.3.0)", "wagtail-factories (>=4.0,<5)"] [[package]] name = "wagtail-localize" -version = "1.4" +version = "1.6" description = "Translation plugin for Wagtail CMS" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "wagtail-localize-1.4.tar.gz", hash = "sha256:fd1195de3c23e3a061576f1b947fe7498676ff5678fe008d4cd388125a20a54a"}, - {file = "wagtail_localize-1.4-py3-none-any.whl", hash = "sha256:40f974809509de54dcc18ee6aa98908bffd9dfaba53150e214f4046b2286920e"}, + {file = "wagtail_localize-1.6-py3-none-any.whl", hash = "sha256:bc46941cd0dc287d8bca0fa15f50fca6ee7bb45f01af6161e75b0173b7af118f"}, + {file = "wagtail_localize-1.6.tar.gz", hash = "sha256:b590d095ca0752a0247909ca8cea71fbaa54b173cd59aa63f460a4a6b0fc74d0"}, ] [package.dependencies] -Django = ">=3.2,<4.2" +Django = ">=3.2,<5.0" polib = ">=1.1,<2.0" typing_extensions = ">=4.0" -Wagtail = ">=2.15,<5.0" +Wagtail = ">=4.1" [package.extras] -documentation = ["mkdocs (==1.1.2)", "mkdocs-include-markdown-plugin (==2.8.0)", "mkdocs-material (==6.2.8)", "mkdocs-mermaid2-plugin (==0.5.1)", "mkdocstrings (==0.14.0)", "pygments (==2.11.2)"] +documentation = ["mkdocs (==1.4.3)", "mkdocs-autorefs (>=0.4.0,<0.5)", "mkdocs-include-markdown-plugin (>=4.0.4,<5)", "mkdocs-material (>=9.1,<10)", "mkdocstrings[python] (==0.22.0)", "pygments (>=2.15,<2.16)"] google = ["google-cloud-translate (>=3.0.0)"] -testing = ["dj-database-url (==0.5.0)", "django-rq (>=2.5,<3.0)", "freezegun (==1.1.0)", "google-cloud-translate (>=3.0.0)"] +testing = ["dj-database-url (>=2.1.0,<3)", "django-rq (>=2.5,<3.0)", "freezegun (>=1.2,<2)", "google-cloud-translate (>=3.0.0)", "pre-commit (>=3.4,<4)"] [[package]] name = "wagtail-markdown" -version = "0.10.0" +version = "0.11.1" description = "Markdown support for Wagtail" optional = false -python-versions = "*" +python-versions = ">=3.8" files = [ - {file = "wagtail-markdown-0.10.0.tar.gz", hash = "sha256:b16be4b6e3518cc6dd15ab335cbc6d6a9122b5d7e3a61fa11c83597e2660044e"}, - {file = "wagtail_markdown-0.10.0-py2.py3-none-any.whl", hash = "sha256:e4a97eee0211eebaab9c850669e647bc1c8ceb70df38b4db5a2c3d8b02ebaf69"}, + {file = "wagtail_markdown-0.11.1-py3-none-any.whl", hash = "sha256:3d2c5dcfac718c3fc03f2ed05aca535b2aa70f71254599505ee272c54437db21"}, + {file = "wagtail_markdown-0.11.1.tar.gz", hash = "sha256:afcb64efac5b1b57de9f7cc475987c0c7dec5b669833e4617ec4658880de0f77"}, ] [package.dependencies] bleach = ">=3.3,<5" Markdown = ">=3.3,<4" -Wagtail = ">=2.15" +Wagtail = ">=4.1" + +[package.extras] +testing = ["pre-commit (>=3.3.0,<4)", "tox (>=4.6.4,<5)"] [[package]] name = "webencodings" @@ -1702,44 +1678,6 @@ files = [ {file = "wrapt-1.14.1.tar.gz", hash = "sha256:380a85cf89e0e69b7cfbe2ea9f765f004ff419f34194018a6827ac0e3edfed4d"}, ] -[[package]] -name = "xlrd" -version = "2.0.1" -description = "Library for developers to extract data from Microsoft Excel (tm) .xls spreadsheet files" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" -files = [ - {file = "xlrd-2.0.1-py2.py3-none-any.whl", hash = "sha256:6a33ee89877bd9abc1158129f6e94be74e2679636b8a205b43b85206c3f0bbdd"}, - {file = "xlrd-2.0.1.tar.gz", hash = "sha256:f72f148f54442c6b056bf931dbc34f986fd0c3b0b6b5a58d013c9aef274d0c88"}, -] - -[package.extras] -build = ["twine", "wheel"] -docs = ["sphinx"] -test = ["pytest", "pytest-cov"] - -[[package]] -name = "xlsxwriter" -version = "3.0.3" -description = "A Python module for creating Excel XLSX files." -optional = false -python-versions = ">=3.4" -files = [ - {file = "XlsxWriter-3.0.3-py3-none-any.whl", hash = "sha256:df0aefe5137478d206847eccf9f114715e42aaea077e6a48d0e8a2152e983010"}, - {file = "XlsxWriter-3.0.3.tar.gz", hash = "sha256:e89f4a1d2fa2c9ea15cde77de95cd3fd8b0345d0efb3964623f395c8c4988b7f"}, -] - -[[package]] -name = "xlwt" -version = "1.3.0" -description = "Library to create spreadsheet files compatible with MS Excel 97/2000/XP/2003 XLS files, on any platform, with Python 2.6, 2.7, 3.3+" -optional = false -python-versions = "*" -files = [ - {file = "xlwt-1.3.0-py2.py3-none-any.whl", hash = "sha256:a082260524678ba48a297d922cc385f58278b8aa68741596a87de01a9c628b2e"}, - {file = "xlwt-1.3.0.tar.gz", hash = "sha256:c59912717a9b28f1a3c2a98fd60741014b06b043936dcecbc113eaaada156c88"}, -] - [[package]] name = "zipp" version = "3.8.1" @@ -1762,4 +1700,4 @@ pgsql = [] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "1fa142f38a5a71b798119f6b7a365e73d2eb36f16a6db8bec26f1477075eb139" +content-hash = "419e7cf2ac1daed69b8e095fe6f4a6bcdf7d68934c1f8c522820e025c4a897ef" diff --git a/pyproject.toml b/pyproject.toml index faa0c9a5..0cc8f746 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,9 +7,9 @@ license = "MIT" [tool.poetry.dependencies] python = "^3.8" -wagtail = ">=2.16.2" +wagtail = "^4.2.4" django-environ = "^0.10.0" -wagtail-localize = "^1.4" +wagtail-localize = "^1.6" mozilla-django-oidc = "^3.0.0" django-bootstrap-icons = "^0.8.3" django-select2 = "^8.1.2" @@ -18,7 +18,7 @@ django-debug-toolbar = "^4.2.0" django-permissionedforms = "^0.1" tenca = "^0.0.2" html2text = "^2020.1.16" -wagtail-markdown = "^0.10.0" +wagtail-markdown = "^0.11.1" autoflake = "^2.2.1" [tool.poetry.group.dev.dependencies]