Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/settings panel append #441

Merged
merged 5 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This is a [Jazzband](https://jazzband.co/) project. By contributing you agree to
* Rebecca Claire Murphy (rcmurphy)
* Gabriel Augendre (Crocmagnon)
* Bojan Mihelac (bmihelac)
* Ben Froelich-Leon (benfroelich)

## Translators

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ For everything you need to get up and running with wagtailmenus, `view the offic
Contributing
============

Instructions on how to contribute to can be house `here <https://wagtailmenus.readthedocs.io/en/stable/contributing/index.html>`_.
Instructions on how to contribute can be found `here <https://wagtailmenus.readthedocs.io/en/stable/contributing/index.html>`_.

As we are members of a `JazzBand project <https://jazzband.co/projects>`_, `wagtailmenus` contributors should adhere to the `Contributor Code of Conduct <https://jazzband.co/about/conduct>`_.
6 changes: 3 additions & 3 deletions docs/source/contributing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ If you'd like a runnable Django project to help with development of wagtailmenus

.. code-block:: console

cp wagtailmenus/settings/development.py.example wagtailmenus/settings/development.py
cp wagtailmenus/settings/development.py{.example,}

3. Create a copy of the development urls:

.. code-block:: console

cp wagtailmenus/development/urls.py.example wagtailmenus/development/urls.py
cp wagtailmenus/development/urls.py{.example,}

4. Create ``manage.py`` by copying the example provided:

.. code-block:: console

cp manage.py.example manage.py
cp manage.py{.example,}

5. Run the migrate command to set up the database tables:

Expand Down
36 changes: 25 additions & 11 deletions docs/source/menupage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,15 @@ Implementing ``MenuPage`` into your project
custom_settings_field_one = BooleanField(default=False)
custom_settings_field_two = BooleanField(default=True)

# 'menupage_panel' is a collapsible `MultiFieldPanel` with the important
# fields already grouped together, making it easy to include in custom
# panel definitions, like so:
# `menupage_settings_panels` is a collapsible `MultiFieldPanel` with the important
# fields already grouped together in addition to wagtail settings fields, making
# it easy to include in custom panel definitions as shown. If you want to exclude
# wagtail settings, instead use `[menupage_panel]`
settings_panels = [
FieldPanel('custom_settings_field_one'),
FieldPanel('custom_settings_field_two'),
menupage_panel
]
] + menupage_settings_panels

...

3. Create migrations for any models you've updated by running:
Expand All @@ -149,7 +150,7 @@ Implementing ``MenuPageMixin`` into your project
Wagtail has a restriction that forbids models from subclassing more than one other class derived from ``Page``, and that single page-derived class must be the left-most item when subclassing more than one model class. Most of the time, that doesn't cause any noticeable issues. But, in some cases, it can make it difficult to swap out base model classes used for page models. In these cases, you can use ``wagtailmenus.models.MenuPageMixin`` instead of ``MenuPage``.

.. NOTE::
``MenuPageMixin`` doesn't change make any changes to the panel configuration on your model that would cause it's new fields to be surfaced in the page editing interface. If you want those fields to appear, you'll have to override ``settings_panels`` on your model to include ``menupage_panel``
``MenuPageMixin`` doesn't change make any changes to the panel configuration on your model that would cause it's new fields to be surfaced in the page editing interface. If you want those fields to appear, you'll have to override ``settings_panels`` on your model to include ``menupage_panel``. If you want to retain wagtails settings fields for features like comments, privacy, and scheduled publishing, add ``menupage_settings_panels``.


1. Subclass ``wagtailmenus.models.MenuPageMixin`` to create your model, including it to the right of any other class that subclasses ``Page``:
Expand All @@ -160,8 +161,10 @@ Wagtail has a restriction that forbids models from subclassing more than one oth

from wagtail.contrib.forms.models import AbstractEmailForm
from wagtailmenus.models import MenuPageMixin
# option 1 (described below)
from wagtailmenus.panels import menupage_panel

# option 2 (described below)
from wagtailmenus.panels import menupage_settings_panels

class MyEmailFormPage(AbstractEmailForm, MenuPageMixin):
"""This page will gain the same fields and methods as if it extended
Expand All @@ -170,10 +173,21 @@ Wagtail has a restriction that forbids models from subclassing more than one oth
...

# It's not possible for MenuPageMixin to set `settings_panel`, so you must
# override `settings_panels` yourself, and include `menupage_panel` in
# order to surface additional fields in the 'Settings' tab of the editor
# interface
settings_panels = [
# override `settings_panels` yourself, and include `menupage_panel` or
# `menupage_settings_panels` in order to surface additional fields in
# the 'Settings' tab of the editor interface
# If you wish to retain the wagtail `settings_panel` features like privacy,
# comments, etc, you must include Page.settings_panels

# option 1
# this version simply retains wagtail and wagtailmenus settings
# this is what the MenuPage class uses by default
settings_panels = menupage_settings_panels

# option 2
# this version drops wagail settings and adds custom ones in
# addition to wagtailmenus fields
settings_panels = [
FieldPanel('custom_settings_field_one'),
FieldPanel('custom_settings_field_two'),
menupage_panel
Expand Down
21 changes: 3 additions & 18 deletions wagtailmenus/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
PageChooserPanel, TabbedInterface)

from wagtailmenus.conf import settings
from wagtail.models import Page

# ########################################################
# For menu models
Expand Down Expand Up @@ -90,7 +91,7 @@ def get_default_relation_name(cls):


# ########################################################
# For MenuPageMixin
# For MenuPageMixin and MenuPage
# ########################################################

menupage_panel = MultiFieldPanel(
Expand All @@ -102,20 +103,4 @@ def get_default_relation_name(cls):
)
)

menupage_settings_panels = [
MultiFieldPanel(
heading=_("Scheduled publishing"),
classname="publishing",
children=(
FieldRowPanel((
FieldPanel('go_live_at', classname="col6"),
FieldPanel('expire_at', classname="col6"),
)),
)
),
menupage_panel,
]

menupage_settings_tab = ObjectList(
menupage_settings_panels, heading=_("Settings"), classname="settings"
)
menupage_settings_panels = Page.settings_panels + [menupage_panel]