Don't monkey patch get_templates_hierarchy at top level

Debug toolbar loads all the panel modules regardless of settings.DEBUG.
If we monkey patch at the module level, we'll always replace
get_templates_hierarchy, even in production mode.
Memoize select_template, and a render_to_string that uses it

Until Django bug #20806 is fixed, we should memoize select_template
because we call it many times with long lists of templates to choose
from. This results in a large speedup while rendering the editors for
large trees.