details: http://www.bx.psu.edu/hg/galaxy/rev/b4c62757393a changeset: 3266:b4c62757393a user: jeremy goecks <jeremy.goecks@emory.edu> date: Mon Jan 25 12:43:45 2010 -0500 description: Better slug generation by ignoring non-alphanumeric characters. diffstat: lib/galaxy/web/base/controller.py | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diffs (19 lines): diff -r 17db30ce0486 -r b4c62757393a lib/galaxy/web/base/controller.py --- a/lib/galaxy/web/base/controller.py Mon Jan 25 10:01:04 2010 -0500 +++ b/lib/galaxy/web/base/controller.py Mon Jan 25 12:43:45 2010 -0500 @@ -148,7 +148,15 @@ def set_item_slug( self, sa_session, item ): """ Set item slug. Slug is unique among user's importable items for item's class. """ if item.slug is None or item.slug == "": + # Replace whitespace with '-' slug_base = re.sub( "\s+", "-", item.name.lower() ) + # Remove all non-alphanumeric characters. + slug_base = re.sub( "[^a-zA-Z0-9\-]", "", slug_base ) + # Remove trailing '-'. + if slug_base.endswith('-'): + slug_base = slug_base[:-1] + + # Make sure that slug is not taken; if it is, add a number to it. slug = slug_base count = 1 while sa_session.query( item.__class__ ).filter_by( user=item.user, slug=slug, importable=True ).count() != 0: