本文整理汇总了Python中pytils.translit.translify函数的典型用法代码示例。如果您正苦于以下问题:Python translify函数的具体用法?Python translify怎么用?Python translify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了translify函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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!')
开发者ID:wd5,项目名称:810arz,代码行数:25,代码来源:views.py
示例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()
开发者ID:zdimon,项目名称:mapshop,代码行数:11,代码来源:models.py
示例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)
开发者ID:ChristosChristofidis,项目名称:djang0byte,代码行数:14,代码来源:utils.py
示例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!"
开发者ID:pgrafov,项目名称:mulan,代码行数:15,代码来源:models.py
示例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
开发者ID:Kuznitsin,项目名称:grab,代码行数:35,代码来源:russian.py
示例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}
开发者ID:AndreyBalychev,项目名称:pytils,代码行数:7,代码来源:pytils_translit.py
示例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')
开发者ID:thaxter,项目名称:django-cked,代码行数:33,代码来源:views.py
示例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
开发者ID:mrmichalis,项目名称:grab,代码行数:25,代码来源:russian.py
示例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))
开发者ID:vishnevski,项目名称:django-ckeditor,代码行数:25,代码来源:views.py
示例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
开发者ID:Arpaso,项目名称:haystack-snippet,代码行数:31,代码来源:views.py
示例11: rename_file
def rename_file(self, filename):
from pytils import translit
filename = translit.translify(filename)
filename = self.get_indexed_name(filename)
return filename
开发者ID:secretgspot,项目名称:bootstrap-12,代码行数:7,代码来源:file_manager.py
示例12: slugify_func
def slugify_func(self, content):
try:
from pytils.translit import translify
content = translify(content)
except:
pass
return slugify(content)
开发者ID:Egregors,项目名称:django-autoslug-field,代码行数:8,代码来源:fields.py
示例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!'
开发者ID:RaSergiy,项目名称:holydate,代码行数:8,代码来源:cli.py
示例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}
开发者ID:mvasilkov,项目名称:pytils,代码行数:8,代码来源:pytils_translit.py
示例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)
开发者ID:vechnoe,项目名称:holydate,代码行数:9,代码来源:cli.py
示例16: _file_view
def _file_view(request, transformation_name, file_id=None, download=False):
not_found_path = '%snotfound/%s'
converting_path = '%sconverting/%s'
if file_id:
try:
file = File.objects.get(id=file_id)
except File.DoesNotExist:
file = None
raise Http404()
else:
try:
modification = file.modifications[transformation_name]
except File.DerivativeNotFound:
modification = None
else:
file = None
modification = None
if modification:
response = HttpResponse(modification.file.read(),
content_type='application/octet-stream' if download
else
modification.file.content_type
)
response['Last-Modified'] = modification.file.upload_date
if download:
user_agent = request.META.get('HTTP_USER_AGENT', '').lower()
file_name = (file.name or str(file.id)) + ('.%s' % file.extension
if file.extension else '')
file_name = translify(file_name)
if 0: #TODO
file_name = iri_to_uri(file_name)
if user_agent.find('opera') == -1:
pass
if user_agent.find('msie') != -1:
file_name.replace('+', '%20')
response['Content-Disposition'] = 'attachment; filename="%s";' % file_name
return response
if file and os.path.exists(converting_path %
(settings.MEDIA_ROOT, transformation_name)):
return redirect(converting_path %
(settings.MEDIA_URL, transformation_name))
if os.path.exists(not_found_path %
(settings.MEDIA_ROOT, transformation_name)):
return redirect(not_found_path %
(settings.MEDIA_URL, transformation_name))
raise Http404()
开发者ID:django-social,项目名称:django-social,代码行数:57,代码来源:views.py
示例17: translit
def translit(self, name):
output_name = []
for letter in name:
try:
out_letter = translify(letter)
except ValueError:
out_letter = '1'
output_name.append(out_letter)
output_name = ''.join(output_name)
return output_name
开发者ID:odin793,项目名称:erahtur-chat,代码行数:10,代码来源:models.py
示例18: community_upload
def community_upload(instance, filename):
filename = translit.translify(filename)
new_name = md5(filename)
path = "uploads/communities/%(cid)d/p_%(filename)s%(ext)s" % {
'cid': instance.id or 0,
'filename': new_name.hexdigest(),
'ext': os.path.splitext(filename)[-1]
}
print path
return path
开发者ID:razum2um,项目名称:socio,代码行数:10,代码来源:community.py
示例19: handle_uploaded_file
def handle_uploaded_file(f, filename, folder):
name, ext = os.path.splitext(translify(filename).replace(' ', '_'))
hashed_name=md5.md5(name+datetime.datetime.now().strftime("%Y%m%d%H%M%S")).hexdigest()
path_name = settings.MEDIA_ROOT + '/uploads/' + folder + hashed_name + ext
destination = open(path_name, 'wb+')
for chunk in f.chunks():
destination.write(chunk)
destination.close()
return '/media/uploads/'+ folder + hashed_name + ext
开发者ID:Artamir,项目名称:sphere,代码行数:10,代码来源:views.py
示例20: save
def save(self, *args, **kwargs):
try:
from pytils.translit import translify
except ImportError:
self.slug = slugify(self.label)
else:
self.slug = slugify(translify(self.label))
self.slug = self.slug.replace('-', '_')
return super(AbstractField, self).save(*args, **kwargs)
开发者ID:amakhnach,项目名称:django-forms-builder,代码行数:11,代码来源:models.py
注:本文中的pytils.translit.translify函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论