# HG changeset patch # User Marcin Kuzminski # Date 1275854094 -7200 # Node ID 6ada8c2233744b282d7c1e74bba96065123d3b25 # Parent dee1913f7f5a638a36df1959b140da93c54b9761 made global funcion to clean repo names, and remove all special chars from the name. Switched message slug into webhelpers function diff -r dee1913f7f5a -r 6ada8c223374 pylons_app/controllers/error.py --- a/pylons_app/controllers/error.py Sun Jun 06 10:57:49 2010 +0200 +++ b/pylons_app/controllers/error.py Sun Jun 06 21:54:54 2010 +0200 @@ -8,7 +8,7 @@ from pylons_app.lib.base import BaseController, render from pylons.middleware import media_path from pylons_app.lib.utils import check_repo -from pylons_app.lib.filters import clean_repo +import pylons_app.lib.helpers as h log = logging.getLogger(__name__) class ErrorController(BaseController): @@ -39,7 +39,7 @@ if resp.status_int == 404: org_e = request.environ.get('pylons.original_request').environ c.repo_name = repo_name = org_e['PATH_INFO'].split('/')[1] - c.repo_name_cleaned = clean_repo(c.repo_name) + c.repo_name_cleaned = h.repo_name_slug(c.repo_name) if check_repo(repo_name, g.base_path): return render('/errors/error_404.html') diff -r dee1913f7f5a -r 6ada8c223374 pylons_app/lib/filters.py --- a/pylons_app/lib/filters.py Sun Jun 06 10:57:49 2010 +0200 +++ b/pylons_app/lib/filters.py Sun Jun 06 21:54:54 2010 +0200 @@ -26,14 +26,6 @@ from mercurial import util from mercurial.templatefilters import age as _age, person as _person -from string import punctuation - -def clean_repo(repo_name): - for x in punctuation: - if x != '_': - repo_name = repo_name.replace(x, '') - repo_name = repo_name.lower().strip() - return repo_name.replace(' ', '_') age = lambda x:_age(x) capitalize = lambda x: x.capitalize() diff -r dee1913f7f5a -r 6ada8c223374 pylons_app/lib/helpers.py --- a/pylons_app/lib/helpers.py Sun Jun 06 10:57:49 2010 +0200 +++ b/pylons_app/lib/helpers.py Sun Jun 06 21:54:54 2010 +0200 @@ -21,7 +21,7 @@ from webhelpers.pylonslib.secure_form import secure_form from webhelpers.text import chop_at, collapse, convert_accented_entities, \ convert_misc_entities, lchop, plural, rchop, remove_formatting, \ - replace_whitespace, urlify + replace_whitespace, urlify, truncate #Custom helper here :) @@ -92,6 +92,35 @@ return literal(annotate_highlight(filenode, url_func, **kwargs)) +def recursive_replace(str, replace=' '): + """ + Recursive replace of given sign to just one instance + @param str: given string + @param replace:char to find and replace multiple instances + + Examples:: + >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-') + 'Mighty-Mighty-Bo-sstones' + """ + + if str.find(replace * 2) == -1: + return str + else: + str = str.replace(replace * 2, replace) + return recursive_replace(str, replace) + +def repo_name_slug(value): + """ + Return slug of name of repository + """ + slug = urlify(value) + for c in """=[]\;',/~!@#$%^&*()+{}|:""": + slug = slug.replace(c, '-') + print slug + slug = recursive_replace(slug, '-') + print slug + return slug + files_breadcrumbs = _FilesBreadCrumbs() link = _Link() flash = _Flash() diff -r dee1913f7f5a -r 6ada8c223374 pylons_app/templates/base/base.html --- a/pylons_app/templates/base/base.html Sun Jun 06 10:57:49 2010 +0200 +++ b/pylons_app/templates/base/base.html Sun Jun 06 21:54:54 2010 +0200 @@ -151,15 +151,4 @@ %endif %endif - - - -<%def name="message_slug(msg)"> - <% - limit = 60 - if len(msg) > limit: - return msg[:limit]+'...' - else: - return msg - %> \ No newline at end of file diff -r dee1913f7f5a -r 6ada8c223374 pylons_app/templates/index.html --- a/pylons_app/templates/index.html Sun Jun 06 10:57:49 2010 +0200 +++ b/pylons_app/templates/index.html Sun Jun 06 21:54:54 2010 +0200 @@ -37,7 +37,7 @@ %for cnt,repo in enumerate(c.repos_list): ${h.link(repo['name'],h.url('summary_home',repo_name=repo['name']))} - ${self.message_slug(repo['description'])} + ${h.truncate(repo['description'],60)} ${repo['last_change']|n,filters.age} ${h.link_to('r%s:%s' % (repo['rev'],repo['tip']),h.url('changeset_home',repo_name=repo['name'],revision=repo['tip']))} ${repo['contact']|n,filters.person} diff -r dee1913f7f5a -r 6ada8c223374 pylons_app/templates/shortlog/shortlog_data.html --- a/pylons_app/templates/shortlog/shortlog_data.html Sun Jun 06 10:57:49 2010 +0200 +++ b/pylons_app/templates/shortlog/shortlog_data.html Sun Jun 06 21:54:54 2010 +0200 @@ -9,7 +9,7 @@ ${cs.author|n,filters.person} r${cs.revision} - ${h.link_to(self.message_slug(cs.message), + ${h.link_to(h.truncate(cs.message,60), h.url('changeset_home',repo_name=c.repo_name,revision=cs._short), title=cs.message)} diff -r dee1913f7f5a -r 6ada8c223374 pylons_app/templates/summary/summary.html --- a/pylons_app/templates/summary/summary.html Sun Jun 06 10:57:49 2010 +0200 +++ b/pylons_app/templates/summary/summary.html Sun Jun 06 21:54:54 2010 +0200 @@ -64,22 +64,13 @@

${h.link_to(_('Changes'),h.url('changelog_home',repo_name=c.repo_name))}

- <%def name="message_slug(msg)"> - <% - limit = 60 - if len(msg) > limit: - return msg[:limit]+'...' - else: - return msg - %> - %for cnt,cs in enumerate(c.repo_changesets):
${cs._ctx.date()|n,filters.age} ${cs.author|n,filters.person} r${cs.revision} - ${h.link_to(message_slug(cs.message), + ${h.link_to(truncate(cs.message,60), h.url('changeset_home',repo_name=c.repo_name,revision=cs._short), title=cs.message)}