P5-703 add support for categories

This commit is contained in:
Martin
2016-06-03 16:32:18 +02:00
parent 672305dee6
commit 7109c7bde5
10 changed files with 177 additions and 7 deletions
+26
View File
@@ -0,0 +1,26 @@
# coding=UTF-8
import unidecode
import re
def slugify(text):
"""Converts a string to a human-readable url"""
# translate
text = unidecode.unidecode(text)
# lowercase
text = text.lower()
# replace unwanted chars
numbers = re.compile('(?<=\d),(?=\d)')
text = numbers.sub('', text)
unwanted_chars = re.compile(r'[^_a-z0-9/]+')
text = unwanted_chars.sub('_', text)
# remove redundant _
duplicated_underscores = re.compile('_{2,}')
text = duplicated_underscores.sub('_', text)
text = text.strip('_')
return text