Permalink
Browse files

Merge branch '2257-clean-helper-functions'

  • Loading branch information...
2 parents dec436b + 1501aef commit c113ef82132654f2c868ecc87a35502709b5c3e6 Sean Hammond committed Oct 12, 2012
View
@@ -1,6 +1,16 @@
CKAN CHANGELOG
++++++++++++++
+v2.0
+====
+
+* [#2257] Removed restrict_template_vars config setting.
+* [#2257] Removed deprecated facet_title() template helper function, use
+ get_facet_title() instead.
+* [#2257] Removed deprecated am_authorized() template helper function, use
+ check_access() instead.
+* [#2257] Removed deprecated datetime_to_datestr() template helper function.
+
v1.8
====
View
@@ -32,7 +32,7 @@ class _Helpers(object):
missing functions from causing template exceptions. Useful if
templates have helper functions provided by extensions that have
not been enabled. '''
- def __init__(self, helpers, restrict=True):
+ def __init__(self, helpers):
functions = {}
allowed = helpers.__allowed_functions__[:]
# list of functions due to be deprecated
@@ -41,8 +41,7 @@ def __init__(self, helpers, restrict=True):
for helper in dir(helpers):
if helper not in allowed:
self.deprecated.append(helper)
- if restrict:
- continue
+ continue
functions[helper] = getattr(helpers, helper)
if helper in allowed:
allowed.remove(helper)
@@ -80,10 +79,8 @@ def __getattr__(self, name):
return self.functions[name]
else:
if name in self.deprecated:
- msg = 'Template helper function `%s` is not available ' \
- 'as it has been deprecated.\nYou can enable it ' \
- 'by setting ckan.restrict_template_vars = true ' \
- 'in your .ini file.' % name
+ msg = ('Template helper function `{0}` is not available '
+ 'because it has been deprecated.'.format(name))
self.log.critical(msg)
else:
msg = 'Helper function `%s` could not be found\n ' \
@@ -181,9 +178,7 @@ def find_controller(self, controller):
config['pylons.app_globals']._init()
# add helper functions
- restrict_helpers = asbool(
- config.get('ckan.restrict_template_vars', 'true'))
- helpers = _Helpers(h, restrict_helpers)
+ helpers = _Helpers(h)
config['pylons.h'] = helpers
## redo template setup to use genshi.search_path
View
@@ -36,7 +36,6 @@
from pylons.i18n import _, ungettext
import ckan.lib.fanstatic_resources as fanstatic_resources
-from lib.maintain import deprecated
import ckan.model as model
import ckan.lib.formatters as formatters
@@ -294,19 +293,7 @@ def are_there_flash_messages():
return flash.are_there_messages()
-def nav_link(*args, **kwargs):
- # nav_link() used to need c passing as the first arg
- # this is deprecated as pointless
- # throws error if ckan.restrict_template_vars is True
- # When we move to strict helpers then this should be removed as a wrapper
- if len(args) > 2 or (len(args) > 1 and 'controller' in kwargs):
- if not asbool(config.get('ckan.restrict_template_vars', 'false')):
- return _nav_link(*args[1:], **kwargs)
- raise Exception('nav_link() calling has been changed. remove c in template %s or included one' % _get_template_name())
- return _nav_link(*args, **kwargs)
-
-
-def _nav_link(text, controller, **kwargs):
+def nav_link(text, controller, **kwargs):
'''
params
class_: pass extra class(s) to add to the <a> tag
@@ -343,20 +330,7 @@ def _link_class(kwargs):
return kwargs.pop('class_', '') + active
-def nav_named_link(*args, **kwargs):
- # subnav_link() used to need c passing as the first arg
- # this is deprecated as pointless
- # throws error if ckan.restrict_template_vars is True
- # When we move to strict helpers then this should be removed as a wrapper
- if len(args) > 3 or (len(args) > 0 and 'text' in kwargs) or \
- (len(args) > 1 and 'name' in kwargs):
- if not asbool(config.get('ckan.restrict_template_vars', 'false')):
- return _nav_named_link(*args[1:], **kwargs)
- raise Exception('nav_named_link() calling has been changed. remove c in template %s or included one' % _get_template_name())
- return _nav_named_link(*args, **kwargs)
-
-
-def _nav_named_link(text, name, **kwargs):
+def nav_named_link(text, name, **kwargs):
class_ = _link_class(kwargs)
return link_to(
text,
@@ -365,19 +339,7 @@ def _nav_named_link(text, name, **kwargs):
)
-def subnav_link(*args, **kwargs):
- # subnav_link() used to need c passing as the first arg
- # this is deprecated as pointless
- # throws error if ckan.restrict_template_vars is True
- # When we move to strict helpers then this should be removed as a wrapper
- if len(args) > 2 or (len(args) > 1 and 'action' in kwargs):
- if not asbool(config.get('ckan.restrict_template_vars', 'false')):
- return _subnav_link(*args[1:], **kwargs)
- raise Exception('subnav_link() calling has been changed. remove c in template %s or included one' % _get_template_name())
- return _subnav_link(*args, **kwargs)
-
-
-def _subnav_link(text, action, **kwargs):
+def subnav_link(text, action, **kwargs):
kwargs['action'] = action
class_ = _link_class(kwargs)
return link_to(
@@ -387,20 +349,7 @@ def _subnav_link(text, action, **kwargs):
)
-def subnav_named_route(*args, **kwargs):
- # subnav_link() used to need c passing as the first arg
- # this is deprecated as pointless
- # throws error if ckan.restrict_template_vars is True
- # When we move to strict helpers then this should be removed as a wrapper
- if len(args) > 2 or (len(args) > 0 and 'text' in kwargs) or \
- (len(args) > 1 and 'routename' in kwargs):
- if not asbool(config.get('ckan.restrict_template_vars', 'false')):
- return _subnav_named_route(*args[1:], **kwargs)
- raise Exception('subnav_named_route() calling has been changed. remove c in template %s or included one' % _get_template_name())
- return _subnav_named_route(*args, **kwargs)
-
-
-def _subnav_named_route(text, routename, **kwargs):
+def subnav_named_route(text, routename, **kwargs):
""" Generate a subnav element based on a named route """
# FIXME this is the same as _nav_named_link
# they should be combined
@@ -522,19 +471,6 @@ def unselected_facet_items(facet, limit=10):
return get_facet_items_dict(facet, limit=limit, exclude_active=True)
-@deprecated('Please use get_facet_title(name) for i18n improvements.')
-def facet_title(name):
- '''Returns a title for the given facet name.
-
- If a mapping is declared in the config, this is used. Otherwise it falls
- back to capitalizing the given name.
-
- This function is deprecated, use `get_facet_title` instead.
- '''
- # FIXME this looks like an i18n issue
- return config.get('search.facets.%s.title' % name, name.capitalize())
-
-
def get_facet_title(name):
# if this is set in the config use this
@@ -581,15 +517,6 @@ def sorted_extras(list_):
return output
-@deprecated('Please use check_access instead.')
-def am_authorized(c, action, domain_object=None):
- ''' Deprecated. Please use check_access instead'''
- from ckan.authz import Authorizer
- if domain_object is None:
- domain_object = model.System()
- return Authorizer.am_authorized(c, action, domain_object)
-
-
def check_access(action, data_dict=None):
from ckan.logic import check_access as check_access_logic, NotAuthorized
@@ -782,14 +709,6 @@ def render_datetime(datetime_, date_format=None, with_hours=False):
return ''
-@deprecated()
-def datetime_to_date_str(datetime_):
- '''DEPRECATED: Takes a datetime.datetime object and returns a string of it
- in ISO format.
- '''
- return datetime_.isoformat()
-
-
def date_str_to_datetime(date_str):
'''Convert ISO-like formatted datestring to datetime object.
@@ -975,23 +894,13 @@ def dump_json(obj, **kw):
return json.dumps(obj, **kw)
-def auto_log_message(*args):
- # auto_log_message() used to need c passing as the first arg
- # this is deprecated as pointless
- # throws error if ckan.restrict_template_vars is True
- # When we move to strict helpers then this should be removed as a wrapper
- if len(args) and asbool(config.get('ckan.restrict_template_vars', 'false')):
- raise Exception('auto_log_message() calling has been changed. remove c in template %s or included one' % _get_template_name())
- return _auto_log_message()
-
-
def _get_template_name():
#FIX ME THIS IS BROKEN
''' helper function to get the currently/last rendered template name '''
return c.__debug_info[-1]['template_name']
-def _auto_log_message():
+def auto_log_message():
if (c.action == 'new'):
return _('Created new dataset.')
elif (c.action == 'editresources'):
@@ -1402,7 +1311,6 @@ def resource_preview(resource, pkg_id):
# these are the functions that will end up in `h` template helpers
-# if config option restrict_template_vars is true
__allowed_functions__ = [
# functions defined in ckan.lib.helpers
'redirect_to',
@@ -1419,8 +1327,6 @@ def resource_preview(resource, pkg_id):
'subnav_link',
'subnav_named_route',
'default_group_type',
- # 'facet_title', # deprecated
- # am_authorized, # deprecated
'check_access',
'linked_user',
'group_name_to_title',
@@ -1435,7 +1341,6 @@ def resource_preview(resource, pkg_id):
'pager_url',
'render_datetime',
'date_str_to_datetime',
- 'datetime_to_date_str',
'parse_rfc_2822_date',
'time_ago_in_words_from_str',
'button_attr',
@@ -1,5 +1,3 @@
-from ckan.lib.helpers import datetime_to_date_str
-
from ckan.tests.functional.api.base import *
from ckan.tests import TestController as ControllerTestCase
@@ -48,15 +46,15 @@ def test_12_search_revision_since_time(self):
revs = model.Session.query(model.Revision).all()
# Check since time of first.
rev_first = revs[-1]
- params = "?since_time=%s" % datetime_to_date_str(rev_first.timestamp)
+ params = "?since_time=%s" % rev_first.timestamp.isoformat()
res = self.app.get(offset+params, status=200)
res_list = self.data_from_res(res)
assert rev_first.id not in res_list
for rev in revs[:-1]:
assert rev.id in res_list, (rev.id, res_list)
# Check since time of last.
rev_last = revs[0]
- params = "?since_time=%s" % datetime_to_date_str(rev_last.timestamp)
+ params = "?since_time=%s" % rev_last.timestamp.isoformat()
res = self.app.get(offset+params, status=200)
res_list = self.data_from_res(res)
assert res_list == [], res_list
@@ -35,7 +35,7 @@ def test_render_datetime_blank(self):
assert_equal(res, '')
def test_datetime_to_date_str(self):
- res = h.datetime_to_date_str(datetime.datetime(2008, 4, 13, 20, 40, 20, 123456))
+ res = datetime.datetime(2008, 4, 13, 20, 40, 20, 123456).isoformat()
assert_equal(res, '2008-04-13T20:40:20.123456')
def test_date_str_to_datetime_date_only(self):
@@ -73,7 +73,7 @@ def test_date_str_to_datetime_with_ambiguous_microseconds(self):
def test_time_ago_in_words_from_str(self):
two_months_ago = datetime.datetime.now() - datetime.timedelta(days=65)
- two_months_ago_str = h.datetime_to_date_str(two_months_ago)
+ two_months_ago_str = two_months_ago.isoformat()
res = h.time_ago_in_words_from_str(two_months_ago_str)
assert_equal(res, '2 months')
View
@@ -569,12 +569,11 @@ Guidelines when writing controller actions:
ckan.logic.action.get.group_activity_list_html(...)
-- Controllers have access to helper functions in ``ckan.lib.helpers``. When
- developing for ckan core, only use the helper functions found in
- ``ckan.lib.helpers.__allowed_functions__`` because any instance may set the
- ``ckan.restrict_template_vars`` configuration value to ``True``.
+- Controllers have access to helper functions in ``ckan.lib.helpers``.
+ When developing for ckan core, only use the helper functions found in
+ ``ckan.lib.helpers.__allowed_functions__``.
-.. todo:: Anything else for contrllers?
+.. todo:: Anything else for controllers?
Templating
----------
@@ -584,8 +583,7 @@ Helper Functions
Templates have access to a set of helper functions in ``ckan.lib.helpers``.
When developing for ckan core, only use the helper functions found in
-``ckan.lib.helpers.__allowed_functions__`` because any instance may set the
-``ckan.restrict_template_vars`` configuration value to ``True``.
+``ckan.lib.helpers.__allowed_functions__``.
.. todo:: Jinja2 templates
View
@@ -681,22 +681,3 @@ Example::
ckan.backup_dir = /var/backups/ckan/
This is a directory where SQL database backups are to be written, assuming a script has been installed to do this.
-
-
-
-Compatibility
--------------
-
-.. index::
- single: restrict_template_vars
-
-restrict_template_vars
-^^^^^^^^^^^^^^^^^^^^^^
-
-Example::
-
- ckan.restrict_template_vars = true
-
-Default value: ``false``
-
-This is used to limit the functions available via h in templates. It also forces correct usage of functions as some function signatures have changed. It's main purpose is to allow transition to a cleaner world.
View
@@ -33,8 +33,6 @@ package_edit_return_url = http://localhost/dataset/<NAME>?test=edit
rdf_packages = http://test.com/package/
ckan.extra_resource_fields = alt_url
-# disable this so we can test all types of indexing
-ckan.restrict_template_vars = false
# we need legacy templates for many tests to pass
ckan.legacy_templates = yes

0 comments on commit c113ef8

Please sign in to comment.