Mercurial > kallithea
changeset 7805:b077cf7e7f90
helpers: use WebHelpers2 as much as possible - it supports Python3, and WebHelpers is dead
The remaining uses of WebHelpers have to be replaced too - see
https://webhelpers2.readthedocs.io/en/latest/migrate.html .
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Mon, 22 Jul 2019 04:18:37 +0200 |
parents | 09100b3b8f42 |
children | 87672c1916f8 |
files | kallithea/controllers/search.py kallithea/lib/helpers.py kallithea/lib/page.py kallithea/lib/utils2.py kallithea/model/db.py setup.py |
diffstat | 6 files changed, 34 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/search.py Tue Aug 06 22:42:37 2019 +0200 +++ b/kallithea/controllers/search.py Mon Jul 22 04:18:37 2019 +0200 @@ -34,7 +34,7 @@ from whoosh.index import open_dir, exists_in, EmptyIndexError from whoosh.qparser import QueryParser, QueryParserError from whoosh.query import Phrase, Prefix -from webhelpers.util import update_params +from webhelpers2.html.tools import update_params from kallithea.lib.auth import LoginRequired from kallithea.lib.base import BaseRepoController, render @@ -120,8 +120,7 @@ def url_generator(**kw): q = urllib.quote(safe_str(c.cur_query)) - return update_params("?q=%s&type=%s" \ - % (q, safe_str(c.cur_type)), **kw) + return update_params("?q=%s&type=%s" % (q, safe_str(c.cur_type)), **kw) repo_location = RepoModel().repos_path c.formated_results = Page( WhooshResultWrapper(search_type, searcher, matcher,
--- a/kallithea/lib/helpers.py Tue Aug 06 22:42:37 2019 +0200 +++ b/kallithea/lib/helpers.py Mon Jul 22 04:18:37 2019 +0200 @@ -31,14 +31,14 @@ from pygments import highlight as code_highlight from tg.i18n import ugettext as _ -from webhelpers.html import literal, HTML, escape -from webhelpers.html.tags import checkbox, end_form, hidden, link_to, \ - select, submit, text, password, textarea, radio, form as insecure_form -from webhelpers.number import format_byte_size +from webhelpers2.html import literal, HTML, escape +from webhelpers2.html.tags import checkbox, end_form, hidden, link_to, \ + select as webhelpers2_select, Option, Options, \ + submit, text, password, textarea, radio, form as insecure_form +from webhelpers2.number import format_byte_size from webhelpers.pylonslib import Flash as _Flash -from webhelpers.text import chop_at, truncate, wrap_paragraphs -from webhelpers.html.tags import _set_input_attrs, _set_id_attr, \ - convert_boolean_attrs, NotGiven, _make_safe_id_component +from webhelpers2.text import chop_at, truncate, wrap_paragraphs +from webhelpers2.html.tags import _input, NotGiven, _make_safe_id_component from kallithea.config.routing import url from kallithea.lib.annotate import annotate_highlight @@ -144,17 +144,29 @@ return s -def _reset(name, value=None, id=NotGiven, type="reset", **attrs): - """ - Reset button - """ - _set_input_attrs(attrs, type, name, value) - _set_id_attr(attrs, id, name) - convert_boolean_attrs(attrs, ["disabled"]) - return HTML.input(**attrs) +def reset(name, value, id=NotGiven, **attrs): + """Create a reset button, similar to webhelpers2.html.tags.submit .""" + return _input("reset", name, value, id, attrs) -reset = _reset +def select(name, selected_values, options, id=NotGiven, **attrs): + """Convenient wrapper of webhelpers2 to let it accept options as a tuple list""" + if isinstance(options, list): + l = [] + for x in options: + try: + value, label = x + except ValueError: # too many values to unpack + if isinstance(x, basestring): + value = label = x + else: + log.error('invalid select option %r', x) + raise + l.append(Option(label, value)) + options = Options(l) + return webhelpers2_select(name, selected_values, options, id=id, **attrs) + + safeid = _make_safe_id_component
--- a/kallithea/lib/page.py Tue Aug 06 22:42:37 2019 +0200 +++ b/kallithea/lib/page.py Mon Jul 22 04:18:37 2019 +0200 @@ -18,7 +18,7 @@ import math import re from kallithea.config.routing import url -from webhelpers.html import literal, HTML +from webhelpers2.html import literal, HTML from webhelpers.paginate import Page as _Page log = logging.getLogger(__name__)
--- a/kallithea/lib/utils2.py Tue Aug 06 22:42:37 2019 +0200 +++ b/kallithea/lib/utils2.py Mon Jul 22 04:18:37 2019 +0200 @@ -40,7 +40,7 @@ import webob import urlobject -from webhelpers.text import collapse, remove_formatting, strip_tags +from webhelpers2.text import collapse, remove_formatting, strip_tags from tg.i18n import ugettext as _, ungettext from kallithea.lib.vcs.utils.lazy import LazyProperty
--- a/kallithea/model/db.py Tue Aug 06 22:42:37 2019 +0200 +++ b/kallithea/model/db.py Mon Jul 22 04:18:37 2019 +0200 @@ -1495,7 +1495,7 @@ @classmethod def _generate_choice(cls, repo_group): """Return tuple with group_id and name as html literal""" - from webhelpers.html import literal + from webhelpers2.html import literal if repo_group is None: return (-1, u'-- %s --' % _('top level')) return repo_group.group_id, literal(cls.SEP.join(repo_group.full_path_splitted))
--- a/setup.py Tue Aug 06 22:42:37 2019 +0200 +++ b/setup.py Mon Jul 22 04:18:37 2019 +0200 @@ -44,6 +44,7 @@ "tgext.routes >= 0.2.0, < 1", "Beaker >= 1.7.0, < 2", "WebHelpers >= 1.3, < 1.4", + "WebHelpers2 >= 2.0, < 2.1", "FormEncode >= 1.3.0, < 1.4", "SQLAlchemy >= 1.1, < 1.4", "Mako >= 0.9.0, < 1.1",