#15307: slugify should take an optional max length
-------------------------------------+-------------------------------------
Reporter: jdunck | Owner: nobody
Type: New feature | Status: closed
Component: Template system | Version: 1.2
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Design
| decision needed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by andrewbadr):
Here's a more efficient version of `slugify_max`, if anyone comes looking.
{{{
def slugify_max(text, max_length=50):
slug = slugify(text)
if len(slug) <= max_length:
return slug
trimmed_slug = slug[:max_length].rsplit('-', 1)[0]
if len(trimmed_slug) <= max_length:
return trimmed_slug
# First word is > max_length chars, so we have to break it
return slug[:max_length]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/15307#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.de676eddc635a7301f21a6a20a440083%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.