diff --git a/README.txt b/README.txt index ea3c7f0..74774e4 100644 --- a/README.txt +++ b/README.txt @@ -18,6 +18,7 @@ This application is based on the original code, written by: Enhanced by: Alexander Artemenko Antti Kaihola + GW [http://gw.tnode.com/] Sources ------- diff --git a/docs/overview.txt b/docs/overview.txt index 0fc65be..06787cb 100644 --- a/docs/overview.txt +++ b/docs/overview.txt @@ -112,6 +112,14 @@ Default: ``False`` A boolean that turns on/off forcing of all tag names to lowercase before they are saved to the database. +FORCE_TAG_DELIMITER +------------------- + +Default: ``None`` + +Force a string to be used as a delimiter for separating tags or None for default +behavour. + MAX_TAG_LENGTH -------------- @@ -121,6 +129,13 @@ An integer which specifies the maximum length which any tag is allowed to have. This is used for validation in the ``django.contrib.admin`` application and in any forms automatically generated using ``ModelForm``. +MULTILINGUAL_TAGS +----------------- + +Default: ``False`` + +Whether to use multilingual tags. + Registering your models ======================= diff --git a/tagging/admin.py b/tagging/admin.py index fa22656..213bcf0 100644 --- a/tagging/admin.py +++ b/tagging/admin.py @@ -18,15 +18,21 @@ def _synonyms(tag): return ', '.join(s.name for s in tag.synonyms.all()) _synonyms.short_description = _('synonyms') + def _translations(tag): + return ', '.join(s.name for s in tag.translations.all()) + _translations.short_description = _('translations') + class TagAdmin(multilingual.ModelAdmin): form = TagAdminForm - list_display = (_name, _synonyms) + list_display = (_name, _synonyms, _translations) + search_fields = ('name', 'synonyms__name', 'translations__name') _synonym_tag_name = 'name_any' else: class TagAdmin(admin.ModelAdmin): form = TagAdminForm list_display = ('name',) + search_fields = ('name', 'synonyms__name') _synonym_tag_name = 'name' @@ -43,4 +49,6 @@ def _tag_name(synonym): admin.site.register(Synonym, list_display = ('name', _tag_name), + search_fields = ('name',), ) + diff --git a/tagging/models.py b/tagging/models.py index 61efebc..9696ccb 100644 --- a/tagging/models.py +++ b/tagging/models.py @@ -53,7 +53,7 @@ def update_tags(self, obj, tag_names): object_id=obj.pk, tag__in=tags_for_removal).delete() # Add new tags - current_tag_names = [tag.name_any for tag in current_tags] + current_tag_names = [tag.name or tag.name_any for tag in current_tags] for tag_name in updated_tag_names: if tag_name not in current_tag_names: tag, created = self.get_or_create(name=tag_name) @@ -625,7 +625,7 @@ def __unicode__(self): def _updateLinkedObjects(self, remove_this = False): from tagging.fields import TagField - object_tags = [ tag.name_any \ + object_tags = [ tag.name or tag.name_any \ for tag in Tag.objects.get_for_object(self.object) \ if not remove_this or tag.id != self.tag_id ] tags_as_string = ', '.join(object_tags) diff --git a/tagging/settings.py b/tagging/settings.py index 2762d0b..8b16a85 100644 --- a/tagging/settings.py +++ b/tagging/settings.py @@ -5,12 +5,17 @@ """ from django.conf import settings -# The maximum length of a tag's name. -MAX_TAG_LENGTH = getattr(settings, 'MAX_TAG_LENGTH', 50) - # Whether to force all tags to lowercase before they are saved to the # database. FORCE_LOWERCASE_TAGS = getattr(settings, 'FORCE_LOWERCASE_TAGS', False) + +# Force a delimiter string for tags. +FORCE_TAG_DELIMITER = getattr(settings, 'FORCE_TAG_DELIMITER', None) + +# The maximum length of a tag's name. +MAX_TAG_LENGTH = getattr(settings, 'MAX_TAG_LENGTH', 50) + +# Whether to use multilingual tags MULTILINGUAL_TAGS = getattr(settings, 'MULTILINGUAL_TAGS', False) if MULTILINGUAL_TAGS: DEFAULT_LANGUAGE = getattr(settings, 'DEFAULT_LANGUAGE') diff --git a/tagging/utils.py b/tagging/utils.py index 7d50360..76550dd 100644 --- a/tagging/utils.py +++ b/tagging/utils.py @@ -11,6 +11,8 @@ from django.utils.encoding import force_unicode from django.utils.translation import ugettext as _ +from tagging import settings + # Python 2.3 compatibility try: set @@ -134,6 +136,8 @@ def edit_string_for_tags(tags): glue = u', ' else: glue = u' ' + if settings.FORCE_TAG_DELIMITER is not None: + glue = settings.FORCE_TAG_DELIMITER return glue.join(names) def get_queryset_and_model(queryset_or_model):