本文整理汇总了Python中pytils.translit.translify函数的典型用法代码示例。如果您正苦于以下问题:Python translify函数的具体用法?Python translify怎么用?Python translify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了translify函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_pricelist
def upload_pricelist(request):
if request.user.is_staff:
if request.method == 'POST':
f = request.FILES['file']
filename = request.FILES['file'].name
name, ext = os.path.splitext(translify(filename).replace(' ', '_'))
newname = '/uploads/' + 'purchase_doc' + ext
oldfile = 'purchase_doc'
for root, dirs, files in os.walk(settings.MEDIA_ROOT+'/uploads/',):
for filename in files:
name, ext = os.path.splitext(translify(u'%s' % filename).replace(' ', '_'))
if name=='purchase_doc':
oldfile = '/uploads/' + filename
try:
os.remove(settings.MEDIA_ROOT + oldfile)
except OSError:
oldfile = False
path_name = settings.MEDIA_ROOT + newname
destination = open(path_name, 'wb+')
for chunk in f.chunks():
destination.write(chunk)
destination.close()
return http.HttpResponseRedirect('/admin/')
else:
return http.HttpResponse('403 Forbidden. Authentication Required!')
示例2: set_slug
def set_slug(self):
from pytils.translit import translify
n = ''
if(self.first_name):
n = n + translify(self.first_name)
if(self.last_name):
n = n +'-'+ translify(self.last_name)
st = str(self.id)+'-'+n
self.slug = st
#import pdb; pdb.set_trace()
self.save()
示例3: file_upload_path
def file_upload_path(instance, filename):
"""Generates upload path
Keyword arguments:
instance -- FileField
filename - String
Returns: String
"""
parts = filename.rsplit('.', 1)
name = "%s.%s" % (slugify(translify(parts[0])), slugify(translify(parts[1])))
return "%s/%s/%s/%s" % (strftime('%Y'),
strftime('%m'), strftime('%d'), name)
示例4: to_sms
def to_sms (self):
addr_part = remove_short_numbers (translit.translify(u"Addr:" + self.address()))
tel_part = remove_short_numbers (translit.translify(u"Tel:" + self.phoneNo))
order_part = remove_short_numbers (translit.translify(u'Zakaz:' + self.orderItems()))
name_part = remove_short_numbers (translit.translify(u"Imya:" + self.name if self.name else u''))
comment = remove_short_numbers (translit.translify (u"Komment:" + self.comment if self.comment else u''))
zakaz = " ".join ([addr_part, tel_part, order_part])
if (name_part) and (len(zakaz) + len(" ")+ len(name_part)) <= 160:
zakaz += " " + name_part
if (comment) and (len(zakaz) + len(" ")+ len(comment)) <= 160:
zakaz += " " + comment
if len(zakaz) <= 160:
return zakaz
else:
return u"Shlishkom dlinnyi zakaz! Smotrite na sayte ili na pochte!"
示例5: slugify
def slugify(value, limit=None, default='', lower=True, dot_allowed=False):
value = smart_unicode(value)
# Replace all non-allowed chars with "-" char
# to help pytils not to crash
if dot_allowed:
value = RE_NOT_ENRUCHAR_DOT.sub('-', value)
else:
value = RE_NOT_ENRUCHAR.sub('-', value)
# Do transliteration
value = translify(value)
# Replace trash with safe "-" char
if dot_allowed:
value = RE_NOT_ENCHAR_DOT.sub('-', value)
else:
value = RE_NOT_ENCHAR.sub('-', value)
# Replace "-" from both side of the string
value = value.strip('-')
if lower:
value = value.lower()
# Replace sequences of dashes
value = RE_DASH.sub('-', value)
if limit is not None:
value = value[:limit]
if value != "":
return value
else:
return default
示例6: translify
def translify(text):
"""Translify russian text"""
try:
res = translit.translify(smart_unicode(text, encoding))
except Exception, err:
# because filter must die silently
res = default_value % {'error': err, 'value': text}
示例7: elfinder_connector
def elfinder_connector(request):
elf = elFinder.connector(settings.ELFINDER_OPTIONS)
req = {}
if request.method == 'GET':
form = request.GET
else:
form = request.POST
for field in elf.httpAllowedParameters:
if field in form:
req[field] = form.get(field)
# Hack by Kidwind
if field == 'targets[]' and hasattr(form, 'getlist'):
req[field] = form.getlist(field)
if request.FILES and request.FILES.getlist('upload[]'):
up_files = {}
for up in request.FILES.getlist('upload[]'):
if up.name:
file_name = slugify(translify(up.name))
up_files[file_name] = up.file
req[field] = up_files
status, header, response = elf.run(req)
if not response is None and status == 200:
if 'file' in response and isinstance(response['file'], file):
response['file'].close()
return HttpResponse(json.dumps(response), content_type='application/json')
示例8: slugify
def slugify(value, limit=None, default='', lower=True):
value = smart_unicode(value)
# Replace all non russian/english chars with "-" char
# to help pytils not to crash
value = RE_NOT_ENRUCHAR.sub('-', value)
# Do transliteration
value = translify(value)
# Replace trash with safe "-" char
value = RE_NOT_ENCHAR.sub('-', value).strip('-')
if lower:
value = value.lower()
# Replace sequences of dashes
value = RE_DASH.sub('-', value)
if limit is not None:
value = value[:limit]
if value != "":
return value
else:
return default
示例9: upload
def upload(request):
"""
Uploads a file and send back its URL to CKEditor.
TODO:
Validate uploads
"""
# Get the uploaded file from request.
upload = request.FILES['upload']
# Open output file in which to store upload.
upload_filename = generate_filename(translify(upload.name))
url = get_media_url(upload_filename)
out = open(upload_filename, 'wb+')
# Iterate through chunks and write to destination.
for chunk in upload.chunks():
out.write(chunk)
out.close()
# Respond with Javascript sending ckeditor upload url.
return HttpResponse("""
<script type='text/javascript'>
window.parent.CKEDITOR.tools.callFunction(%s, '%s');
</script>""" % (request.GET['CKEditorFuncNum'], url))
示例10: get_results
def get_results(self):
"""
Fetches the results via the form.
Returns an empty list if there's no query to search with.
"""
query = self.query
if not (self.form.is_valid() and query):
return self.form.no_query_found()
#Replace letter ё --> е
query = replace_special(query)
# save the query to statistic
if 'page' not in self.request.GET and query:
rows = SearchLogger.objects.filter(text=query).update(counter=F('counter')+1)
if not rows:
SearchLogger.objects.create(text=query)
translited_query = force_unicode(translify(query))
detranslited_query = force_unicode(detranslify(query))
sqs = self.searchqueryset().filter_and(SQ(content=detranslited_query) | SQ(content=translited_query) | SQ(content=query))
#sqs = self.searchqueryset().auto_query(query)
if self.load_all:
sqs = sqs.load_all()
return sqs
示例11: rename_file
def rename_file(self, filename):
from pytils import translit
filename = translit.translify(filename)
filename = self.get_indexed_name(filename)
return filename
示例12: slugify_func
def slugify_func(self, content):
try:
from pytils.translit import translify
content = translify(content)
except:
pass
return slugify(content)
示例13: translit_cal
def translit_cal(string):
"""Print transliterated formatted calendar. """
try:
out = string.replace('ⵛ', '-:)').replace('☩', '+').replace('⊕', '(+)')
return translit.translify(out.decode('utf8'))
except UnicodeDecodeError:
return 'Transliteration is not working!'
示例14: translify
def translify(stext):
"""Translify russian text"""
try:
utext = pseudo_unicode(stext, encoding, default_value)
res = translit.translify(utext)
except Exception, err:
# because filter must die silently
res = default_value % {"error": err, "value": stext}
示例15: translit_cal
def translit_cal(string):
"""
:return transliterated formatted calendar.
"""
out = string.replace(
DICT_FORMAT['gl'], u'-:)').replace(
DICT_FORMAT['pl'], u'+').replace(
DICT_FORMAT['tw'], u'(+)')
return translit.translify(out)