mirror of
https://github.com/NaN-tic/trytond-galatea_tutorial.git
synced 2023-12-14 02:32:55 +01:00
27 lines
776 B
Python
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
|