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
1012 B
35 lines
1012 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'
|
|
|
|
"""
|
|
#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
|
|
|
|
#def check_url(url, id, Model, field='url', msg='Такой урл уже занят'):
|
|
# try:
|
|
|