Repository: ckan/ckan

Issue:
TypeError: do_truncate() takes at least 2 arguments (4 given)
### CKAN Version if known (or site URL)

2.6.0 and 2.7.1a (Master Branch)

### Please describe the expected behaviour

User can view any object via a get request, examples are user, organization or dataset, but basically trying to view any overview page of a CKAN 'thing'.

### Please describe the actual behaviour

Jinja template throws 500 error performing the do_truncate operation (see screenshot). For example, if I click on my username in the header toolbar or on the name of a dataset the error occurs.

![screen shot 2017-01-30 at 12 03 30](https://cloud.githubusercontent.com/assets/6863551/22423991/5a95ebfe-e6ec-11e6-9a1d-318b8f9c4df7.png)


### What steps can be taken to reproduce the issue? 

So far I've built docker images with both 2.6.0 and the master branch built from source. The Jinja repository released a 2.8.1 on 29 December which could be the root cause of this issue. The CKAN requirements list a dependency on Jinja 2.8, so it's possible a breaking change was introduced in 2.8.1. I'm going to try to update to Jinja 2.9 to see if that helps.



Discussion:
Using version 2.9.5 of Jinja with CKAN 2.6.0 has the same issue
One moment.

Resolving patch:
diff --git a/ckan/config/environment.py b/ckan/config/environment.py
--- a/ckan/config/environment.py
+++ b/ckan/config/environment.py
@@ -256,7 +256,6 @@ def update_config():
     env.install_gettext_callables(_, ungettext, newstyle=True)
     # custom filters
     env.filters['empty_and_escape'] = jinja_extensions.empty_and_escape
-    env.filters['truncate'] = jinja_extensions.truncate
     config['pylons.app_globals'].jinja_env = env
 
     # CONFIGURATION OPTIONS HERE (note: all config options will override
diff --git a/ckan/config/middleware/flask_app.py b/ckan/config/middleware/flask_app.py
--- a/ckan/config/middleware/flask_app.py
+++ b/ckan/config/middleware/flask_app.py
@@ -86,7 +86,6 @@ def make_flask_stack(conf, **app_conf):
         app.jinja_env.add_extension(extension)
     app.jinja_env.filters['empty_and_escape'] = \
         jinja_extensions.empty_and_escape
-    app.jinja_env.filters['truncate'] = jinja_extensions.truncate
 
     # Common handlers for all requests
     app.before_request(ckan_before_request)
diff --git a/ckan/lib/jinja_extensions.py b/ckan/lib/jinja_extensions.py
--- a/ckan/lib/jinja_extensions.py
+++ b/ckan/lib/jinja_extensions.py
@@ -9,7 +9,6 @@
 from jinja2 import ext
 from jinja2.exceptions import TemplateNotFound
 from jinja2.utils import open_if_exists, escape
-from jinja2.filters import do_truncate
 from jinja2 import Environment
 
 import ckan.lib.base as base
@@ -27,19 +26,6 @@ def empty_and_escape(value):
     else:
         return escape(value)
 
-def truncate(value, length=255, killwords=None, end='...'):
-    ''' A more clever truncate. If killwords is supplied we use the default
-    truncate.  Otherwise we try to truncate using killwords=False, if this
-    truncates the whole value we try again with killwords=True '''
-    if value is None:
-        return None
-    if killwords is not None:
-        return do_truncate(value, length=length, killwords=killwords, end=end)
-    result = do_truncate(value, length=length, killwords=False, end=end)
-    if result != end:
-        return result
-    return do_truncate(value, length=length, killwords=True, end=end)
-
 ### Tags
 
 def regularise_html(html):


Test patch: