================
A Django slugify application that guarantees uniqueness and handles unicode.
UUSlug = (``U``nique + ``U``nicode Slug)
Patches welcome: https://github.com/un33k/django-uuslug
Usage
=====
A. Install django-uuslug:
* _ Make sure you have python 2.6+ and can install from pypi
1. easy_install django-uuslug
2. pip install django-uuslug
3. git clone http://github.com/un33k/django-uuslug
a. cd django-uuslug
b. run python setup.py
4. wget https://github.com/un33k/django-uuslug/zipball/master
a. unzip the downloaded file
b. cd into django-uuslug-* directory
c. run python setup.py
B. Test & contribute to django-uuslug: (for developers)
* _ git clone http://github.com/un33k/django-uuslug
a. cd into django-uuslug
b. run python bootstrap.py
c. run bin/buildout -vvvvv
d. run bin/test
Unicode Test Example
=====================
from uuslug import 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-lete")
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
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 = uuslug(self.name, instance=self)
super(CoolSlug, self).save(*args, **kwargs)
Note: You can also specify the start number.
Example:
self.slug = uuslug(self.name, instance=self, start_no=2)
# the second slug should start with "-2" instead of "-1"
Test:
=====
name = "john"
c = CoolSlug.objects.create(name=name)
c.save()
self.assertEquals(c.slug, name) # slug = "john"
c1 = CoolSlug.objects.create(name=name)
c1.save()
self.assertEquals(c1.slug, name+"-1") # slug = "john-1"
c1 = CoolSlug.objects.create(name=name)
c1.save()
self.assertEquals(c1.slug, name+"-2") # slug = "john-2"
ToDo:
=====
clean up README
add more test and examples
Credits:
=========
This is inspired by a snippet from http://www.djangosnippets.org/
Improved to handle unique slugs and unicode chars and packaged for easy install.
Metadata
Release files for django-uuslug 0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-uuslug-0.8.tar.gz | 4.1 kB | Without provenance | Details for django-uuslug-0.8.tar.gz |
Release files / django-uuslug-0.8.tar.gz
| Download URL | django-uuslug-0.8.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a5ea91025e57af43ec512ea869107643f725e2215d4548eb8b33c63af0534d6
|
|
BLAKE2b-256 checksum How to use checksums |
e6b368fe22042a89b504b5331a88460d2b49cee8f02f234114820f05a3cf1080
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-uuslug 0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.