django-uuslug
================
A custom slug app for Django, that guarantees Double (U)s for (Uniqueness & Unicode handling)
Most of the code is originally by snippet http://www.djangosnippets.org/snippets/369/
Improved slightly to handle unique slugs and unicode chars and packaged by Val L33.
Patches welcome: https://github.com/un33k/django-uuslug
Usage
=====
If you want a worry free slug-er, then this is for you.
It handles unicode and it produces unique slugs.
Here what you need to do:
1. Install (via source code on github) or (pip install django-uuslug) ... etc.
2. Then import it like: from uuslug import uuslug as slugify
That's it.
Unicode Test Example
=====
from uuslug import uuslug as slugify
s = "This is a test ---"
r = slugify(s)
self.assertEquals(r, "this-is-a-test")
s = 'C\'est déjà l\'été.'
r = slugify(s)
self.assertEquals(r, "c-est-deja-l-ete")
s = 'Nín hǎo. Wǒ shì zhōng guó rén'
r = slugify(s)
self.assertEquals(r, "nin-hao-wo-shi-zhong-guo-ren")
s = '影師嗎'
r = slugify(s)
self.assertEquals(r, "ying-shi-ma")
Uniqueness Test Example
=====
Override your object's save method with something like this (models.py)
from django.db import models
from uuslug import uuslug as slugify
class CoolSlug(models.Model):
name = models.CharField(max_length=100)
slug = models.CharField(max_length=200)
def __unicode__(self):
return self.name
def save(self, *args, **kwargs):
self.slug = slugify(self.name, instance=self)
super(CoolSlug, self).save(*args, **kwargs)
Test:
name = "john"
c = CoolSlug.objects.create(name=name)
c.save()
self.assertEquals(c.slug, name)
c1 = CoolSlug.objects.create(name=name)
c1.save()
self.assertEquals(c1.slug, name+"-1")
Notice:
the slug for the first object would be "john", while the second object's slug
would be "john-1".
ToDo
=====
clean up README
================
A custom slug app for Django, that guarantees Double (U)s for (Uniqueness & Unicode handling)
Most of the code is originally by snippet http://www.djangosnippets.org/snippets/369/
Improved slightly to handle unique slugs and unicode chars and packaged by Val L33.
Patches welcome: https://github.com/un33k/django-uuslug
Usage
=====
If you want a worry free slug-er, then this is for you.
It handles unicode and it produces unique slugs.
Here what you need to do:
1. Install (via source code on github) or (pip install django-uuslug) ... etc.
2. Then import it like: from uuslug import uuslug as slugify
That's it.
Unicode Test Example
=====
from uuslug import uuslug as slugify
s = "This is a test ---"
r = slugify(s)
self.assertEquals(r, "this-is-a-test")
s = 'C\'est déjà l\'été.'
r = slugify(s)
self.assertEquals(r, "c-est-deja-l-ete")
s = 'Nín hǎo. Wǒ shì zhōng guó rén'
r = slugify(s)
self.assertEquals(r, "nin-hao-wo-shi-zhong-guo-ren")
s = '影師嗎'
r = slugify(s)
self.assertEquals(r, "ying-shi-ma")
Uniqueness Test Example
=====
Override your object's save method with something like this (models.py)
from django.db import models
from uuslug import uuslug as slugify
class CoolSlug(models.Model):
name = models.CharField(max_length=100)
slug = models.CharField(max_length=200)
def __unicode__(self):
return self.name
def save(self, *args, **kwargs):
self.slug = slugify(self.name, instance=self)
super(CoolSlug, self).save(*args, **kwargs)
Test:
name = "john"
c = CoolSlug.objects.create(name=name)
c.save()
self.assertEquals(c.slug, name)
c1 = CoolSlug.objects.create(name=name)
c1.save()
self.assertEquals(c1.slug, name+"-1")
Notice:
the slug for the first object would be "john", while the second object's slug
would be "john-1".
ToDo
=====
clean up README
Metadata
Release files for django-uuslug 0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-uuslug-0.5.tar.gz | 3.6 kB | Details |
Release files / django-uuslug-0.5.tar.gz
| Download URL | django-uuslug-0.5.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5c6f638ea6a4aec393f92ca20c2e6e65e261fc554f8851c46f263c74ca089a77
|
|
BLAKE2b-256 checksum How to use checksums |
e87839e67e6818481b3daef2ec7297529c32be3d5e715c7e066e5253d357c201
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |