first bash at customisable tabs like in PR #210

pull/326/head
Dave Cranwell 2014-06-17 15:09:10 +01:00
rodzic 7f72bdd917
commit 4788144c86
3 zmienionych plików z 40 dodań i 7 usunięć

Wyświetl plik

@ -447,10 +447,11 @@ class BaseObjectList(BaseCompositeEditHandler):
template = "wagtailadmin/edit_handlers/object_list.html"
def ObjectList(children, heading=""):
def ObjectList(children, heading="", classes=None):
return type('_ObjectList', (BaseObjectList,), {
'children': children,
'heading': heading,
'classes': classes
})

Wyświetl plik

@ -1,12 +1,12 @@
<ul class="tab-nav merged">
{% for child in self.children %}
<li class="{% if forloop.first %}active{% endif %}"><a href="#{{ child.heading|slugify }}" class="{% if forloop.first %}active{% endif %}">{{ child.heading }}</a></li>
<li class="{{ child.classes }} {% if forloop.first %}active{% endif %}"><a href="#{{ child.heading|slugify }}" class="{% if forloop.first %}active{% endif %}">{{ child.heading }}</a></li>
{% endfor %}
</ul>
<div class="tab-content">
{% for child in self.children %}
<section id="{{ child.heading|slugify }}" class="{% if forloop.first %}active{% endif %}">
<section id="{{ child.heading|slugify }}" class="{{ child.classes }} {% if forloop.first %}active{% endif %}">
{{ child.render_as_object }}
</section>
{% endfor %}

Wyświetl plik

@ -155,6 +155,9 @@ def create(request, content_type_app_name, content_type_model_name, parent_page_
page.save_revision(user=request.user, submitted_for_moderation=is_submitting)
if is_publishing:
message = mark_safe(render_to_string(self.template, {
'self': self
}))
messages.success(request, _("Page '{0}' published.").format(page.title))
elif is_submitting:
messages.success(request, _("Page '{0}' submitted for moderation.").format(page.title))
@ -527,12 +530,41 @@ def set_page_position(request, page_to_move_id):
PAGE_EDIT_HANDLERS = {}
def get_default_panels(page_class):
panels = []
try:
panels.append(ObjectList(page_class.content_panels, heading='Content'))
except AttributeError:
pass
try:
panels.append(ObjectList(page_class.promote_panels, heading='Promote'))
except AttributeError:
pass
try:
panels.append(ObjectList(page_class.settings_panels, heading='Settings', classes='settings'))
except AttributeError:
pass
return panels
def get_panels(page_class):
try:
return page_class.panels
except AttributeError:
return get_default_panels(page_class)
def set_panels(page_class, panels):
page_class.panels = panels
def get_page_edit_handler(page_class):
if page_class not in PAGE_EDIT_HANDLERS:
PAGE_EDIT_HANDLERS[page_class] = TabbedInterface([
ObjectList(page_class.content_panels, heading='Content'),
ObjectList(page_class.promote_panels, heading='Promote')
])
PAGE_EDIT_HANDLERS[page_class] = TabbedInterface(get_panels(page_class))
return PAGE_EDIT_HANDLERS[page_class]