Add slugify
This commit is contained in:
parent
98d72043ab
commit
4dd581abea
|
@ -6,7 +6,7 @@ This module contains boilerplate for python projects, mostly based on django.
|
|||
|
||||
### Django
|
||||
|
||||
#### PositiveAutoField
|
||||
#### `ktools.django.db.models.fields.PositiveAutoField`
|
||||
|
||||
A mysql-based `AutoField` that will use an `UNSIGNED INT` for a primary field.
|
||||
|
||||
|
@ -22,3 +22,6 @@ DEFAULT_AUTO_FIELD = 'ktools.django.db.models.fields.PositiveAutoField'
|
|||
|
||||
A decorator to cache return values of a method (of a class) until the class is used. Parameters are that of `lru_cache()` since it uses that function under the hood.
|
||||
|
||||
#### `ktools.django.utils.text.slugify`
|
||||
|
||||
Function to return an ASCII-safe slugified string from any utf-8 string.
|
||||
|
|
5
setup.py
5
setup.py
|
@ -6,7 +6,10 @@ setup(
|
|||
name='py-ktools',
|
||||
version='1.0.0',
|
||||
# packages=['ktools'],
|
||||
install_requires=['typing_extensions~=4.4'],
|
||||
install_requires=[
|
||||
'typing_extensions~=4.4',
|
||||
'Unidecode~=1.3.6'
|
||||
],
|
||||
author='László Károlyi',
|
||||
author_email='laszlo@karolyi.hu',
|
||||
description='Boilerplate tools for python based projects.',
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
from django.utils.encoding import force_str
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.text import slugify as django_slugify
|
||||
from unidecode import unidecode
|
||||
|
||||
_SLUG_TRANSTABLE = str.maketrans('./_', '---')
|
||||
|
||||
|
||||
def slugify(input_data: str):
|
||||
'Powerup version of the original django slugify.'
|
||||
pass_one = unidecode(force_str(input_data))\
|
||||
.translate(_SLUG_TRANSTABLE)\
|
||||
.strip('-')
|
||||
pass_two = django_slugify(value=pass_one)
|
||||
return mark_safe(pass_two)
|
Loading…
Reference in New Issue