Skip to content

Commit

Permalink
Merge pull request #8 from torchbox-forks/support/wagtail-63
Browse files Browse the repository at this point in the history
Support/wagtail 63
  • Loading branch information
nickmoreton authored Jan 16, 2025
2 parents e9d4c1b + 61b8b40 commit 76e0dfe
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 120 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jobs:
build:
working_directory: ~/wagtailquickcreate
docker:
- image: circleci/python:3.8.0
- image: circleci/python:3.9.0
environment:
PIPENV_VENV_IN_PROJECT: true
DATABASE_URL: postgresql://root@localhost/circle_test?sslmode=disable
Expand All @@ -14,7 +14,7 @@ jobs:
steps:
- checkout
- run: sudo chown -R circleci:circleci /usr/local/bin
- run: sudo chown -R circleci:circleci /usr/local/lib/python3.8/site-packages
- run: sudo chown -R circleci:circleci /usr/local/lib/python3.9/site-packages
- run:
command: |
sudo pip install pipenv
Expand Down
35 changes: 25 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,32 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- python: 3.9
wagtail: wagtail>=4.1
python: ["3.9", "3.10", "3.11", "3.12", "3.13"]
django: ["4.2", "5.0", "5.1"]
wagtail: ["6.3"]
exclude:
- python: "3.9"
django: "5.0"
- python: "3.9"
django: "5.1"
- python: "3.13"
django: "4.2"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
cache: "pip"
cache-dependency-path: "**/setup.cfg"
- run: |
pip install "${{ matrix.wagtail }}"
- run: |

- name: Install dependencies Django - ${{ matrix.django }} Wagtail - ${{ matrix.wagtail }} Python - ${{ matrix.python }}
run: |
python -m pip install --upgrade pip
pip install "django==${{ matrix.django }}"
pip install "wagtail==${{ matrix.wagtail }}"
python --version
pip list
- name: Run tests
run: |
python runtests.py
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Added support for Wagtail 6.3
- Drop support for Wagtail versions 5 & 6
- Updated support for Django 4.2, 5.0 and 5.1
- Drop support for Django versions 2 & 3
- Drop support for Python versions 3.8
- Add support for Python versions 3.13

## Relases up to 2.0.1

