[Python-modules-commits] [django-taggit] 01/03: Imported Upstream version 0.18.0
Michal Cihar
nijel at moszumanska.debian.org
Mon Jan 25 14:47:46 UTC 2016
This is an automated email from the git hooks/post-receive script.
nijel pushed a commit to branch master
in repository django-taggit.
commit c0fc118b08af19fa3daa0f001bc9d870bb416c6d
Author: Michal Čihař <nijel at debian.org>
Date: Mon Jan 25 15:45:31 2016 +0100
Imported Upstream version 0.18.0
---
CHANGELOG.txt | 7 +++++++
PKG-INFO | 3 +--
django_taggit.egg-info/PKG-INFO | 3 +--
django_taggit.egg-info/SOURCES.txt | 1 +
docs/custom_tagging.txt | 38 ++++++++++++++++++++++++++++++++++++--
setup.py | 1 -
taggit/__init__.py | 2 +-
taggit/managers.py | 15 +++++++--------
taggit/models.py | 3 ++-
taggit/utils.py | 34 ++++++++++++++++++++++++++++++++--
tests/custom_parser.py | 5 +++++
tests/tests.py | 15 +++++++++++++++
tox.ini | 18 ------------------
13 files changed, 108 insertions(+), 37 deletions(-)
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 5d9a65c..01cb0bc 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,6 +1,13 @@
Changelog
=========
+0.18.0 (2016-01-18)
+~~~~~~~~~~~~~~~~~~~
+ * Add option to override default tag string parsing
+ * https://github.com/alex/django-taggit/pull/232
+ * Drop support for Python 2.6
+ * https://github.com/alex/django-taggit/pull/373
+
0.17.6 (2015-12-09)
~~~~~~~~~~~~~~~~~~~
* Silence Django 1.9 warning
diff --git a/PKG-INFO b/PKG-INFO
index f194e4f..f48cccb 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: django-taggit
-Version: 0.17.6
+Version: 0.18.0
Summary: django-taggit is a reusable Django application for simple tagging.
Home-page: http://github.com/alex/django-taggit/tree/master
Author: Alex Gaynor
@@ -54,7 +54,6 @@ Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python
-Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.2
Classifier: Programming Language :: Python :: 3.3
diff --git a/django_taggit.egg-info/PKG-INFO b/django_taggit.egg-info/PKG-INFO
index f194e4f..f48cccb 100644
--- a/django_taggit.egg-info/PKG-INFO
+++ b/django_taggit.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: django-taggit
-Version: 0.17.6
+Version: 0.18.0
Summary: django-taggit is a reusable Django application for simple tagging.
Home-page: http://github.com/alex/django-taggit/tree/master
Author: Alex Gaynor
@@ -54,7 +54,6 @@ Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python
-Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.2
Classifier: Programming Language :: Python :: 3.3
diff --git a/django_taggit.egg-info/SOURCES.txt b/django_taggit.egg-info/SOURCES.txt
index 559aef3..e1e936c 100644
--- a/django_taggit.egg-info/SOURCES.txt
+++ b/django_taggit.egg-info/SOURCES.txt
@@ -57,6 +57,7 @@ taggit/south_migrations/0001_initial.py
taggit/south_migrations/0002_unique_tagnames.py
taggit/south_migrations/__init__.py
tests/__init__.py
+tests/custom_parser.py
tests/forms.py
tests/models.py
tests/tests.py
diff --git a/docs/custom_tagging.txt b/docs/custom_tagging.txt
index 87ff286..29d4b75 100644
--- a/docs/custom_tagging.txt
+++ b/docs/custom_tagging.txt
@@ -1,6 +1,8 @@
-Using a Custom Tag or Through Model
-===================================
+Customizing taggit
+==================
+Using a Custom Tag or Through Model
+-----------------------------------
By default ``django-taggit`` uses a "through model" with a
``GenericForeignKey`` on it, that has another ``ForeignKey`` to an included
``Tag`` model. However, there are some cases where this isn't desirable, for
@@ -165,3 +167,35 @@ model named ``"tag"``:
signifies how many times the slug for this tag has been attempted to be
calculated, it is ``None`` on the first time, and the counting begins
at ``1`` thereafter.
+
+
+Using a custom tag string parser
+--------------------------------
+By default ``django-taggit`` uses :func:`taggit.utils._parse_tags` which
+accepts a string which may contain one or more tags and returns a list of tag
+names. This parser is quite intelligent and can handle a number of edge cases;
+however, you may wish to provide your own parser for various reasons (e.g. you
+can do some preprocessing on the tags so that they are converted to lowercase,
+reject certain tags, disallow certain characters, split only on commas rather
+than commas and whitespace, etc.). To provide your own parser, write a
+function that takes a tag string and returns a list of tag names. For example,
+a simple function to split on comma and convert to lowercase::
+
+ def comma_splitter(tag_string):
+ return [t.strip().lower() for t in tag_string.split(',') if t.strip()]
+
+You need to tell ``taggit`` to use this function instead of the default by
+adding a new setting, ``TAGGIT_TAGS_FROM_STRING`` and providing it with the
+dotted path to your function. Likewise, you can provide a function to convert
+a list of tags to a string representation and use the setting
+``TAGGIT_STRING_FROM_TAGS`` to override the default value (which is
+:func:`taggit.utils._edit_string_for_tags`)::
+
+ def comma_joiner(tag_string):
+ return ', '.join(t.name for t in tags)
+
+If the functions above were defined in a module, ``appname.utils``, then your
+project settings.py file should contain the following::
+
+ TAGGIT_TAGS_FROM_STRING = 'appname.utils.comma_splitter'
+ TAGGIT_STRING_FROM_TAGS = 'appname.utils.comma_joiner'
diff --git a/setup.py b/setup.py
index cb953af..da115ff 100644
--- a/setup.py
+++ b/setup.py
@@ -29,7 +29,6 @@ setup(
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python',
- 'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
diff --git a/taggit/__init__.py b/taggit/__init__.py
index 6910041..15f904d 100644
--- a/taggit/__init__.py
+++ b/taggit/__init__.py
@@ -1 +1 @@
-VERSION = (0, 17, 6)
+VERSION = (0, 18, 0)
diff --git a/taggit/managers.py b/taggit/managers.py
index bc6cba1..3d78d8f 100644
--- a/taggit/managers.py
+++ b/taggit/managers.py
@@ -9,6 +9,13 @@ from django.db import models, router
from django.db.models.fields import Field
from django.db.models.fields.related import (add_lazy_relation, ManyToManyRel,
OneToOneRel, RelatedField)
+from django.utils import six
+from django.utils.text import capfirst
+from django.utils.translation import ugettext_lazy as _
+
+from taggit.forms import TagField
+from taggit.models import CommonGenericTaggedItemBase, TaggedItem
+from taggit.utils import _get_field, require_instance_manager
if VERSION < (1, 8):
# related.py was removed in Django 1.8
@@ -21,14 +28,6 @@ if VERSION < (1, 8):
else:
RelatedObject = None
-from django.utils import six
-from django.utils.text import capfirst
-from django.utils.translation import ugettext_lazy as _
-
-from taggit.forms import TagField
-from taggit.models import CommonGenericTaggedItemBase, TaggedItem
-from taggit.utils import _get_field, require_instance_manager
-
try:
from django.contrib.contenttypes.fields import GenericRelation
except ImportError: # django < 1.7
diff --git a/taggit/models.py b/taggit/models.py
index 1378784..cd0d147 100644
--- a/taggit/models.py
+++ b/taggit/models.py
@@ -14,7 +14,8 @@ from taggit.utils import _get_field
try:
from unidecode import unidecode
except ImportError:
- unidecode = lambda tag: tag
+ def unidecode(tag):
+ return tag
try:
diff --git a/taggit/utils.py b/taggit/utils.py
index 775d16a..520ac86 100644
--- a/taggit/utils.py
+++ b/taggit/utils.py
@@ -1,6 +1,9 @@
from __future__ import unicode_literals
+from importlib import import_module
+
from django import VERSION
+from django.conf import settings
from django.utils import six
from django.utils.encoding import force_text
from django.utils.functional import wraps
@@ -13,7 +16,7 @@ def _get_field(model, name):
return model._meta.get_field(name)
-def parse_tags(tagstring):
+def _parse_tags(tagstring):
"""
Parses tag input, with multiple word input being activated and
delineated by commas and double quotes. Quotes take precedence, so
@@ -102,7 +105,7 @@ def split_strip(string, delimiter=','):
return [w for w in words if w]
-def edit_string_for_tags(tags):
+def _edit_string_for_tags(tags):
"""
Given list of ``Tag`` instances, creates a string representation of
the list suitable for editing by the user, such that submitting the
@@ -135,3 +138,30 @@ def require_instance_manager(func):
raise TypeError("Can't call %s with a non-instance manager" % func.__name__)
return func(self, *args, **kwargs)
return inner
+
+
+def get_func(key, default):
+ func_path = getattr(settings, key, default)
+ try:
+ return get_func.cache[func_path]
+ except KeyError:
+ mod_path, func_name = func_path.rsplit('.', 1)
+ func = getattr(import_module(mod_path), func_name)
+ get_func.cache[func_path] = func
+ return func
+
+# Create a cache as an attribute on the function that way it can cache the
+# imported callable rather than re-importing it each time `parse_tags` or
+# `edit_string_for_tags` needs the callable.
+get_func.cache = {}
+
+
+def parse_tags(tagstring):
+ func = get_func('TAGGIT_TAGS_FROM_STRING', 'taggit.utils._parse_tags')
+ return func(tagstring)
+
+
+def edit_string_for_tags(tags):
+ func = get_func('TAGGIT_STRING_FROM_TAGS',
+ 'taggit.utils._edit_string_for_tags')
+ return func(tags)
diff --git a/tests/custom_parser.py b/tests/custom_parser.py
new file mode 100644
index 0000000..5b2e95b
--- /dev/null
+++ b/tests/custom_parser.py
@@ -0,0 +1,5 @@
+def comma_splitter(tag_string):
+ return [t.strip() for t in tag_string.split(',') if t.strip()]
+
+def comma_joiner(tags):
+ return ', '.join(t.name for t in tags)
diff --git a/tests/tests.py b/tests/tests.py
index de60f9a..f57535d 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -10,6 +10,7 @@ from django.core.management import call_command
from django.db import connection, models
from django.test import TestCase, TransactionTestCase
from django.test.utils import override_settings
+from django.utils import six
from django.utils.encoding import force_text
from .forms import (CustomPKFoodForm, DirectCustomPKFoodForm, DirectFoodForm,
@@ -621,6 +622,20 @@ class TagStringParseTestCase(UnitTestCase):
self.assertEqual(edit_string_for_tags([plain, comma]), '"com,ma", plain')
self.assertEqual(edit_string_for_tags([comma, spaces]), '"com,ma", "spa ces"')
+ @override_settings(TAGGIT_TAGS_FROM_STRING='tests.custom_parser.comma_splitter')
+ def test_custom_comma_splitter(self):
+ self.assertEqual(parse_tags(' Cued Speech '), ['Cued Speech'])
+ self.assertEqual(parse_tags(' ,Cued Speech, '), ['Cued Speech'])
+ self.assertEqual(parse_tags('Cued Speech'), ['Cued Speech'])
+ self.assertEqual(parse_tags('Cued Speech, dictionary'),
+ ['Cued Speech', 'dictionary'])
+
+ @override_settings(TAGGIT_STRING_FROM_TAGS='tests.custom_parser.comma_joiner')
+ def test_custom_comma_joiner(self):
+ a = Tag.objects.create(name='Cued Speech')
+ b = Tag.objects.create(name='transliterator')
+ self.assertEqual(edit_string_for_tags([a, b]), 'Cued Speech, transliterator')
+
@skipIf(django.VERSION < (1, 7), "not relevant for Django < 1.7")
class DeconstructTestCase(UnitTestCase):
diff --git a/tox.ini b/tox.ini
index 123c3f1..7dd3b45 100644
--- a/tox.ini
+++ b/tox.ini
@@ -20,24 +20,6 @@ commands =
python ./runtests.py {posargs}
-[testenv:py26-1.4.x]
-basepython = python2.6
-deps =
- {[testenv]deps}
- {[testenv]deps14}
-
-[testenv:py26-1.5.x]
-basepython = python2.6
-deps =
- {[testenv]deps}
- {[testenv]deps15}
-
-[testenv:py26-1.6.x]
-basepython = python2.6
-deps =
- {[testenv]deps}
- {[testenv]deps16}
-
[testenv:py27-1.4.x]
basepython = python2.7
deps =
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/django-taggit.git
More information about the Python-modules-commits
mailing list