From 80be35cca9995c050e0692b5ba3ffac1c7291461 Mon Sep 17 00:00:00 2001 From: tobes Date: Tue, 18 Sep 2012 10:54:42 +0100 Subject: [PATCH] [#2257] Cleanup deprecated helper functions --- ckan/lib/helpers.py | 103 ++---------------- .../functional/api/test_revision_search.py | 6 +- ckan/tests/lib/test_helpers.py | 4 +- test-core.ini | 2 - 4 files changed, 11 insertions(+), 104 deletions(-) diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index cda89f90fd0..0c1c8440423 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -37,7 +37,7 @@ from pylons.i18n import _, ungettext import ckan.lib.fanstatic_resources as fanstatic_resources -from lib.maintain import deprecated +#from lib.maintain import deprecated import ckan.model as model import ckan.lib.formatters as formatters @@ -295,19 +295,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 tag @@ -343,20 +331,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 +340,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 +350,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 @@ -521,18 +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 @@ -574,14 +512,6 @@ def sorted_extras(list_): output.append((k, v)) 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 @@ -772,14 +702,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. @@ -965,21 +887,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'): @@ -1322,8 +1236,6 @@ def format_resource_items(items): 'subnav_link', 'subnav_named_route', 'default_group_type', - # 'facet_title', # deprecated - # am_authorized, # deprecated 'check_access', 'linked_user', 'group_name_to_title', @@ -1338,7 +1250,6 @@ def format_resource_items(items): 'pager_url', 'render_datetime', 'date_str_to_datetime', - 'datetime_to_date_str', 'parse_rfc_2822_date', 'time_ago_in_words_from_str', 'button_attr', diff --git a/ckan/tests/functional/api/test_revision_search.py b/ckan/tests/functional/api/test_revision_search.py index f376c36db0c..d223537b1e2 100644 --- a/ckan/tests/functional/api/test_revision_search.py +++ b/ckan/tests/functional/api/test_revision_search.py @@ -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,7 +46,7 @@ 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 @@ -56,7 +54,7 @@ def test_12_search_revision_since_time(self): 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 diff --git a/ckan/tests/lib/test_helpers.py b/ckan/tests/lib/test_helpers.py index d501c8e7837..68859977c62 100644 --- a/ckan/tests/lib/test_helpers.py +++ b/ckan/tests/lib/test_helpers.py @@ -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') diff --git a/test-core.ini b/test-core.ini index c6f8cd7535a..03e997e4568 100644 --- a/test-core.ini +++ b/test-core.ini @@ -33,8 +33,6 @@ package_edit_return_url = http://localhost/dataset/?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 # FIXME this is to allow some tests to pass but should be removed when possible