Older versions of this package are available for older versions of Wagtail and Django.
See [PyPi](https://pypi.org/project/wagtail-quick-create/#history) for more information.
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Wagtail Quick Create

## Wagtail Quick Create offers shortcut links to create objects from models specified in your settings file.
**Add shortcut links to the admin Home page** create objects from models specified in your settings file.

A panel is added to the admin home, offering a type:
A panel is added to the admin home, offering a model type:

![Quick Create Panel example](./docs/images/dashboard.png)
![Quick Create Panel example](./docs/images/dashboard.jpg)

Clicking a create link will offer a parent selection for the new item
Clicking a create link will bring to the generic Wagtail add page for the model type:

![Parent selection example](./docs/images/create.png)
![Parent selection example](./docs/images/create.jpg)

## Note on parent pages

Expand All @@ -33,25 +33,33 @@ INSTALLED_APPS = [

Also add the models you would like to create quick links for to your settings file as `'your_app_name.YourModelName'`:

EG:
example setting:

```python
WAGTAIL_QUICK_CREATE_PAGE_TYPES = ['news.NewsPage', 'events.EventPage']
```

If you want the Quick Create links panel to _replace_ the wagtail summary panel, you can set this by adding the following to your settings
If you would like to offer image and or document links, this can also be done by specifying the following in your settings:

```python
WAGTAIL_QUICK_CREATE_REPLACE_SUMMARY_PANEL = True
WAGTAIL_QUICK_CREATE_DOCUMENTS = True
WAGTAIL_QUICK_CREATE_IMAGES = True
```

If you would like to offer image and or document links, this can also be done by specifying the following in your settings:
### Customising the panel

The panel is not collapsed by default, but you can collapse it by adding the following to your settings:

```python
WAGTAIL_QUICK_CREATE_DOCUMENTS = True
WAGTAIL_QUICK_CREATE_IMAGES = True
WAGTAIL_QUICK_CREATE_INITIAL_COLLAPSED = True
```

## Compatibility

This package is compatible with Wagtail 6.3 and above.

If you are using a version of Wagtail below 6.3, you can use the [2.0.1](https://pypi.org/project/wagtail-quick-create/2.0.1/) release of this package.

## Contributing

We are happy to receive pull requests for bug fixes, improvements and new features. See [CONTRIBUTING.md](./docs/CONTRIBUTING.md) for more information.
Expand Down
Binary file added docs/images/create.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/create.png
Binary file not shown.
Binary file added docs/images/dashboard.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/dashboard.png
Binary file not shown.
15 changes: 11 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,28 @@
packages=find_packages(exclude=['tests*']),
include_package_data=True,
install_requires=[
'wagtail>=4.1',
'wagtail>=6.3',
],
extras_require={
'testing': [
'beautifulsoup4',
],
},
classifiers=[
'Environment :: Web Environment',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Framework :: Wagtail',
'Framework :: Wagtail :: 4',
'Framework :: Wagtail :: 5',
'Framework :: Wagtail :: 6',
'Framework :: Django :: 4.2',
'Framework :: Django :: 5.0',
'Framework :: Django :: 5.1',
],
)
66 changes: 40 additions & 26 deletions wagtailquickcreate/templates/wagtailquickcreate/create.html
Original file line number Diff line number Diff line change
@@ -1,44 +1,58 @@

{% extends "wagtailadmin/base.html" %}
{% extends "wagtailadmin/generic/listing.html" %}
{% load wagtailadmin_tags static i18n %}
{% block titletag %}{% trans browser_title %}{% endblock %}


{% block content %}
<header class="w-header w-header--merged">
<div class="row row-flush">
<div class="col">
<h1 class="w-header__title">
<img src="{% avatar_url user %}" alt="" class="avatar"/>
Add {{ model_verbose_name }}
</h1>
<h2>{{ user.get_full_name|default:user.get_username }}</h2>

{% block header %}
<header class="w-header">
<div class="row">
<div class="left">
<div class="col">
<h1 class="w-header__title" id="header-title">
<svg class="icon icon-doc-empty-inverse w-header__glyph" aria-hidden="true">
<use href="#icon-doc-empty-inverse"></use>
</svg>Add <span class="w-header__subtitle">{{ model_verbose_name }}</span>
</h1>
</div>
</div>
</div>
</header>
{% endblock %}

{% block listing %}
<div class="nice-padding">
{% if parent_pages %}
<p>Choose a parent section for the new <strong>{{ model_verbose_name }}</strong></p>
{% else %}
<p class="help-block help-warning">
<svg class="icon icon-warning icon" aria-hidden="true"><use href="#icon-warning"></use></svg>
There are no parent <strong>{{ model_verbose_name }}</strong> sections created for child pages to be added to yet...
</p>
{% endif %}
<ul class="listing">
{% if parent_pages %}
<div class="help-block help-info">
Choose a parent section for the new <strong>{{ model_verbose_name }}</strong>
</div>
{% else %}
<p class="help-block help-warning">There are no parent <strong>{{ model_verbose_name }}</strong> sections created for child pages to be added to yet...</p>
{% endif %}

{% for page in parent_pages %}
<li>
<a href="/admin/pages/add/{{model_app|lower}}/{{page.model|lower}}/{{page.id}}/" class="icon icon-plus-inverse icon-larger">
{% for parent in page.ancestors %}
{% if not parent.is_root %}
{{ parent }} >
{% endif %}
{% endfor %}
<strong>{{ page.title }}</strong>
</a>
<div class="row row-flush">
<div class="col12">
<a href="/admin/pages/add/{{model_app|lower}}/{{page.model|lower}}/{{page.id}}/" class="icon icon-plus-inverse icon-larger">
<svg class="icon icon-crosshairs default w-mr-1 w-align-middle" aria-hidden="true"><use href="#icon-crosshairs"></use></svg>
{% for parent in page.ancestors %}
{% if not parent.is_root %}
{{ parent }} >
{% endif %}
{% endfor %}
<strong>{{ page.title }}</strong>
</a>
</div>

</div>
</li>
{% endfor %}
</ul>
</div>
{% endblock %}

{% endblock %}

53 changes: 50 additions & 3 deletions wagtailquickcreate/templates/wagtailquickcreate/panel.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
<section class="panel wagtail_quick_create summary nice-padding">
{{ models }}
</section>
<section class="w-panel w-panel--dashboard" id="quickcreate-section" aria-labelledby="quickcreate-heading" data-panel>
<div class="w-panel__header">
<a class="w-panel__anchor w-panel__anchor--prefix" href="#quickcreate-section" data-panel-anchor=""
aria-labelledby="quickcreate-heading">
<svg class="icon icon-link w-panel__icon" aria-hidden="true">
<use href="#icon-link"></use>
</svg>
</a>
<button class="w-panel__toggle" type="button" aria-label="Toggle section" aria-describedby="quickcreate-heading"
data-panel-toggle="" aria-controls="quickcreate-content" aria-expanded="{{ initial_collapsed.aria_expanded }}">

<svg class="icon icon-placeholder w-panel__icon" aria-hidden="true">
<use href="#icon-placeholder"></use>
</svg>
</button>

<h2 class="w-panel__heading " id="quickcreate-heading" data-panel-heading="">
<span data-panel-heading-text="">Quick Create</span>
</h2>

<a class="w-panel__anchor w-panel__anchor--suffix" href="#quickcreate-section"
aria-labelledby="quickcreate-heading">
<svg class="icon icon-link w-panel__icon" aria-hidden="true">
<use href="#icon-link"></use>
</svg>
</a>
<div class="w-panel__divider"></div>

</div>
<div id="quickcreate-content" class="w-panel__content" {% if initial_collapsed.hidden %}hidden="{{ initial_collapsed.hidden }}"{% endif %}>
<table class="listing listing--dashboard listing-quickcreate">
<tbody>
<tr>
<td>
{% for button in model_buttons %}
{% include "wagtailquickcreate/quickcreate_button.html" with button=button %}
{% endfor %}
</td>
</tr>
</tbody>
</table>
{% for error in model_button_errors %}
<div class="help-block help-warning">
<svg class="icon icon-warning icon" aria-hidden="true"><use href="#icon-warning"></use></svg>
<strong>{{ error }}</strong> found in WAGTAIL_QUICK_CREATE_PAGE_TYPES does not exist.
</div>
{% endfor %}

</div>
</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<a href="{{ button.link }}" class="button bicolor button--icon">
<span class="icon-wrapper">
<svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg>
</span>
{{ button.name }}
</a>
1 change: 0 additions & 1 deletion wagtailquickcreate/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
]

WAGTAIL_SITE_NAME = 'llama-savers'
WAGTAIL_QUICK_CREATE_REPLACE_SUMMARY_PANEL = True
WAGTAIL_QUICK_CREATE_DOCUMENTS = True
WAGTAIL_QUICK_CREATE_IMAGES = True
WAGTAIL_QUICK_CREATE_PAGE_TYPES = ['wagtailquickcreate.tests.standardpages.InformationPage']
Expand Down
31 changes: 26 additions & 5 deletions wagtailquickcreate/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from bs4 import BeautifulSoup

from django.test import TestCase
from django.urls import reverse

Expand Down Expand Up @@ -33,14 +35,33 @@ def test_admin(self):

def test_quickcreate_panel_links(self):
response = self.client.get('/admin/')
self.assertTrue('Add Image' in str(response.content))
self.assertTrue('Add Document' in str(response.content))
self.assertTrue('Add Information page' in str(response.content))
soup = BeautifulSoup(response.content, 'html.parser')
quick_create_content = soup.find('div', id='quickcreate-content')
buttons = quick_create_content.find_all('a')
self.assertTrue(len(buttons) == 3)
self.assertTrue(buttons[0].text.strip() == 'Information page')
self.assertTrue(buttons[0]['href'] == '/admin/quickcreate/create/standardpages/InformationPage/')
self.assertTrue(buttons[1].text.strip() == 'Image')
self.assertTrue(buttons[1]['href'] == '/admin/images/')
self.assertTrue(buttons[2].text.strip() == 'Document')
self.assertTrue(buttons[2]['href'] == '/admin/documents/')

def test_quickcreate_index_page_title(self):
response = self.client.get('/admin/quickcreate/create/standardpages/informationpage/')
soup = BeautifulSoup(response.content, 'html.parser')
title = soup.find('h1')
self.assertTrue(title.text.strip() == 'Add Information page')

def test_first_level_index_page_in_shortcut_view(self):
response = self.client.get('/admin/quickcreate/create/standardpages/informationpage/')
self.assertContains(response, 'Home > <strong>Section 1</strong>', html=True)
soup = BeautifulSoup(response.content, 'html.parser')
parent_link = soup.find('a', href='/admin/pages/add/standardpages/informationpage/3/')
self.assertIsNotNone(parent_link)
self.assertTrue(parent_link.text.replace('\n', ''), 'Home > <strong>Section 1</strong>')

def test_second_level_index_in_shortcut_view(self):
response = self.client.get('/admin/quickcreate/create/standardpages/informationpage/')
self.assertContains(response, 'Home > Section 1 > <strong>Section 2</strong>', html=True)
soup = BeautifulSoup(response.content, 'html.parser')
parent_link = soup.find('a', href='/admin/pages/add/standardpages/informationpage/4/')
self.assertIsNotNone(parent_link)
self.assertTrue(parent_link.text.replace('\n', ''), 'Home > Section 1 > <strong>Section 2</strong>')
Loading

0 comments on commit 76e0dfe

Please sign in to comment.