From 3f2f5665b0f7763476fea743ce05a17e58eb48ad Mon Sep 17 00:00:00 2001 From: Mikalai Radchuk Date: Mon, 25 Jan 2016 17:47:59 +0300 Subject: [PATCH] Allow specifying custom edit handlers for snippets --- CHANGELOG.txt | 1 + CONTRIBUTORS.rst | 1 + .../customisation/page_editing_interface.rst | 6 ++-- docs/releases/1.4.rst | 1 + wagtail/tests/testapp/fixtures/test.json | 9 ++++++ .../0024_advertwithtabbedinterface.py | 23 +++++++++++++++ .../tests/testapp/migrations/0025_merge.py | 16 ++++++++++ wagtail/tests/testapp/models.py | 27 +++++++++++++++++ .../wagtailsnippets/snippets/create.html | 2 +- .../wagtailsnippets/snippets/edit.html | 2 +- wagtail/wagtailsnippets/tests.py | 29 ++++++++++++++++++- wagtail/wagtailsnippets/views/snippets.py | 10 +++++-- 12 files changed, 118 insertions(+), 9 deletions(-) create mode 100644 wagtail/tests/testapp/migrations/0024_advertwithtabbedinterface.py create mode 100644 wagtail/tests/testapp/migrations/0025_merge.py diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 8442f03d9c..d2e0e2b207 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -5,6 +5,7 @@ Changelog ~~~~~~~~~~~~~~~~ * The `Document` model can now be overridden using the new `WAGTAILDOCS_DOCUMENT_MODEL` setting (Alex Gleason) + * Snippets now support a custom `edit_handler` property (Mikalai Radchuk) * Date/time pickers now respect the locale's 'first day of week' setting (Peter Quade) * Refactored the way forms are constructed for the page editor, to allow custom forms to be used * Notification message on publish now indicates whether the page is being published now or scheduled for publication in future (Chris Rogers) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 660d3afaae..81300832c0 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -102,6 +102,7 @@ Contributors * Matt Fozard * Chris Rogers * Josh Schneier +* Mikalai Radchuk Translators diff --git a/docs/advanced_topics/customisation/page_editing_interface.rst b/docs/advanced_topics/customisation/page_editing_interface.rst index 17e22a7b96..99f31f00d0 100644 --- a/docs/advanced_topics/customisation/page_editing_interface.rst +++ b/docs/advanced_topics/customisation/page_editing_interface.rst @@ -1,5 +1,5 @@ -Customising the page editing interface -====================================== +Customising the editing interface +================================= .. _customising_the_tabbed_interface: @@ -8,7 +8,7 @@ Customising the tabbed interface .. versionadded:: 1.0 -As standard, Wagtail organises panels into three tabs: 'Content', 'Promote' and 'Settings'. Depending on the requirements of your site, you may wish to customise this for specific page types - for example, adding an additional tab for sidebar content. This can be done by specifying an ``edit_handler`` property on the page model. For example: +As standard, Wagtail organises panels for pages into three tabs: 'Content', 'Promote' and 'Settings'. For snippets Wagtail puts all panels into one page. Depending on the requirements of your site, you may wish to customise this for specific page types or snippets - for example, adding an additional tab for sidebar content. This can be done by specifying an ``edit_handler`` attribute on the page or snippet model. For example: .. code-block:: python diff --git a/docs/releases/1.4.rst b/docs/releases/1.4.rst index 0e18cdc966..49d659b549 100644 --- a/docs/releases/1.4.rst +++ b/docs/releases/1.4.rst @@ -19,6 +19,7 @@ The `Document` model can now be overridden using the new `WAGTAILDOCS_DOCUMENT_M Minor features ~~~~~~~~~~~~~~ + * Snippets now support a custom ``edit_handler`` property; this can be used to implement a tabbed interface, for example. See :ref:`customising_the_tabbed_interface` (Mikalai Radchuk) * Date/time pickers now respect the locale's 'first day of week' setting (Peter Quade) * Refactored the way forms are constructed for the page editor, to allow custom forms to be used * Notification message on publish now indicates whether the page is being published now or scheduled for publication in future (Chris Rogers) diff --git a/wagtail/tests/testapp/fixtures/test.json b/wagtail/tests/testapp/fixtures/test.json index 240439d2df..309036b893 100644 --- a/wagtail/tests/testapp/fixtures/test.json +++ b/wagtail/tests/testapp/fixtures/test.json @@ -706,6 +706,15 @@ "url": "http://www.example.com" } }, +{ + "pk": 1, + "model": "tests.advertwithtabbedinterface", + "fields": { + "text": "test_advert", + "url": "http://www.example.com", + "something_else": "Model with tabbed interface" + } +}, { "pk": 1, "model": "wagtaildocs.Document", diff --git a/wagtail/tests/testapp/migrations/0024_advertwithtabbedinterface.py b/wagtail/tests/testapp/migrations/0024_advertwithtabbedinterface.py new file mode 100644 index 0000000000..86516d6834 --- /dev/null +++ b/wagtail/tests/testapp/migrations/0024_advertwithtabbedinterface.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('tests', '0023_mycustompage'), + ] + + operations = [ + migrations.CreateModel( + name='AdvertWithTabbedInterface', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('url', models.URLField(null=True, blank=True)), + ('text', models.CharField(max_length=255)), + ('something_else', models.CharField(max_length=255)), + ], + ), + ] diff --git a/wagtail/tests/testapp/migrations/0025_merge.py b/wagtail/tests/testapp/migrations/0025_merge.py new file mode 100644 index 0000000000..47f691b250 --- /dev/null +++ b/wagtail/tests/testapp/migrations/0025_merge.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.1 on 2016-01-28 12:53 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('tests', '0024_validatedpage'), + ('tests', '0024_advertwithtabbedinterface'), + ] + + operations = [ + ] diff --git a/wagtail/tests/testapp/models.py b/wagtail/tests/testapp/models.py index fe0263e28b..789944f058 100644 --- a/wagtail/tests/testapp/models.py +++ b/wagtail/tests/testapp/models.py @@ -371,6 +371,33 @@ class Advert(ClusterableModel): register_snippet(Advert) +@python_2_unicode_compatible +class AdvertWithTabbedInterface(models.Model): + url = models.URLField(null=True, blank=True) + text = models.CharField(max_length=255) + something_else = models.CharField(max_length=255) + + advert_panels = [ + FieldPanel('url'), + FieldPanel('text'), + ] + + other_panels = [ + FieldPanel('something_else'), + ] + + edit_handler = TabbedInterface([ + ObjectList(advert_panels, heading='Advert'), + ObjectList(other_panels, heading='Other'), + ]) + + def __str__(self): + return self.text + + +register_snippet(AdvertWithTabbedInterface) + + class StandardIndex(Page): """ Index for the site """ parent_page_types = [Page] diff --git a/wagtail/wagtailsnippets/templates/wagtailsnippets/snippets/create.html b/wagtail/wagtailsnippets/templates/wagtailsnippets/snippets/create.html index 457815904b..1c22a3b07f 100644 --- a/wagtail/wagtailsnippets/templates/wagtailsnippets/snippets/create.html +++ b/wagtail/wagtailsnippets/templates/wagtailsnippets/snippets/create.html @@ -3,7 +3,7 @@ {% block titletag %}{% blocktrans with snippet_type_name=model_opts.verbose_name %}New {{ snippet_type_name }}{% endblocktrans %}{% endblock %} {% block content %} {% trans "New" as new_str %} - {% include "wagtailadmin/shared/header.html" with title=new_str subtitle=model_opts.verbose_name icon="snippet" %} + {% include "wagtailadmin/shared/header.html" with title=new_str subtitle=model_opts.verbose_name icon="snippet" tabbed=1 merged=1 %}
{% csrf_token %} diff --git a/wagtail/wagtailsnippets/templates/wagtailsnippets/snippets/edit.html b/wagtail/wagtailsnippets/templates/wagtailsnippets/snippets/edit.html index 74a868795c..63b1a2a21d 100644 --- a/wagtail/wagtailsnippets/templates/wagtailsnippets/snippets/edit.html +++ b/wagtail/wagtailsnippets/templates/wagtailsnippets/snippets/edit.html @@ -3,7 +3,7 @@ {% block titletag %}{% blocktrans with snippet_type_name=model_opts.verbose_name %}Editing {{ snippet_type_name }} - {{ instance }}{% endblocktrans %}{% endblock %} {% block content %} {% trans "Editing" as editing_str %} - {% include "wagtailadmin/shared/header.html" with title=editing_str subtitle=instance icon="snippet" usage_object=instance %} + {% include "wagtailadmin/shared/header.html" with title=editing_str subtitle=instance icon="snippet" usage_object=instance tabbed=1 merged=1 %} {% csrf_token %} diff --git a/wagtail/wagtailsnippets/tests.py b/wagtail/wagtailsnippets/tests.py index e52d533bab..677d92683f 100644 --- a/wagtail/wagtailsnippets/tests.py +++ b/wagtail/wagtailsnippets/tests.py @@ -8,7 +8,7 @@ from django.core.exceptions import ImproperlyConfigured from taggit.models import Tag from wagtail.tests.utils import WagtailTestUtils -from wagtail.tests.testapp.models import Advert, SnippetChooserModel +from wagtail.tests.testapp.models import Advert, SnippetChooserModel, AdvertWithTabbedInterface from wagtail.tests.snippets.models import ( AlphaSnippet, ZuluSnippet, RegisterDecorator, RegisterFunction, SearchableSnippet ) @@ -131,6 +131,19 @@ class TestSnippetCreateView(TestCase, WagtailTestUtils): response = self.get() self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'wagtailsnippets/snippets/create.html') + self.assertNotContains(response, '