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.
 
 
 
 
 
 

33 lines
891 B

# -*- coding: utf-8 -*-
from django.core.exceptions import ValidationError
import pytils, re
def is_positive_integer(data):
"""
function checking if data positive integer
"""
if not data:
return
elif data.isdigit() and int(data) > 0:
return int(data)
else:
raise ValidationError('Введите правильное значение')
def translit_with_separator(string, separator='-'):
"""
Trsanslit string and replace "bad" symbols for separator
usage: translit_with_separator('введите, слово', '_') return 'vvedite_slovo'
string must be unicode
"""
#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