Skip to content

Commit

Permalink
[#2257] Cleanup deprecated helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Sep 18, 2012
1 parent 076008f commit 80be35c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 104 deletions.
103 changes: 7 additions & 96 deletions ckan/lib/helpers.py
Expand Up @@ -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

Expand Down Expand Up @@ -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 <a> tag
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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'):
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
6 changes: 2 additions & 4 deletions 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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ckan/tests/lib/test_helpers.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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')

Expand Down
2 changes: 0 additions & 2 deletions test-core.ini
Expand Up @@ -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
# FIXME this is to allow some tests to pass but should be removed when possible
Expand Down

0 comments on commit 80be35c

Please sign in to comment.