xotl.tools.web – Utils for Web applications

Utils for Web applications.

xotl.tools.web.slugify(s, entities=True, decimal=True, hexadecimal=True)[source]

Convert a string to a slug representation.

Normalizes string, converts to lower-case, removes non-alpha characters, and converts spaces to hyphens.

Parts from http://www.djangosnippets.org/snippets/369/

>>> slugify("Manuel Vázquez Acosta")    # doctest: +SKIP
'manuel-vazquez-acosta'

If s and entities is True (the default) all HTML entities are replaced by its equivalent character before normalization:

>>> slugify("Manuel Vázquez Acosta")   
'manuel-vazquez-acosta'

If entities is False, then no HTML-entities substitution is made:

>>> value = "Manuel Vázquez Acosta"
>>> slugify(value, entities=False)  
'manuel-v-aacute-zquez-acosta'

If decimal is True, then all entities of the form &#nnnn where nnnn is a decimal number deemed as a unicode codepoint, are replaced by the corresponding unicode character:

>>> slugify('Manuel Vázquez Acosta')  
'manuel-vazquez-acosta'

>>> value = 'Manuel Vázquez Acosta'
>>> slugify(value, decimal=False)  
'manuel-v-225-zquez-acosta'

If hexadecimal is True, then all entities of the form &#nnnn where nnnn is a hexdecimal number deemed as a unicode codepoint, are replaced by the corresponding unicode character:

>>> slugify('Manuel Vázquez Acosta')  
'manuel-vazquez-acosta'

>>> slugify('Manuel Vázquez Acosta', hexadecimal=False)  
'manuel-v-x00e1-zquez-acosta'

Deprecated since version 2.1.0: Use xotl.tools.strings.slugify().