forked from torchbox/wagtail-footnotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from torchbox-forks/support/wagtail-60
Support/wagtail 60
- Loading branch information
Showing
12 changed files
with
122 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,18 +20,18 @@ env: | |
TOX_TESTENV_PASSENV: FORCE_COLOR | ||
PIP_DISABLE_PIP_VERSION_CHECK: "1" | ||
PIP_NO_PYTHON_VERSION_WARNING: "1" | ||
PYTHON_LATEST: "3.11" | ||
PYTHON_LATEST: "3.12" | ||
|
||
|
||
jobs: | ||
|
||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/setup-python@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{env.PYTHON_LATEST}} | ||
- uses: pre-commit/[email protected] | ||
|
@@ -44,9 +44,9 @@ jobs: | |
python: ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
- name: 🐍 Setup Python ${{ matrix.python }} | ||
uses: actions/setup-python@v4 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python }} | ||
- name: 📦 Install dependencies | ||
|
@@ -57,13 +57,13 @@ jobs: | |
- name: 🏗️ Build wheel | ||
run: python -Im flit build --format wheel | ||
|
||
- name: 🧪 Run tox targets for Python ${{ matrix.python-version }} | ||
- name: 🧪 Run tox targets for Python ${{ matrix.python }} | ||
run: tox --installpkg ./dist/*.whl | ||
|
||
- name: ⬆️ Upload coverage data | ||
uses: actions/upload-artifact@v3 | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: coverage-data | ||
name: coverage-data-${{ matrix.python }} | ||
path: .coverage.* | ||
if-no-files-found: ignore | ||
retention-days: 1 | ||
|
@@ -72,20 +72,21 @@ jobs: | |
runs-on: ubuntu-latest | ||
needs: tests | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/setup-python@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
# Use latest Python, so it understands all syntax. | ||
python-version: ${{env.PYTHON_LATEST}} | ||
|
||
- run: python -Im pip install --upgrade "coverage[toml]>=7.2,<8.0" | ||
|
||
- name: ⬇️ Download coverage data | ||
uses: actions/download-artifact@v3 | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: coverage-data | ||
pattern: coverage-data-* | ||
merge-multiple: true | ||
|
||
- name: + Combine coverage | ||
run: | | ||
|
@@ -95,7 +96,7 @@ jobs: | |
echo "## Coverage summary" >> $GITHUB_STEP_SUMMARY | ||
python -Im coverage report --format=markdown >> $GITHUB_STEP_SUMMARY | ||
- name: 📈 Upload HTML report if check failed. | ||
uses: actions/upload-artifact@v3 | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: html-report | ||
path: htmlcov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
wagtail_footnotes/static/footnotes/js/read-only-uuid-controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// myapp/static/js/read-only-uuid-controller.js | ||
|
||
class CustomEditorController extends window.StimulusModule.Controller { | ||
connect() { | ||
setUUID(this.element.id); | ||
} | ||
} | ||
|
||
window.wagtail.app.register('read-only-uuid', CustomEditorController); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,64 @@ | ||
from django.forms import HiddenInput | ||
from wagtail.utils.widgets import WidgetWithScript | ||
from wagtail import VERSION as WAGTAIL_VERSION | ||
|
||
|
||
class ReadonlyUUIDInput(WidgetWithScript, HiddenInput): | ||
""" | ||
This isn't really read-only. It's a hidden input with an an adjacent div | ||
showing the current value; that way we can set the value in JavaScript, but | ||
the user can't easily change it. | ||
""" | ||
if WAGTAIL_VERSION and WAGTAIL_VERSION >= (6, 0): | ||
from django.forms import Media | ||
from django.utils.safestring import mark_safe | ||
|
||
def render_html(self, name, value, attrs): | ||
"""Render the HTML (non-JS) portion of the field markup""" | ||
hidden = super(WidgetWithScript, self).render(name, value, attrs) | ||
display_value = value[:6] if value is not None else value | ||
shown = f'<div id="{attrs["id"]}_display-value" style="padding-top: 1.2em;">{display_value}</div>' | ||
return shown + hidden | ||
class ReadonlyUUIDInput(HiddenInput): | ||
""" | ||
This isn't really read-only. It's a hidden input with an an adjacent div | ||
showing the current value; that way we can set the value in JavaScript, but | ||
the user can't easily change it. | ||
""" | ||
|
||
def render_js_init(self, id_, name, value): | ||
return f'setUUID("{id_}");' | ||
def render(self, name, value, attrs=None, renderer=None): | ||
# no point trying to come up with sensible semantics for when 'id' is missing from attrs, | ||
# so let's make sure it fails early in the process | ||
try: | ||
attrs["id"] | ||
except (KeyError, TypeError) as exc: | ||
raise TypeError( | ||
"ReadonlyUUIDInput cannot be rendered without an 'id' attribute" | ||
) from exc | ||
|
||
widget_html = self.render_html(name, value, attrs) | ||
|
||
return mark_safe(widget_html) # noqa: S308 | ||
|
||
def render_html(self, name, value, attrs): | ||
"""Render the HTML (non-JS) portion of the field markup""" | ||
hidden = super().render(name, value, attrs) | ||
display_value = value[:6] if value is not None else value | ||
shown = f'<div id="{attrs["id"]}_display-value" style="padding-top: 1.2em;">{display_value}</div>' | ||
return shown + hidden | ||
|
||
def build_attrs(self, *args, **kwargs): | ||
attrs = super().build_attrs(*args, **kwargs) | ||
attrs["data-controller"] = "read-only-uuid" | ||
return attrs | ||
|
||
@property | ||
def media(self): | ||
return Media(js=["footnotes/js/read-only-uuid-controller.js"]) | ||
|
||
else: | ||
from wagtail.utils.widgets import WidgetWithScript | ||
|
||
class ReadonlyUUIDInput(WidgetWithScript, HiddenInput): | ||
""" | ||
This isn't really read-only. It's a hidden input with an an adjacent div | ||
showing the current value; that way we can set the value in JavaScript, but | ||
the user can't easily change it. | ||
""" | ||
|
||
def render_html(self, name, value, attrs): | ||
"""Render the HTML (non-JS) portion of the field markup""" | ||
hidden = super(WidgetWithScript, self).render(name, value, attrs) | ||
display_value = value[:6] if value is not None else value | ||
shown = f'<div id="{attrs["id"]}_display-value" style="padding-top: 1.2em;">{display_value}</div>' | ||
return shown + hidden | ||
|
||
def render_js_init(self, id_, name, value): | ||
return f'setUUID("{id_}");' |