Skip to content

Commit

Permalink
[#2818] remove package controller c.form compat hack
Browse files Browse the repository at this point in the history
  • Loading branch information
wardi committed Dec 31, 2015
1 parent 60061b0 commit 5786994
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 58 deletions.
16 changes: 0 additions & 16 deletions ckan/controllers/package.py
Expand Up @@ -533,14 +533,6 @@ def new(self, data=None, errors=None, error_summary=None):
package_type=package_type)

new_template = self._new_template(package_type)
c.form = ckan.lib.render.deprecated_lazy_render(
new_template,
form_snippet,
lambda: render(form_snippet, extra_vars=form_vars),
'use of c.form is deprecated. please see '
'ckan/templates/package/base_form_page.html for an example '
'of the new way to include the form snippet'
)
return render(new_template,
extra_vars={'form_vars': form_vars,
'form_snippet': form_snippet,
Expand Down Expand Up @@ -799,14 +791,6 @@ def edit(self, id, data=None, errors=None, error_summary=None):
form_vars['stage'] = ['active', 'complete']

edit_template = self._edit_template(package_type)
c.form = ckan.lib.render.deprecated_lazy_render(
edit_template,
form_snippet,
lambda: render(form_snippet, extra_vars=form_vars),
'use of c.form is deprecated. please see '
'ckan/templates/package/edit.html for an example '
'of the new way to include the form snippet'
)
return render(edit_template,
extra_vars={'form_vars': form_vars,
'form_snippet': form_snippet,
Expand Down
42 changes: 0 additions & 42 deletions ckan/lib/render.py
Expand Up @@ -61,45 +61,3 @@ def template_info(template_name):
'template_type' : t_type,}
_template_info_cache[template_name] = t_data
return template_path, t_type


def deprecated_lazy_render(target_template, snippet_template, render,
message):
'''
If either target_template is a genshi template this function renders
immediately and returns a string, otherwise an object that will lazily
render when {{ the_object | safe }} is used in the jinja template
is returned.
:param target_template: name of jinja or genshi template
that may include the object returned
:param snippet_template: name of jinja or genshi template
that will be rendered
:param render: function to call to render the template snippet
:param message: message to log.warn() if render is called
'''
lazy = DeprecatedLazyRenderer(render, message)
t_path, t_type = template_info(target_template)
if t_type.startswith('genshi'):
return lazy.__html__()
return lazy

class DeprecatedLazyRenderer(object):
'''
An object that will defer rendering until absolutely necessary to
pass to a template that might do {{ the_object | safe }}.
Used maintain backwards compatibility with templates that used to
expect a pre-rendered HTML snippet but have been updated to use
a normal {% snippet %} tag.
'''
def __init__(self, render, message):
self._html = None
self._render = render
self._message = message

def __html__(self):
if not self._html:
log.warn(self._message)
self._html = self._render()
return self._html

0 comments on commit 5786994

Please sign in to comment.