diff --git a/ckan/controllers/error.py b/ckan/controllers/error.py index d03b112ef14..5bca6ab20fe 100644 --- a/ckan/controllers/error.py +++ b/ckan/controllers/error.py @@ -11,6 +11,7 @@ from ckan.lib.base import render from ckan.lib.helpers import literal + class ErrorController(BaseController): """Generates error documents as and when they are required. diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index e8a94e74b0a..557a4f472d2 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -776,11 +776,11 @@ def _create_link_text(text, **kwargs): return text icon = kwargs.pop('icon', None) - class_ = _link_class(kwargs) + cls = _link_class(kwargs) return link_to( _create_link_text(text, **kwargs), url_for(*args, **kwargs), - class_=class_ + cls=cls ) @@ -791,7 +791,11 @@ def _preprocess_dom_attrs(attrs): like `class` that cannot be used because it special meaning in Python. """ - return {key.rstrip('_'): value for key, value in attrs.items()} + return { + key.rstrip('_'): value + for key, value in attrs.items() + if value is not None + } def _make_safe_id_component(idstring): @@ -806,7 +810,7 @@ def _make_safe_id_component(idstring): Whitespace is transformed into underscores, and then anything which is not a hyphen or a character that - matches \w (alphanumerics and underscore) is removed. + matches \\w (alphanumerics and underscore) is removed. """ # Transform all whitespace to underscore @@ -1351,7 +1355,7 @@ def truncate(text, length=30, indicator='...', whole_word=False): if i <= 0: # Entire text before break is one word, or we miscalculated. return text[:short_length] + indicator - return text[:i+1] + indicator + return text[:i + 1] + indicator @core_helper diff --git a/ckan/lib/pagination.py b/ckan/lib/pagination.py index 9c90b86e37b..b20a335b462 100644 --- a/ckan/lib/pagination.py +++ b/ckan/lib/pagination.py @@ -145,7 +145,8 @@ def __init__( self.page_count = ((self.item_count - 1) / self.items_per_page) + 1 self.last_page = self.first_page + self.page_count - 1 - # Make sure that the requested page number is the range of valid pages + # Make sure that the requested page number is the range of + # valid pages if self.page > self.last_page: self.page = self.last_page elif self.page < self.first_page: @@ -241,8 +242,7 @@ def pager( dotdot_attr={u"class": u"pager_dotdot"}, **kwargs ): - """ - Return string with links to other pages (e.g. "1 2 [3] 4 5 6 7"). + """Return string with links to other pages (e.g. "1 2 [3] 4 5 6 7"). format: Format string that defines how the pager is rendered. The string @@ -374,10 +374,10 @@ def pager( Default: { 'class':'pager_dotdot' } onclick (optional) - This paramter is a string containing optional Javascript code - that will be used as the 'onclick' action of each pager link. - It can be used to enhance your pager with AJAX actions loading another - page into a DOM object. + This paramter is a string containing optional Javascript + code that will be used as the 'onclick' action of each + pager link. It can be used to enhance your pager with + AJAX actions loading another page into a DOM object. In this string the variable '$partial_url' will be replaced by the URL linking to the desired page with an added 'partial=1' @@ -385,27 +385,34 @@ def pager( In addition the '$page' variable gets replaced by the respective page number. - Note that the URL to the destination page contains a 'partial_param' - parameter so that you can distinguish between AJAX requests (just - refreshing the paginated area of your page) and full requests (loading - the whole new page). + Note that the URL to the destination page contains a + 'partial_param' parameter so that you can distinguish + between AJAX requests (just refreshing the paginated area + of your page) and full requests (loading the whole new + page). - [Backward compatibility: you can use '%s' instead of '$partial_url'] + [Backward compatibility: you can use '%s' instead of + '$partial_url'] jQuery example: "$('#my-page-area').load('$partial_url'); return false;" Yahoo UI example: "YAHOO.util.Connect.asyncRequest('GET','$partial_url',{ - success:function(o){YAHOO.util.Dom.get('#my-page-area').innerHTML=o.responseText;} - },null); return false;" + success:function(o){ + YAHOO.util.Dom.get( + '#my-page-area' + ).innerHTML=o.responseText; + } + },null); return false;" scriptaculous example: "new Ajax.Updater('#my-page-area', '$partial_url', {asynchronous:true, evalScripts:true}); return false;" ExtJS example: - "Ext.get('#my-page-area').load({url:'$partial_url'}); return false;" + "Ext.get('#my-page-area').load({url:'$partial_url'}); + return false;" Custom example: "my_load_page($page)" @@ -413,6 +420,7 @@ def pager( Additional keyword arguments are used as arguments in the links. Otherwise the link will be created with url_for() which points to the page you are currently displaying. + """ self.curpage_attr = curpage_attr self.separator = separator @@ -430,7 +438,7 @@ def pager( return u"" # Replace ~...~ in token format by range of pages - result = re.sub(r"~(\d+)~", self._range, format) + result = re.sub(u"~(\\d+)~", self._range, format) # Interpolate '%' variables result = Template(result).safe_substitute( @@ -460,7 +468,7 @@ def pager( return Markup(result) - #### Private methods #### + # Private methods def _range(self, regexp_match): """ Return range of linked pages (e.g. '1 2 [3] 4 5 6 7 8'). @@ -563,7 +571,9 @@ def _pagerlink(self, page, text): # updates) link_params[self.partial_param] = 1 partial_url = url_generator(**link_params) - try: # if '%s' is used in the 'onclick' parameter (backwards compatibility) + try: + # if '%s' is used in the 'onclick' parameter + # (backwards compatibility) onclick_action = self.onclick % (partial_url,) except TypeError: onclick_action = Template(self.onclick).safe_substitute( diff --git a/ckan/tests/legacy/functional/api/test_package_search.py b/ckan/tests/legacy/functional/api/test_package_search.py index 31792d3cc71..55b73765925 100644 --- a/ckan/tests/legacy/functional/api/test_package_search.py +++ b/ckan/tests/legacy/functional/api/test_package_search.py @@ -2,7 +2,7 @@ from six.moves.urllib.parse import quote -import webhelpers +from dominate.util import escape import ckan.lib.search as search from ckan.tests.legacy import setup_test_search_index @@ -64,7 +64,7 @@ def test_04_post_json(self): assert res_dict['result']['count'] == 1, res_dict['result']['count'] def test_06_uri_q_tags(self): - query = webhelpers.util.html_escape('annakarenina tags:russian tags:tolstoy') + query = escape('annakarenina tags:russian tags:tolstoy') offset = self.base_url + '?q=%s' % query res = self.app.get(offset, status=200) res_dict = self.data_from_res(res) diff --git a/ckan/tests/legacy/lib/test_helpers.py b/ckan/tests/legacy/lib/test_helpers.py index 5516c2808b6..e1b2eda14ac 100644 --- a/ckan/tests/legacy/lib/test_helpers.py +++ b/ckan/tests/legacy/lib/test_helpers.py @@ -64,7 +64,7 @@ def test_time_ago_in_words_from_str(self): two_months_ago = datetime.datetime.now() - datetime.timedelta(days=65) 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') + assert_equal(res, '2 months ago') def test_gravatar(self): email = 'zephod@gmail.com' diff --git a/ckan/tests/lib/test_helpers.py b/ckan/tests/lib/test_helpers.py index fcb7cfb80b1..7c918f845d1 100644 --- a/ckan/tests/lib/test_helpers.py +++ b/ckan/tests/lib/test_helpers.py @@ -420,13 +420,13 @@ def test_internal_tag_link(self): def test_internal_tag_linked_with_quotes(self): """Asserts links like 'tag:"test-tag"' work""" data = 'tag:"test-tag" foobar' - output = '

tag:"test-tag" foobar

' + output = '

tag:"test-tag" foobar

' eq_(h.render_markdown(data), output) def test_internal_tag_linked_with_quotes_and_space(self): """Asserts links like 'tag:"test tag"' work""" data = 'tag:"test tag" foobar' - output = '

tag:"test tag" foobar

' + output = '

tag:"test tag" foobar

' eq_(h.render_markdown(data), output) def test_internal_tag_with_no_opening_quote_only_matches_single_word(self): @@ -450,7 +450,7 @@ def test_internal_tag_with_no_closing_quote_does_not_match(self): def test_tag_names_match_simple_punctuation(self): """Asserts punctuation and capital letters are matched in the tag name""" data = 'tag:"Test- _." foobar' - output = '

tag:"Test- _." foobar

' + output = '

tag:"Test- _." foobar

' eq_(h.render_markdown(data), output) def test_tag_names_do_not_match_commas(self): @@ -471,7 +471,7 @@ def test_tag_names_dont_match_non_space_whitespace(self): def test_tag_names_with_unicode_alphanumeric(self): """Asserts that unicode alphanumeric characters are captured""" data = u'tag:"Japanese katakana \u30a1" blah' - output = u'

tag:"Japanese katakana \u30a1" blah

' + output = u'

tag:"Japanese katakana \u30a1" blah

' eq_(h.render_markdown(data), output) def test_normal_link(self):