Skip to content

Commit

Permalink
Merge pull request svetlyak40wt#1 from svetlyak40wt/master
Browse files Browse the repository at this point in the history
latest
  • Loading branch information
pombredanne committed Nov 12, 2012
2 parents 62d7005 + 5b94e0f commit f185bf2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This application is based on the original code, written by:
Enhanced by:
Alexander Artemenko <[email protected]>
Antti Kaihola <[email protected]>
GW [http://gw.tnode.com/] <[email protected]>

Sources
-------
Expand Down
15 changes: 15 additions & 0 deletions docs/overview.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------

Expand All @@ -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
=======================
Expand Down
10 changes: 9 additions & 1 deletion tagging/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -43,4 +49,6 @@ def _tag_name(synonym):

admin.site.register(Synonym,
list_display = ('name', _tag_name),
search_fields = ('name',),
)

4 changes: 2 additions & 2 deletions tagging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions tagging/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 4 additions & 0 deletions tagging/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit f185bf2

Please sign in to comment.