Skip to content

Commit

Permalink
Merge pull request #23 from kevinhowbrook/issue/22-menu-configuration
Browse files Browse the repository at this point in the history
Wagtail 4 updates
  • Loading branch information
kevinhowbrook committed Apr 2, 2023
2 parents 839ef65 + 54be3f9 commit db81326
Show file tree
Hide file tree
Showing 19 changed files with 174 additions and 104 deletions.
Binary file added .coverage
Binary file not shown.
17 changes: 3 additions & 14 deletions .github/workflows/main.yml
Expand Up @@ -7,11 +7,7 @@ on:
branches: [master]

# Current configuration:
# - python 3.9, wagtail 4.0
# - python 3.9, wagtail 3.0
# - python 3.9, wagtail 2.16
# - python 3.8, wagtail 2.16

# - python 3.9, wagtail 4.1

jobs:
lint:
Expand Down Expand Up @@ -42,14 +38,7 @@ jobs:
matrix:
include:
- python: 3.9
wagtail: wagtail>=4.0,<5.0
latest: true
- python: 3.9
wagtail: wagtail>=3.0,<4.0
- python: 3.9
wagtail: wagtail>=2.16,<3.0
- python: 3.8
wagtail: wagtail>=2.16,<3.0
wagtail: wagtail>=4.1,<5.0
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
Expand All @@ -67,4 +56,4 @@ jobs:
- if: ${{ matrix.latest }}
uses: codecov/codecov-action@v2
with:
name: Python 3.9
name: Python 3.9
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,26 @@
default_language_version:
node: system
python: python3.9
repos:
- repo: https://github.com/python/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
# flake8 config is in setup.cfg
rev: 3.8.3
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.3.2
hooks:
- id: prettier
types_or: [markdown, css, scss, javascript, ts, tsx, json, yaml, vue]
- repo: https://github.com/awebdeveloper/pre-commit-stylelint
rev: c4c991cd38b0218735858716b09924f8b20e3812
hooks:
- id: stylelint
files: \.(scss|vue)$
additional_dependencies:
- stylelint@13.13.1
- stylelint-config-torchbox@1.1.0
64 changes: 60 additions & 4 deletions README.md
@@ -1,4 +1,5 @@
# Wagtail Guide

