mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
Allow the setting of a SLUG_TRANSLITERATOR to convert non-ASCII characters to ASCII characters.
This commit is contained in:
parent
65ef584cf4
commit
96a3f61928
3 changed files with 21 additions and 4 deletions
|
|
@ -14,7 +14,7 @@ from mptt.fields import TreeForeignKey
|
|||
from mptt.managers import TreeManager
|
||||
|
||||
from .editor.tree_editor import TreeEditor
|
||||
from .settings import ALLOW_SLUG_CHANGE
|
||||
from .settings import ALLOW_SLUG_CHANGE, SLUG_TRANSLITERATOR
|
||||
|
||||
class CategoryManager(models.Manager):
|
||||
"""
|
||||
|
|
@ -51,7 +51,7 @@ class CategoryBase(MPTTModel):
|
|||
decendants remain active.
|
||||
"""
|
||||
if not self.slug:
|
||||
self.slug = slugify(self.name)[:50]
|
||||
self.slug = slugify(SLUG_TRANSLITERATOR(self.name))[:50]
|
||||
|
||||
super(CategoryBase, self).save(*args, **kwargs)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
from django.core.management.base import BaseCommand, CommandError
|
||||
from categories.models import Category
|
||||
from django.template.defaultfilters import slugify
|
||||
from django.db import transaction
|
||||
|
||||
from categories.models import Category
|
||||
from categories.settings import SLUG_TRANSLITERATOR
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""Import category trees from a file."""
|
||||
|
||||
|
|
@ -30,7 +32,7 @@ class Command(BaseCommand):
|
|||
"""
|
||||
cat = Category(
|
||||
name=string.strip(),
|
||||
slug=slugify(string.strip())[:49],
|
||||
slug=slugify(SLUG_TRANSLITERATOR(string.strip()))[:49],
|
||||
#parent=parent,
|
||||
order=order
|
||||
)
|
||||
|
|
|
|||
|
|
@ -12,10 +12,25 @@ DEFAULT_SETTINGS = {
|
|||
'THUMBNAIL_UPLOAD_PATH': 'uploads/categories/thumbnails',
|
||||
'THUMBNAIL_STORAGE': settings.DEFAULT_FILE_STORAGE,
|
||||
'JAVASCRIPT_URL': getattr(settings, 'STATIC_URL', settings.MEDIA_URL) + 'js/',
|
||||
'SLUG_TRANSLITERATOR': '',
|
||||
}
|
||||
|
||||
DEFAULT_SETTINGS.update(getattr(settings, 'CATEGORIES_SETTINGS', {}))
|
||||
|
||||
if DEFAULT_SETTINGS['SLUG_TRANSLITERATOR']:
|
||||
if callable(DEFAULT_SETTINGS['SLUG_TRANSLITERATOR']):
|
||||
pass
|
||||
elif isinstance(DEFAULT_SETTINGS['SLUG_TRANSLITERATOR'], basestring):
|
||||
from django.utils.importlib import import_module
|
||||
bits = DEFAULT_SETTINGS['SLUG_TRANSLITERATOR'].split(".")
|
||||
module = import_module(".".join(bits[:-1]))
|
||||
DEFAULT_SETTINGS['SLUG_TRANSLITERATOR'] = getattr(module, bits[-1])
|
||||
else:
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
raise ImproperlyConfigured("SLUG_TRANSLITERATOR must be a callable or a string.")
|
||||
else:
|
||||
DEFAULT_SETTINGS['SLUG_TRANSLITERATOR'] = lambda x: x
|
||||
|
||||
ERR_MSG = "settings.%s is deprecated; use settings.CATEGORIES_SETTINGS instead."
|
||||
|
||||
if hasattr(settings, 'CATEGORIES_ALLOW_SLUG_CHANGE'):
|
||||
|
|
|
|||
Loading…
Reference in a new issue