You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

35 lines
974 B

# -*- coding: utf-8 -*-
from django.core.exceptions import ValidationError
import pytils, re
def is_positive_integer(data,
msg='Введите правильное значение'):
"""
function checking if data positive integer
"""
if not data:
return
elif data.isdigit() and int(data) > 0:
return int(data)
else:
raise ValidationError(msg)
def translit_with_separator(string, separator='-'):
"""
Trsanslit string and replace "bad" symbols for separator
usage: translit_with_separator('введите, слово', '_') return 'vvedite_slovo'
"""
string = string.strip()
#make string unicode
string = u'%s'%string
#make string translit
st = pytils.translit.translify(string)
#replace "bad" symbols for '-'symbol
st = re.sub('[^\w\-_\.]', separator, st)
#delete dublicating separators
st = re.sub('%s+'%separator, separator, st)
return st