![tests](https://github.com/kevinhowbrook/wagtailguide/workflows/Test/badge.svg) [![codecov](https://codecov.io/gh/kevinhowbrook/wagtailguide/branch/master/graph/badge.svg?token=K2XKBfubBh)](https://codecov.io/gh/kevinhowbrook/wagtailguide)

## What is it?
Expand All @@ -23,21 +24,76 @@ INSTALLED_APPS = [
]
```

## Dependencies
Wagtail Guide requires `wagtail>=2.16`
## Settings and configuration

Wagtail guide has some customisation options...

**WAGTAIL_GUIDE_MENU_LABEL**
Use this setting to define your own menu label for viewing the guide.

**ADD_WAGTAIL_GUIDE_TO_HELP_MENU**
This setting will place the guide within the 'Help' menu.

**HIDE_WAGTAIL_CORE_EDITOR_GUIDE**
You can use this setting to turn off the Wagtail core Editor Guide link

### Examples of customisation via settings

Here is an example of a custom menu label (outlined here in orange),
and placing the editor guide link in the help menu:

```
WAGTAIL_GUIDE_SETTINGS = {
"ADD_WAGTAIL_GUIDE_TO_HELP_MENU": True,
"WAGTAIL_GUIDE_MENU_LABEL": "CMS Publishing Guide",
"HIDE_WAGTAIL_CORE_EDITOR_GUIDE": False,
}
```

![](screenshots/custom-label.png)

Here is an example of hiding the core Editor Guide link and just using ours:

```
WAGTAIL_GUIDE_SETTINGS = {
"ADD_WAGTAIL_GUIDE_TO_HELP_MENU": True,
"WAGTAIL_GUIDE_MENU_LABEL": "CMS Publishing Guide",
"HIDE_WAGTAIL_CORE_EDITOR_GUIDE": True,
}
```

![](screenshots/remove-help.png)

You can define them in your project settings file like this:

```
WAGTAIL_GUIDE_SETTINGS = {
"ADD_WAGTAIL_GUIDE_TO_HELP_MENU": False,
"WAGTAIL_GUIDE_MENU_LABEL": "WG guide menu label",
"HIDE_WAGTAIL_CORE_EDITOR_GUIDE": True,
}
```

## Usage

To edit the guide, the user needs to be an admin, or have the `Manage editor guide` 'change' value checked in their user group permissions.

### Editing the guide

To edit the guide, from the left hand menu open settings > then click 'Manage editor guide'. Edit your content and then save.

![guide edit](https://i.imgur.com/ZGRlu3I.png)
![guide edit](screenshots/editing.png)

#### Guide navigation menu

If more than one 'heading' blocks are added to the content, an automatic menu will be displayed at the top of the guide under the heading 'Contents'

### Viewing the guide

Once logged in, a new menu icon towards the bottom of the left hand menu will be visible labeled as 'Editor guide':

![guide view](https://i.imgur.com/HbCVvXy.png)
![guide view](screenshots/default.png)

## Dependencies

Wagtail Guide requires `wagtail>=4.1`
Binary file added screenshots/custom-label.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/default.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/editing.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/remove-help.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions setup.cfg
Expand Up @@ -5,8 +5,8 @@ description-file = README.md
[options.extras_require]
lint =
black ==22.3.0
isort ==5.9.3
flake8 ==3.9.2
isort ==5.7.0
flake8 ==3.8.3

[flake8]
ignore = C901,W503
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -14,7 +14,7 @@

setup(
name="wagtail_guide",
version="1.0.8",
version="2.0.0",
description="Adds functionality to add and edit a CMS guide page for editors.",
long_description=long_description,
long_description_content_type="text/markdown",
Expand All @@ -25,7 +25,7 @@
packages=find_packages(exclude=["tests*"]),
include_package_data=True,
install_requires=[
"wagtail>=2.16",
"wagtail>=4.1",
],
testing_extras=[
"coverage>=6.4.1",
Expand Down
9 changes: 2 additions & 7 deletions wagtail_guide/migrations/0001_initial.py
Expand Up @@ -2,14 +2,9 @@

import django.db.models.deletion
from django.db import migrations, models
from wagtail import VERSION as WAGTAIL_VERSION

if WAGTAIL_VERSION >= (3, 0):
import wagtail.blocks as wagtail_blocks
import wagtail.fields as wagtail_fields
else:
import wagtail.core.blocks as wagtail_blocks
import wagtail.core.fields as wagtail_fields
import wagtail.blocks as wagtail_blocks
import wagtail.fields as wagtail_fields

import wagtail.embeds.blocks
import wagtail.images.blocks
Expand Down
Expand Up @@ -5,12 +5,8 @@
from django.db import migrations
from wagtail import VERSION as WAGTAIL_VERSION

if WAGTAIL_VERSION >= (3, 0):
import wagtail.blocks as wagtail_blocks
import wagtail.fields as wagtail_fields
else:
import wagtail.core.blocks as wagtail_blocks
import wagtail.core.fields as wagtail_fields
import wagtail.blocks as wagtail_blocks
import wagtail.fields as wagtail_fields


class Migration(migrations.Migration):
Expand Down
32 changes: 6 additions & 26 deletions wagtail_guide/models.py
@@ -1,24 +1,12 @@
from django.db import models
from modelcluster.models import ClusterableModel
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail import blocks
from wagtail.admin.panels import FieldPanel
from wagtail.contrib.settings.models import BaseSiteSetting, register_setting
from wagtail.embeds.blocks import EmbedBlock
from wagtail.fields import StreamField
from wagtail.images.blocks import ImageChooserBlock

if WAGTAIL_VERSION >= (4, 0):
from wagtail.contrib.settings.models import BaseSiteSetting, register_setting
else:
from wagtail.contrib.settings.models import BaseSetting as BaseSiteSetting
from wagtail.contrib.settings.models import register_setting

if WAGTAIL_VERSION >= (3, 0):
from wagtail import blocks
from wagtail.admin.panels import FieldPanel
from wagtail.fields import StreamField
else:
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.core import blocks
from wagtail.core.fields import StreamField


class ImageBlock(blocks.StructBlock):
image = ImageChooserBlock()
Expand Down Expand Up @@ -110,17 +98,9 @@ class EditorGuide(BaseSiteSetting, ClusterableModel):
information_text = models.TextField(
blank=True, help_text="Add a leading information paragraph explaining the guide"
)
sections = (
StreamField(GuideBlock(required=False), blank=True, use_json_field=True)
if WAGTAIL_VERSION >= (3, 0)
else StreamField(GuideBlock(required=False), blank=True)
)
sections = StreamField(GuideBlock(required=False), blank=True, use_json_field=True)

panels = (
[FieldPanel("information_text"), FieldPanel("sections")]
if WAGTAIL_VERSION >= (3, 0)
else [FieldPanel("information_text"), StreamFieldPanel("sections")]
)
panels = [FieldPanel("information_text"), FieldPanel("sections")]

class Meta:
verbose_name = "Manage Editor Guide"
24 changes: 24 additions & 0 deletions wagtail_guide/settings.py
@@ -0,0 +1,24 @@
from django.conf import settings


class WagtailGuideSettings:
def __init__(self, defaults=None):
self.defaults = {
"ADD_WAGTAIL_GUIDE_TO_HELP_MENU": False,
"WAGTAIL_GUIDE_MENU_LABEL": "Editor guide",
"HIDE_WAGTAIL_CORE_EDITOR_GUIDE": True,
}
if defaults is not None:
self.defaults.update(defaults)

def __getattr__(self, attr):
if attr not in self.defaults:
raise AttributeError(
f"'{self.__class__.__name__}' object has no attribute '{attr}'"
)

django_settings = getattr(settings, "WAGTAIL_GUIDE_SETTINGS", {})
return django_settings.get(attr, self.defaults[attr])


wagtail_guide_settings = WagtailGuideSettings()
13 changes: 10 additions & 3 deletions wagtail_guide/tests/settings.py
@@ -1,7 +1,5 @@
import os

from wagtail import VERSION as WAGTAIL_VERSION

PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(PROJECT_DIR)

Expand Down Expand Up @@ -30,7 +28,7 @@
"wagtail.documents",
"wagtail.images",
"wagtail.admin",
"wagtail" if WAGTAIL_VERSION >= (3, 0) else "wagtail.core",
"wagtail",
"taggit",
"django.contrib.admin",
"django.contrib.auth",
Expand Down Expand Up @@ -70,3 +68,12 @@
]
WAGTAIL_SITE_NAME = "llama-savers"
USE_TZ = True


WAGTAILADMIN_BASE_URL = "http://localhost:8000"

WAGTAIL_GUIDE_SETTINGS = {
"ADD_WAGTAIL_GUIDE_TO_HELP_MENU": False,
"WAGTAIL_GUIDE_MENU_LABEL": "WG guide menu label",
"HIDE_WAGTAIL_CORE_EDITOR_GUIDE": True,
}
16 changes: 3 additions & 13 deletions wagtail_guide/tests/tests.py
Expand Up @@ -2,15 +2,10 @@
from django.contrib.auth.models import Group
from django.test import TestCase
from django.urls import reverse
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.test.utils import WagtailTestUtils

from ..models import EditorGuide

if WAGTAIL_VERSION >= (3, 0):
from wagtail.test.utils import WagtailTestUtils
else:
from wagtail.tests.utils import WagtailTestUtils


class EditorGuideTest(TestCase, WagtailTestUtils):
def setUp(self):
Expand All @@ -26,12 +21,6 @@ def test_admin(self):
response = self.client.get(reverse("wagtailadmin_home"))
self.assertEqual(response.status_code, 200)

def test_guide_view_links(self):
response = self.client.get(reverse("wagtailadmin_home"))
self.assertIn(
'"name": "editor-guide", "label": "Editor guide"', response.content.decode()
)

def test_guide_edit_links(self):
response = self.client.get(reverse("wagtailadmin_home"))
self.assertIn(
Expand All @@ -48,7 +37,8 @@ def test_editor_view_null_message(self):
response = self.client.get(reverse("wagtaileditorguide"))
self.assertContains(
response,
'<p class="help-block help-warning">An editor guide has not been created yet. Add one in Settings > Manage Editor Guide</p>',
'<p class="help-block help-warning">An editor guide has not been\n'
"created yet. Add one in Settings > Manage Editor Guide</p>",
html=True,
)

Expand Down
8 changes: 1 addition & 7 deletions wagtail_guide/tests/urls.py
@@ -1,15 +1,9 @@
from django.contrib import admin
from django.urls import include, path
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail import urls as wagtail_urls
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls

if WAGTAIL_VERSION >= (3, 0):
from wagtail import urls as wagtail_urls
else:
from wagtail.core import urls as wagtail_urls


private_urlpatterns = [
path("django-admin/", admin.site.urls),
path("admin/", include(wagtailadmin_urls)),
Expand Down
7 changes: 1 addition & 6 deletions wagtail_guide/views.py
@@ -1,13 +1,8 @@
from django.shortcuts import render
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.models import Site

from .models import EditorGuide

if WAGTAIL_VERSION >= (3, 0):
from wagtail.models import Site
else:
from wagtail.core.models import Site


def index(request):
# There should only ever be one instance of the guide
Expand Down

0 comments on commit db81326

Please sign in to comment.