Mercurial > kallithea
diff rhodecode/lib/helpers.py @ 2165:dc2584ba5fbc
merged beta into default branch
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 28 Mar 2012 19:54:16 +0200 |
parents | 82a88013a3fd 04d3fae0e4c0 |
children | a437a986d399 |
line wrap: on
line diff
--- a/rhodecode/lib/helpers.py Sat Mar 03 03:41:19 2012 +0200 +++ b/rhodecode/lib/helpers.py Wed Mar 28 19:54:16 2012 +0200 @@ -39,12 +39,20 @@ from rhodecode.lib.annotate import annotate_highlight from rhodecode.lib.utils import repo_name_slug -from rhodecode.lib import str2bool, safe_unicode, safe_str, get_changeset_safe +from rhodecode.lib.utils2 import str2bool, safe_unicode, safe_str, \ + get_changeset_safe from rhodecode.lib.markup_renderer import MarkupRenderer log = logging.getLogger(__name__) +def shorter(text, size=20): + postfix = '...' + if len(text) > size: + return text[:size - len(postfix)] + postfix + return text + + def _reset(name, value=None, id=NotGiven, type="reset", **attrs): """ Reset button @@ -67,7 +75,7 @@ :param path: """ - return 'C-%s-%s' % (short_id(raw_id), md5(path).hexdigest()[:12]) + return 'C-%s-%s' % (short_id(raw_id), md5(safe_str(path)).hexdigest()[:12]) def get_token(): @@ -86,6 +94,7 @@ session.save() return session[token_key] + class _GetError(object): """Get error from form_errors, and represent it as span wrapped error message @@ -101,6 +110,7 @@ get_error = _GetError() + class _ToolTip(object): def __call__(self, tooltip_title, trim_at=50): @@ -112,6 +122,7 @@ return escape(tooltip_title) tooltip = _ToolTip() + class _FilesBreadCrumbs(object): def __call__(self, repo_name, rev, paths): @@ -136,8 +147,10 @@ files_breadcrumbs = _FilesBreadCrumbs() + class CodeHtmlFormatter(HtmlFormatter): - """My code Html Formatter for source codes + """ + My code Html Formatter for source codes """ def wrap(self, source, outfile): @@ -319,7 +332,7 @@ # SCM FILTERS available via h. #============================================================================== from rhodecode.lib.vcs.utils import author_name, author_email -from rhodecode.lib import credentials_filter, age as _age +from rhodecode.lib.utils2 import credentials_filter, age as _age from rhodecode.model.db import User age = lambda x: _age(x) @@ -759,10 +772,10 @@ d_v = d if d > 0 else '' def cgen(l_type): - mapping = {'tr': 'top-right-rounded-corner', - 'tl': 'top-left-rounded-corner', - 'br': 'bottom-right-rounded-corner', - 'bl': 'bottom-left-rounded-corner'} + mapping = {'tr': 'top-right-rounded-corner-mid', + 'tl': 'top-left-rounded-corner-mid', + 'br': 'bottom-right-rounded-corner-mid', + 'bl': 'bottom-left-rounded-corner-mid'} map_getter = lambda x: mapping[x] if l_type == 'a' and d_v: @@ -801,6 +814,12 @@ def urlify_changesets(text_, repository): + """ + Extract revision ids from changeset and make link from them + + :param text_: + :param repository: + """ import re URL_PAT = re.compile(r'([0-9a-fA-F]{12,})') @@ -839,8 +858,8 @@ import re import traceback - # urlify changesets - text_ = urlify_changesets(text_, repository) + def escaper(string): + return string.replace('<', '<').replace('>', '>') def linkify_others(t, l): urls = re.compile(r'(\<a.*?\<\/a\>)',) @@ -852,6 +871,11 @@ links.append(e) return ''.join(links) + + + # urlify changesets - extrac revisions and make link out of them + text_ = urlify_changesets(escaper(text_), repository) + try: conf = config['app_conf']