mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-19 06:20:59 +00:00
Merge branch 'takeflight-feature/register-snippet-decorator'
This commit is contained in:
commit
a4cf05f1bc
6 changed files with 30 additions and 8 deletions
|
|
@ -7,6 +7,7 @@ Changelog
|
|||
* Removed 'content_type' template filter from the project template, as the same thing can be accomplished with self.get_verbose_name|slugify
|
||||
* Page copy operations now also copy the page revision history
|
||||
* Page models now support a 'parent_page_types' property in addition to 'subpage types', to restrict the types of page they can be created under
|
||||
* 'register_snippet' can now be invoked as a decorator
|
||||
|
||||
0.6 (11.09.2014)
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
Snippets
|
||||
========
|
||||
|
||||
Snippets are pieces of content which do not necessitate a full webpage to render. They could be used for making secondary content, such as headers, footers, and sidebars, editable in the Wagtail admin. Snippets are models which do not inherit the ``Page`` class and are thus not organized into the Wagtail tree, but can still be made editable by assigning panels and identifying the model as a snippet with ``register_snippet()``.
|
||||
Snippets are pieces of content which do not necessitate a full webpage to render. They could be used for making secondary content, such as headers, footers, and sidebars, editable in the Wagtail admin. Snippets are models which do not inherit the ``Page`` class and are thus not organized into the Wagtail tree, but can still be made editable by assigning panels and identifying the model as a snippet with the ``register_snippet`` class decorator.
|
||||
|
||||
Snippets are not search-able or order-able in the Wagtail admin, so decide carefully if the content type you would want to build into a snippet might be more suited to a page.
|
||||
|
||||
|
|
@ -19,9 +19,10 @@ Here's an example snippet from the Wagtail demo website:
|
|||
|
||||
from wagtail.wagtailadmin.edit_handlers import FieldPanel
|
||||
from wagtail.wagtailsnippets.models import register_snippet
|
||||
|
||||
|
||||
...
|
||||
|
||||
@register_snippet
|
||||
class Advert(models.Model):
|
||||
url = models.URLField(null=True, blank=True)
|
||||
text = models.CharField(max_length=255)
|
||||
|
|
@ -34,11 +35,9 @@ Here's an example snippet from the Wagtail demo website:
|
|||
def __unicode__(self):
|
||||
return self.text
|
||||
|
||||
register_snippet(Advert)
|
||||
|
||||
The ``Advert`` model uses the basic Django model class and defines two properties: text and url. The editing interface is very close to that provided for ``Page``-derived models, with fields assigned in the panels property. Snippets do not use multiple tabs of fields, nor do they provide the "save as draft" or "submit for moderation" features.
|
||||
|
||||
``register_snippet(Advert)`` tells Wagtail to treat the model as a snippet. The ``panels`` list defines the fields to show on the snippet editing page. It's also important to provide a string representation of the class through ``def __unicode__(self):`` so that the snippet objects make sense when listed in the Wagtail admin.
|
||||
``@register_snippet`` tells Wagtail to treat the model as a snippet. The ``panels`` list defines the fields to show on the snippet editing page. It's also important to provide a string representation of the class through ``def __unicode__(self):`` so that the snippet objects make sense when listed in the Wagtail admin.
|
||||
|
||||
Including Snippets in Template Tags
|
||||
-----------------------------------
|
||||
|
|
|
|||
|
|
@ -63,9 +63,10 @@ You will now be able to run the following command to set up an initial file stru
|
|||
**Without Vagrant:** Run the following steps to complete setup of your project (the ``migrate`` step will prompt you to set up a superuser account)::
|
||||
|
||||
cd myprojectname
|
||||
./manage.py syncdb
|
||||
./manage.py migrate
|
||||
./manage.py runserver
|
||||
pip install -r requirements.txt
|
||||
python manage.py syncdb
|
||||
python manage.py migrate
|
||||
python manage.py runserver
|
||||
|
||||
Your site is now accessible at http://localhost:8000, with the admin backend available at http://localhost:8000/admin/ .
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ Minor features
|
|||
* The ``content_type`` template filter has been removed from the project template, as the same thing can be accomplished with ``self.get_verbose_name|slugify``.
|
||||
* Page copy operations now also copy the page revision history.
|
||||
* Page models now support a ``parent_page_types`` property in addition to ``subpage types``, to restrict the types of page they can be created under.
|
||||
* ``register_snippet`` can now be invoked as a decorator.
|
||||
|
||||
Bug fixes
|
||||
~~~~~~~~~
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ def register_snippet(model):
|
|||
model.usage_url = get_snippet_usage_url
|
||||
SNIPPET_MODELS.append(model)
|
||||
SNIPPET_MODELS.sort(key=lambda x: x._meta.verbose_name)
|
||||
return model
|
||||
|
||||
|
||||
def get_snippet_usage_url(self):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from django.test import TestCase
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import models
|
||||
|
||||
from wagtail.tests.utils import WagtailTestUtils
|
||||
from django.test.utils import override_settings
|
||||
|
|
@ -176,6 +177,24 @@ class TestSnippetChooserPanel(TestCase):
|
|||
in self.snippet_chooser_panel.render_js())
|
||||
|
||||
|
||||
class TestSnippetRegistering(TestCase):
|
||||
def test_register_function(self):
|
||||
class RegisterFunction(models.Model):
|
||||
pass
|
||||
register_snippet(RegisterFunction)
|
||||
|
||||
self.assertIn(RegisterFunction, SNIPPET_MODELS)
|
||||
|
||||
def test_register_function(self):
|
||||
@register_snippet
|
||||
class RegisterDecorator(models.Model):
|
||||
pass
|
||||
|
||||
# Misbehaving decorators often return None
|
||||
self.assertIsNotNone(RegisterDecorator)
|
||||
self.assertIn(RegisterDecorator, SNIPPET_MODELS)
|
||||
|
||||
|
||||
class TestSnippetOrdering(TestCase):
|
||||
def setUp(self):
|
||||
register_snippet(ZuluSnippet)
|
||||
|
|
|
|||
Loading…
Reference in a new issue