Skip to content

Commit

Permalink
Merge pull request #398 from jorenham/wagtail51
Browse files Browse the repository at this point in the history
Fixed deprecated hook for wagtail>=5.1
  • Loading branch information
DiogoMarques29 authored Aug 25, 2023
2 parents 5ddde55 + 811387e commit 52aafb4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python: ["3.8", "3.9", "3.10", "3.11"]
django-modeltranslation: ["0.17", "0.18"]
wagtail: ["4.0", "4.1", "5.0"]
wagtail: ["4.0", "4.1", "5.0", "5.1"]
database: ["sqlite", "postgres", "mysql"]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

<ul class="fields">
{% for field in form.visible_fields %}
{% include "wagtailadmin/shared/field_as_li.html" with field=field %}
<li>
{% include "wagtailadmin/shared/field.html" %}
</li>
{% endfor %}
</ul>

Expand Down
1 change: 0 additions & 1 deletion wagtail_modeltranslation/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
'wagtail.contrib.frontend_cache',
'wagtail.contrib.search_promotions',
'wagtail.contrib.settings',
'wagtail.contrib.modeladmin',
'wagtail.contrib.table_block',
'wagtail.contrib.forms',

Expand Down
16 changes: 11 additions & 5 deletions wagtail_modeltranslation/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@

from .patch_wagtailadmin_forms import PatchedCopyForm

from wagtail import hooks
from wagtail import hooks, VERSION as _WAGTAIL_VERSION
from wagtail.models import Page
from wagtail.rich_text.pages import PageLinkHandler
from wagtail.admin import messages

from wagtail.admin.views.pages.utils import get_valid_next_url_from_request

if _WAGTAIL_VERSION >= (5, 1):
# https://docs.wagtail.org/en/stable/releases/5.1.html#insert-editor-css-hook-is-deprecated
_HOOK_INSERT_CSS = 'insert_global_admin_css'
else:
_HOOK_INSERT_CSS = 'insert_editor_css'


@hooks.register('insert_editor_js')
def translated_slugs():
Expand Down Expand Up @@ -174,20 +180,20 @@ def streamfields_translation_copy():
return js_includes


@hooks.register('insert_editor_css')
@hooks.register(_HOOK_INSERT_CSS)
def modeltranslation_page_editor_css():
filename = 'wagtail_modeltranslation/css/page_editor_modeltranslation.css'
return format_html('<link rel="stylesheet" href="{}" >'.format(static(filename)))
return format_html('<link rel="stylesheet" href="{}">', static(filename))


@hooks.register('insert_editor_css')
@hooks.register(_HOOK_INSERT_CSS)
def modeltranslation_page_editor_titles_css():
"""
Patch admin styles, in particular page title headings missing in Wagtail 4
"""

filename = 'wagtail_modeltranslation/css/admin_patch.css'
return format_html('<link rel="stylesheet" href="{}" >'.format(static(filename)))
return format_html('<link rel="stylesheet" href="{}">', static(filename))


@hooks.register('register_rich_text_link_handler')
Expand Down

0 comments on commit 52aafb4

Please sign in to comment.