ToolbarMiddleware.process_response: conditional refactor

Changed loop into a 'not all()' call and replaced "found" bool with combined clauses
cms.plugin_pool: use sorted, attrgetter and set()

PluginPool.get_all_plugins(): sorted and attrgetter
The force_unicode in the lambdas shouldn't be necessary. If strings are all the
same type, unicode or not, the sorting should be equivalent. If the strings had
mixed types the sorting comparison should coerce the byte strings to unicode.

PluginPool.get_text_enabled_plugins(): set()
Use set() to collect unique plugins; Django ORM objects are hashed on primary
key. Sort result to retain order of get_all_plugins().
cms.utils.urlutils refactors

levelize_path(): list comp
prepend slash explicitly, not relying on join of empty string
splitting all slashes and filtering empty strings also converts paths with
consecutive slashes

urljoin():
The conditionals became simpler because '/'.join(stripped) never could have
started or ended with a slash
cms.utils.i18n: builtins refactors

get_language_list, get_language_tuple, and get_public_languages: list comps
get_language_dict: dict(get_language_tuple)
is_language_prefix_patterns_used: any()
ToolbarPool.get_watch_models: sum() refactor
cms.utils.django_load: iterator and sum() refactors

import iterative map and filter

iterload(): filter()
iterload_objects(): map()
get_subclasses(): recursive sum(..., [])

Added DjangoLoadTestCase to cover iterload() and verify signatures
menus.*: comprehensions, infix if/else, shortcut or

MenuPool.get_menus_by_attribute():
The value parameter shouldn't be None so the hasattr() call was dropped.
cms.models.pluginmodel: builtin refactors

CMSPlugin:
.__reduce__(): list comp
.get_translatable_content(): now filters using generators/filter
Simplified predicate collecting the fields (one isinstance, removed "and f")
.set_translatable_content(): all()

various infix ix/else and shortcut 'or' replacements
cms.utils.plugins: builtins and std library refactors

import iterative filter/filterfalse

requires_reload(): any()
downcast_plugins(): list comp

assign_plugins():
Moved invariant toolbar conditionals to top level. Pulled plugin placeholder_id
check loop into an all() inside a new disjoint_placeholders filter. The
build_plugin_tree query near the end was simplified since it can now accept an
iterable.

create_default_plugins():
    _create_default_plugins():
New recursive auxillary function that provides the core logic common to both
previous create_default_plugins functions. Nesting the function allows
parameter simplification since request and lang stay constant. The add_plugin()
call now provides parent plugins as the target keyword, simplifying the logic
and halving the save() method calls.
The continue statements inside the core placeholders loop were transformed into
declarative filters/generator expressions feeding the core placeholders
iteration.

create_default_children_plugins():
merged into create_default_plugins as a nested auxillary function

build_plugin_tree():
Reworked to do a groupby query and documentation added. Now also accepts an
iterable. Python3 requires partitioning roots and nonroots to sort on the
parent_id attribute. Sorting the nonroots allows grouping and guarantees the
children tuples are sorted.
cms.utils.copy_plugins.copy_plugins_to(): reworked, new code reuse

Now returns the list of new plugins, rather than new and old plugins zipped.
Behavior was retained, since the return value was only used once, in a len().
If the recipient wants the previous result, they can rezip the result and the
submitted parameter. This allowed the reuse of copy_plugins_to() and
encapsulated the mutating old_parent_cache parameter.

cms.utils.placeholder.MLNGPlaceholderActions.copy():
now reuses copy_plugins_to()
Fix merge
Merge branch 'bradmwalker-develop' into develop
Remove uneeded import
Merge pull request #3669 from yakky/merge/3534

Merge #3534
Added toolbar sanity check to ensure there is valid request.user before building the toolbar

Refs #3659
Fixed plugin ordering for live plugins.

Refs #3637

When publishing a page, the draft plugins are copied to new 'live' versions of themselves. The code was incorrectly overwriting the position of the plugins. This change means the position remains identical to the position of the draft plugin, which is the only correct value.