Merge branch 'janrito-fieldpanel-custom-widgets'

pull/777/head
Matt Westcott 2015-01-14 22:06:47 +00:00
commit d43b2057c5
4 zmienionych plików z 23 dodań i 5 usunięć

Wyświetl plik

@ -9,6 +9,7 @@ Changelog
* Added thousands separator for counters on dashboard
* Added contextual links to admin notification messages
* When copying pages, it is now possible to specify a place to copy to (Timo Rieber)
* FieldPanel now accepts an optional 'widget' parameter to override the field's default form widget (Alejandro Giacometti)
0.8.5 (xx.xx.20xx)

Wyświetl plik

@ -23,8 +23,10 @@ A "panel" is the basic editing block in Wagtail. Wagtail will automatically pick
There are four basic types of panels:
``FieldPanel( field_name, classname=None )``
This is the panel used for basic Django field types. ``field_name`` is the name of the class property used in your model definition. ``classname`` is a string of optional CSS classes given to the panel which are used in formatting and scripted interactivity. By default, panels are formatted as inset fields. The CSS class ``full`` can be used to format the panel so it covers the full width of the Wagtail page editor. The CSS class ``title`` can be used to mark a field as the source for auto-generated slug strings.
``FieldPanel( field_name, classname=None, widget=None )``
This is the panel used for basic Django field types. ``field_name`` is the name of the class property used in your model definition. ``classname`` is a string of optional CSS classes given to the panel which are used in formatting and scripted interactivity. By default, panels are formatted as inset fields. The CSS class ``full`` can be used to format the panel so it covers the full width of the Wagtail page editor. The CSS class ``title`` can be used to mark a field as the source for auto-generated slug strings. The optional ``widget`` parameter allows you to specify a `django form widget`_ to use instead of the default widget for this field type.
.. _django form widget: https://docs.djangoproject.com/en/dev/ref/forms/widgets/
``MultiFieldPanel( children, heading="", classname=None )``
This panel condenses several ``FieldPanel`` s or choosers, from a list or tuple, under a single ``heading`` string.

Wyświetl plik

@ -18,6 +18,7 @@ Minor features
* Added thousands separator for counters on dashboard
* Added contextual links to admin notification messages
* When copying pages, it is now possible to specify a place to copy to
* ``FieldPanel`` now accepts an optional ``widget`` parameter to override the field's default form widget
Bug fixes

Wyświetl plik

@ -351,6 +351,15 @@ def MultiFieldPanel(children, heading="", classname=""):
class BaseFieldPanel(EditHandler):
@classmethod
def widget_overrides(cls):
"""check if a specific widget has been defined for this field"""
if hasattr(cls, 'widget'):
return {cls.field_name: cls.widget}
else:
return {}
def __init__(self, instance=None, form=None):
super(BaseFieldPanel, self).__init__(instance=instance, form=form)
self.bound_field = self.form[self.field_name]
@ -397,11 +406,16 @@ class BaseFieldPanel(EditHandler):
return [self.field_name]
def FieldPanel(field_name, classname=""):
return type(str('_FieldPanel'), (BaseFieldPanel,), {
def FieldPanel(field_name, classname="", widget=None):
base = {
'field_name': field_name,
'classname': classname,
})
}
if widget:
base['widget'] = widget
return type(str('_FieldPanel'), (BaseFieldPanel,), base)
class BaseRichTextFieldPanel(BaseFieldPanel):