trytond-galatea_tutorial/tools.py
2014-12-15 10:29:32 +01:00

27 lines
776 B
Python

#~ # This file is part galatea_tutorial module for Tryton.
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
import logging
try:
import slug
except ImportError:
logging.getLogger('galatea tutorial').error(
'Unable to import slug. Install slug package.')
def slugify(value):
"""Convert value to slug: az09 and replace spaces by -"""
try:
if isinstance(value, unicode):
name = slug.slug(value)
else:
name = slug.slug(unicode(value, 'UTF-8'))
except:
name = ''
return name
def seo_lenght(string):
'''Get first 155 characters from string'''
if len(string) > 155:
return '%s...' % (string[:152])
return string