Mercurial > kallithea
changeset 1342:9dacacc5b7c2 beta
When creating a remote repository, with credentials filled, it's good to hide username and password from the clone url. Only administrators can see this in repository settings page
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 22 May 2011 21:09:02 +0200 |
parents | 1881b808a71d |
children | a04fe5986109 |
files | rhodecode/lib/__init__.py rhodecode/lib/helpers.py rhodecode/templates/summary/summary.html |
diffstat | 3 files changed, 100 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/lib/__init__.py Sun May 15 19:13:08 2011 +0200 +++ b/rhodecode/lib/__init__.py Sun May 22 21:09:02 2011 +0200 @@ -173,3 +173,72 @@ kwargs.update({'poolclass': NullPool}) return efc(configuration, prefix, **kwargs) + + +def age(curdate): + """ + turns a datetime into an age string. + + :param curdate: datetime object + :rtype: unicode + :returns: unicode words describing age + """ + + from datetime import datetime + from webhelpers.date import time_ago_in_words + + _ = lambda s:s + + if not curdate: + return '' + + agescales = [(_(u"year"), 3600 * 24 * 365), + (_(u"month"), 3600 * 24 * 30), + (_(u"day"), 3600 * 24), + (_(u"hour"), 3600), + (_(u"minute"), 60), + (_(u"second"), 1), ] + + age = datetime.now() - curdate + age_seconds = (age.days * agescales[2][1]) + age.seconds + pos = 1 + for scale in agescales: + if scale[1] <= age_seconds: + if pos == 6:pos = 5 + return '%s %s' % (time_ago_in_words(curdate, + agescales[pos][0]), _('ago')) + pos += 1 + + return _(u'just now') + + +def credentials_hidder(uri): + """ + Removes user:password from given url string + + :param uri: + :rtype: unicode + :returns: filtered list of strings + """ + if not uri: + return '' + + proto = '' + + for pat in ('https://', 'http://'): + if uri.startswith(pat): + uri = uri[len(pat):] + proto = pat + break + + # remove passwords and username + uri = uri[uri.find('@') + 1:] + + # get the port + cred_pos = uri.find(':') + if cred_pos == -1: + host, port = uri, None + else: + host, port = uri[:cred_pos], uri[cred_pos + 1:] + + return filter(None, [proto, host, port])
--- a/rhodecode/lib/helpers.py Sun May 15 19:13:08 2011 +0200 +++ b/rhodecode/lib/helpers.py Sun May 22 21:09:02 2011 +0200 @@ -320,30 +320,9 @@ #============================================================================== from mercurial import util from mercurial.templatefilters import person as _person - -def _age(curdate): - """turns a datetime into an age string.""" - - if not curdate: - return '' +from rhodecode.lib import credentials_hidder, age as _age - agescales = [("year", 3600 * 24 * 365), - ("month", 3600 * 24 * 30), - ("day", 3600 * 24), - ("hour", 3600), - ("minute", 60), - ("second", 1), ] - age = datetime.now() - curdate - age_seconds = (age.days * agescales[2][1]) + age.seconds - pos = 1 - for scale in agescales: - if scale[1] <= age_seconds: - if pos == 6:pos = 5 - return time_ago_in_words(curdate, agescales[pos][0]) + ' ' + _('ago') - pos += 1 - - return _('just now') age = lambda x:_age(x) capitalize = lambda x: x.capitalize() @@ -351,7 +330,7 @@ email_or_none = lambda x: util.email(x) if util.email(x) != x else None person = lambda x: _person(x) short_id = lambda x: x[:12] - +hide_credentials = lambda x: ''.join(credentials_hidder(x)) def bool2icon(value): """Returns True/False values represented as small html image of true/false @@ -534,7 +513,7 @@ #============================================================================== -# REPO PAGER +# REPO PAGER, PAGER FOR REPOSITORY #============================================================================== class RepoPage(Page): @@ -620,6 +599,12 @@ def changed_tooltip(nodes): + """ + Generates a html string for changed nodes in changeset page. + It limits the output to 30 entries + + :param nodes: LazyNodesGenerator + """ if nodes: pref = ': <br/> ' suf = '' @@ -633,6 +618,15 @@ def repo_link(groups_and_repos): + """ + Makes a breadcrumbs link to repo within a group + joins » on each group to create a fancy link + + ex:: + group >> subgroup >> repo + + :param groups_and_repos: + """ groups, repo_name = groups_and_repos if not groups: @@ -646,12 +640,20 @@ def fancy_file_stats(stats): + """ + Displays a fancy two colored bar for number of added/deleted + lines of code on file + + :param stats: two element list of added/deleted lines of code + """ + a, d, t = stats[0], stats[1], stats[0] + stats[1] width = 100 unit = float(width) / (t or 1) - a_p = max(9, unit * a) if a > 0 else 0# needs > 9% to be visible - d_p = max(9, unit * d) if d > 0 else 0 # needs > 9% to be visible + # needs > 9% of width to be visible or 0 to be hidden + a_p = max(9, unit * a) if a > 0 else 0 + d_p = max(9, unit * d) if d > 0 else 0 p_sum = a_p + d_p if p_sum > width:
--- a/rhodecode/templates/summary/summary.html Sun May 15 19:13:08 2011 +0200 +++ b/rhodecode/templates/summary/summary.html Sun May 22 21:09:02 2011 +0200 @@ -75,11 +75,11 @@ ##REMOTE %if c.dbrepo.clone_uri: <div style="margin-top:5px;clear:both"> - <a href="${h.url(str(c.dbrepo.clone_uri))}"> + <a href="${h.url(str(h.hide_credentials(c.dbrepo.clone_uri)))}"> <img class="icon" alt="${_('remote clone')}" - title="${_('Clone from')} ${c.dbrepo.clone_uri}" + title="${_('Clone from')} ${h.hide_credentials(c.dbrepo.clone_uri)}" src="${h.url("/images/icons/connect.png")}"/> - ${_('Clone from')} ${c.dbrepo.clone_uri} + ${_('Clone from')} ${h.hide_credentials(c.dbrepo.clone_uri)} </a> </div> %endif