jazzband / django-taggit

Simple tagging for django
https://django-taggit.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.34k stars 623 forks source link

Add a setting for default slugify function #72

Closed gnotaras closed 10 years ago

gnotaras commented 13 years ago

The slugify filter of django is very poor when it deals with languages other than English. On the other hand, there is much work involved in order to override the default Tag.slugify() method in your app.

It would be a lot more convenient if we could set the default slugify function using a setting, eg:

TAGGIT_DEFAULT_SLUGIFY_FUNCTION = 'django.template.defaultfilters.slugify'

Moreover, it would be perfect if you used the unidecode module by default instead of the poor django filter, which is only useful for English.

Thanks.

gnotaras commented 13 years ago

Just noticed that django has all the required code to easily implement this:

settings.py

TAGGIT_DEFAULT_SLUGIFY_FUNCTION = 'django.template.defaultfilters.slugify'

models.py

from django.core.urlresolvers import get_callable
from taggit import settings # Or wherever you keep the defaults
default_slugify = get_callable(settings.TAGGIT_DEFAULT_SLUGIFY_FUNCTION)
panosl commented 12 years ago

Good idea George, currently it's kind of hassle to go through all the proxy/subclass stuff.

troygrosfield commented 10 years ago

+1 for this change. Currently, if you try and tag an object with different cases (i.e. "Hello" and "hello"), it uses an "_#" as the separater which gives you a url that looks like:

/tags/hello

and

/tags/hello_1

Tags with underscores, IMHO, are quite ugly and are not a recommended best practice by google [1]:

We recommend that you use hyphens (-) instead of underscores (_) in your URLs.

Instead if would be great to define the slugifier method as mentioned above or change the models slugify method to instead be:

    def slugify(self, tag, i=None):
        slug = default_slugify(tag)
        if i is not None:
            slug += "-%d" % i
        return slug

[1] https://support.google.com/webmasters/answer/76329?hl=en

MikeVL commented 10 years ago

In my fork https://github.com/alex/django-taggit/pull/188 you can define slugify function via setting AUTOSLUG_SLUGIFY_FUNCTION = '...'

apollo13 commented 10 years ago

Closing in favor of #188