merged master, fixing conflict in core.js

This commit is contained in:
Dave Cranwell 2014-07-18 17:18:20 +01:00
commit f8dc380952
13 changed files with 102 additions and 47 deletions

View file

@ -3,6 +3,7 @@ Changelog
0.5 (xx.xx.20xx)
~~~~~~~~~~~~~~~~
* Explorer nav now rendered separately and fetched with AJAX when needed
* Added decorator syntax for hooks
* Replaced lxml dependency with html5lib, to simplify installation

View file

@ -30,6 +30,14 @@ Core
* The lxml library (used for whitelisting and rewriting of rich text fields) has been replaced with the pure-python html5lib library, to simplify installation.
Admin
-----
* Explorer nav now rendered separately and fetched with AJAX when needed.
This improves the general performance of the admin interface for large sites.
Bug fixes
~~~~~~~~~

View file

@ -12,7 +12,7 @@ $(function(){
$('body').addClass('ready');
// Enable toggle to open/close nav
$('#nav-toggle').click(function(){
$(document).on('click', '#nav-toggle', function(){
$('body').toggleClass('nav-open');
if(!$('body').hasClass('nav-open')){
$('body').addClass('nav-closed');
@ -21,12 +21,30 @@ $(function(){
}
});
// Enable swishy section navigation menu
$('.explorer').addClass('dl-menuwrapper').dlmenu({
animationClasses : {
classin : 'dl-animate-in-2',
classout : 'dl-animate-out-2'
// Dynamically load menu on request.
$(document).on('click', '.dl-trigger', function(){
var $this = $(this);
var $explorer = $('#explorer');
$this.addClass('icon-spinner');
if(!$explorer.children().length){
$explorer.load(window.explorer_menu_url, function() {
$this.removeClass('icon-spinner');
$explorer.addClass('dl-menuwrapper').dlmenu({
animationClasses : {
classin : 'dl-animate-in-2',
classout : 'dl-animate-out-2'
}
});
$explorer.dlmenu('openMenu');
});
}else{
$explorer.dlmenu('openMenu');
}
return false;
});
// Resize nav to fit height of window. This is an unimportant bell/whistle to make it look nice
@ -35,9 +53,6 @@ $(function(){
$('.nav-main').each(function(){
var thisHeight = $(this).height();
var footerHeight = $('.footer', $(this)).height();
// $(this).css({'height':thisHeight - footerHeight, 'overflow-y':'scroll'});
// $('> ul', $(this)).height(thisHeight)
});
};
fitNav();
@ -86,22 +101,6 @@ $(function(){
}
});
/* Bulk-selection */
$(document).on('click', 'thead .bulk', function(){
$(this).closest('table').find('tbody .bulk input').each(function(){
$(this).prop('checked', !$(this).prop('checked'));
});
});
$('#menu-search input').bind('focus', function(){
$('#menu-search').addClass('focussed');
}).bind('blur', function(){
$('#menu-search').removeClass('focussed');
});
$('#menu-search').bind('focus click', function(){
$(this).addClass('focussed');
});
/* Dropzones */
$('.drop-zone').on('dragover', function(){
$(this).addClass('hovered');

View file

@ -104,7 +104,6 @@ body{
}
.nav-main{
top: 43px;
bottom: 0px;
overflow: auto;
@ -167,6 +166,15 @@ body{
&:hover{
color:white;
}
/* only really used for spinners */
&:after{
font-size:1.5em;
margin:0;
position:absolute;
right:0.5em;
margin-top:0.15em;
}
}
.avatar{

View file

@ -22,6 +22,9 @@
<script src="{{ STATIC_URL }}wagtailadmin/js/vendor/bootstrap-tab.js"></script>
<script src="{{ STATIC_URL }}wagtailadmin/js/vendor/jquery.dlmenu.js"></script>
<script src="{{ STATIC_URL }}wagtailadmin/js/core.js"></script>
<script>
window.explorer_menu_url = "{% url 'wagtailadmin_explorer_nav' %}";
</script>
{% endcompress %}
{% block extra_js %}{% endblock %}

View file

@ -8,11 +8,7 @@
{% main_nav %}
</div>
<nav class="explorer">
<ul class="dl-menu">
{% explorer_nav %}
</ul>
</nav>
<nav id="explorer" class="explorer"></nav>
</div>
<div class="content-wrapper">

View file

@ -1,13 +1,5 @@
{% load wagtailadmin_tags %}
{% for page, children in nodes %}
<li {% if children %}class="has-children"{% endif %}>
<a href="{% url 'wagtailadmin_explore' page.id %}" class="icon icon-folder-open-inverse">{{ page.title }}</a>
{% if children %}
<div class="children icon icon-arrow-right"></div>
<ul class="dl-submenu">
{% explorer_subnav children %}
</ul>
{% endif %}
</li>
{% endfor %}
<ul class="dl-menu">
{% include "wagtailadmin/shared/explorer_nav_child.html" %}
</ul>

View file

@ -0,0 +1,13 @@
{% load wagtailadmin_tags %}
{% for page, children in nodes %}
<li {% if children %}class="has-children"{% endif %}>
<a href="{% url 'wagtailadmin_explore' page.id %}" class="icon icon-folder-open-inverse">{{ page.title }}</a>
{% if children %}
<div class="children icon icon-arrow-right"></div>
<ul class="dl-submenu">
{% explorer_subnav children %}
</ul>
{% endif %}
</li>
{% endfor %}

View file

@ -21,7 +21,7 @@ def explorer_nav():
}
@register.inclusion_tag('wagtailadmin/shared/explorer_nav.html')
@register.inclusion_tag('wagtailadmin/shared/explorer_nav_child.html')
def explorer_subnav(nodes):
return {
'nodes': nodes
@ -31,7 +31,7 @@ def explorer_subnav(nodes):
@register.inclusion_tag('wagtailadmin/shared/main_nav.html', takes_context=True)
def main_nav(context):
menu_items = [
MenuItem(_('Explorer'), '#', classnames='icon icon-folder-open-inverse dl-trigger', order=100),
MenuItem(_('Explorer'), urlresolvers.reverse('wagtailadmin_explore_root'), classnames='icon icon-folder-open-inverse dl-trigger', order=100),
MenuItem(_('Search'), urlresolvers.reverse('wagtailadmin_pages_search'), classnames='icon icon-search', order=200),
]

View file

@ -43,3 +43,17 @@ class TestSendEmailTask(TestCase):
self.assertEqual(mail.outbox[0].subject, "Test subject")
self.assertEqual(mail.outbox[0].body, "Test content")
self.assertEqual(mail.outbox[0].to, ["nobody@email.com"])
class TestExplorerNavView(TestCase, WagtailTestUtils):
def setUp(self):
self.homepage = Page.objects.get(id=2).specific
self.login()
def test_explorer_nav_view(self):
response = self.client.get(reverse('wagtailadmin_explorer_nav'))
# Check response
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed('wagtailadmin/shared/explorer_nav.html')
self.assertEqual(response.context['nodes'][0][0], self.homepage)

View file

@ -38,6 +38,8 @@ urlpatterns += [
url(r'^failwhale/$', home.error_test, name='wagtailadmin_error_test'),
url(r'^explorer-nav/$', pages.explorer_nav, name='wagtailadmin_explorer_nav'),
url(r'^pages/$', pages.index, name='wagtailadmin_explore_root'),
url(r'^pages/(\d+)/$', pages.index, name='wagtailadmin_explore'),

View file

@ -17,10 +17,17 @@ from wagtail.wagtailadmin.forms import SearchForm
from wagtail.wagtailadmin import tasks, signals
from wagtail.wagtailcore import hooks
from wagtail.wagtailcore.models import Page, PageRevision
from wagtail.wagtailcore.models import Page, PageRevision, get_navigation_menu_items
from wagtail.wagtailcore.signals import page_published
@permission_required('wagtailadmin.access_admin')
def explorer_nav(request):
return render(request, 'wagtailadmin/shared/explorer_nav.html', {
'nodes': get_navigation_menu_items(),
})
@permission_required('wagtailadmin.access_admin')
def index(request, parent_page_id=None):
if parent_page_id:

View file

@ -157,9 +157,21 @@ LINK_HANDLERS = {
}
# Prepare a whitelisting engine with custom behaviour:
# rewrite any elements with a data-embedtype or data-linktype attribute
class DbWhitelister(Whitelister):
"""
A custom whitelisting engine to convert the HTML as returned by the rich text editor
into the pseudo-HTML format stored in the database (in which images, documents and other
linked objects are identified by ID rather than URL):
* implements a 'construct_whitelister_element_rules' hook so that other apps can modify
the whitelist ruleset (e.g. to permit additional HTML elements beyond those in the base
Whitelister module);
* replaces any element with a 'data-embedtype' attribute with an <embed> element, with
attributes supplied by the handler for that type as defined in EMBED_HANDLERS;
* rewrites the attributes of any <a> element with a 'data-linktype' attribute, as
determined by the handler for that type defined in LINK_HANDLERS, while keeping the
element content intact.
"""
has_loaded_custom_whitelist_rules = False
@classmethod