Skip to content

Commit

Permalink
Document supported versions of Django; fix Travis to test these versi…
Browse files Browse the repository at this point in the history
…ons.

Remove workarounds for unsupported, unmaintained versions of Django.

Per the 0.21 release notes, django-taggit only supports Django 1.7 and
above.

Updated docs to only refer to supported versions.

Fixes #369
  • Loading branch information
jdufresne committed Aug 25, 2016
1 parent 8db427a commit c650779
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 165 deletions.
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ ignore_errors = True
omit =
tests/*
taggit/migrations/*
taggit/south_migrations/*
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ matrix:
python: 2.7
- env: TOXENV=py27-1.9.x
python: 2.7
- env: TOXENV=py27-1.10.x
python: 2.7
- env: TOXENV=py33-1.7.x
python: 3.3
- env: TOXENV=py33-1.8.x
Expand All @@ -18,10 +20,14 @@ matrix:
python: 3.4
- env: TOXENV=py34-1.9.x
python: 3.4
- env: TOXENV=py34-1.10.x
python: 3.4
- env: TOXENV=py35-1.8.x
python: 3.5
- env: TOXENV=py35-1.9.x
python: 3.5
- env: TOXENV=py35-1.10.x
python: 3.5

install:
- pip install flake8 tox isort
Expand Down
9 changes: 0 additions & 9 deletions docs/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,3 @@ make use of the ``distinct()`` method on ``QuerySets``::

You can also filter by the slug on tags. If you're using a custom ``Tag``
model you can use this API to filter on any fields it has.

Aggregation
~~~~~~~~~~~

Unfortunately, due to a
`bug in Django <http://code.djangoproject.com/ticket/10870>`_, it is not
currently (Django < 1.6) possible to use aggregation in conjunction with ``taggit``. This is
a `documented interaction <http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#generic-relations-and-aggregation>`_
of generic relations (which ``taggit`` uses internally) and aggregates.
12 changes: 1 addition & 11 deletions docs/getting_started.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,7 @@ To get started using ``django-taggit`` simply install it with

Add ``"taggit"`` to your project's ``INSTALLED_APPS`` setting.

Run `./manage.py syncdb` or `./manage.py migrate` if using migrations.

.. note::

If you are using South you'll have to add the following setting, since
taggit uses Django migrations by default::

SOUTH_MIGRATION_MODULES = {
'taggit': 'taggit.south_migrations',
}
Run `./manage.py migrate`.

And then to any model you want tagging on do the following::

Expand All @@ -36,4 +27,3 @@ And then to any model you want tagging on do the following::
If you want ``django-taggit`` to be **CASE INSENSITIVE** when looking up existing tags, you'll have to set to ``True`` the TAGGIT_CASE_INSENSITIVE setting (by default ``False``)::

TAGGIT_CASE_INSENSITIVE = True

22 changes: 1 addition & 21 deletions docs/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,7 @@ Welcome to django-taggit's documentation!
``django-taggit`` is a reusable Django application designed to making adding
tagging to your project easy and fun.

``django-taggit`` works with Django 1.4.5+ and Python 2.7-3.X.

.. warning::

Since version 0.10.0 taggit uses South for database migrations.
This means that users who are upgrading to 0.10.0 and up will have to fake
the initial migration, like this::

python manage.py migrate taggit --fake 0001
python manage.py migrate

Since version 0.12.0 taggit uses Django migrations by default. South users
have to adjust their settings::

SOUTH_MIGRATION_MODULES = {
'taggit': 'taggit.south_migrations',
}

For more information, see `south documentation`__
``django-taggit`` works with Django 1.7+ and Python 2.7-3.X.

.. toctree::
:maxdepth: 2
Expand All @@ -41,5 +23,3 @@ Indices and tables
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

__ https://south.readthedocs.io/en/latest/
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ universal=1
# E302: expected 2 blank lines, found 1 [E302]
# E501: line too long
ignore=E501,E302
exclude = south_migrations,migrations
exclude = migrations

[isort]
forced_separate=tests,taggit
skip=migrations,.tox,south_migrations,docs
skip=migrations,.tox,docs
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 1.7',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Framework :: Django',
],
include_package_data=True,
zip_safe=False,
Expand Down
44 changes: 8 additions & 36 deletions taggit/managers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import unicode_literals

from functools import total_ordering
from operator import attrgetter

from django import VERSION
from django.conf import settings
from django.contrib.contenttypes.fields import GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.db import models, router
from django.db.models import signals
Expand Down Expand Up @@ -36,27 +38,10 @@
else:
from django.db.models.fields.related import add_lazy_relation


try:
from django.contrib.contenttypes.fields import GenericRelation
except ImportError: # django < 1.7
from django.contrib.contenttypes.generic import GenericRelation

try:
from django.db.models.query_utils import PathInfo
except ImportError: # Django < 1.8
try:
from django.db.models.related import PathInfo
except ImportError:
pass # PathInfo is not used on Django < 1.6


def _model_name(model):
if VERSION < (1, 6):
return model._meta.module_name
else:
return model._meta.model_name

from django.db.models.related import PathInfo

class TaggableRel(ManyToManyRel):
def __init__(self, field, related_name, through, to=None):
Expand All @@ -69,7 +54,7 @@ def __init__(self, field, related_name, through, to=None):
self.limit_choices_to = {}
self.symmetrical = True
self.multiple = True
self.through = None if VERSION < (1, 7) else through
self.through = through
self.field = field
self.through_fields = None

Expand Down Expand Up @@ -158,10 +143,6 @@ def get_prefetch_queryset(self, instances, queryset=None):
False,
self.prefetch_cache_name)

# Django < 1.6 uses the previous name of query_set
get_query_set = get_queryset
get_prefetch_query_set = get_prefetch_queryset

def _lookup_kwargs(self):
return self.through.lookup_kwargs(self.instance)

Expand Down Expand Up @@ -462,10 +443,7 @@ def deconstruct(self):
return name, path, args, kwargs

def contribute_to_class(self, cls, name):
if VERSION < (1, 7):
self.name = self.column = self.attname = name
else:
self.set_attributes_from_name(name)
self.set_attributes_from_name(name)
self.model = cls
self.opts = cls._meta

Expand Down Expand Up @@ -565,7 +543,7 @@ def value_from_object(self, instance):
return self.through.objects.none()

def related_query_name(self):
return _model_name(self.model)
return self.model._meta.model_name

def m2m_reverse_name(self):
return _get_field(self.through, 'tag').column
Expand Down Expand Up @@ -608,7 +586,7 @@ def extra_filters(self, pieces, pos, negate):
return [("%s__content_type__in" % prefix, cts)]

def get_extra_join_sql(self, connection, qn, lhs_alias, rhs_alias):
model_name = _model_name(self.through)
model_name = self.through._meta.model_name
if rhs_alias == '%s_%s' % (self.through._meta.app_label, model_name):
alias_to_join = rhs_alias
else:
Expand All @@ -629,7 +607,6 @@ def get_extra_join_sql(self, connection, qn, lhs_alias, rhs_alias):
params = content_type_ids
return extra_where, params

# This and all the methods till the end of class are only used in django >= 1.6
def _get_mm_case_path_info(self, direct=False):
pathinfos = []
linkfield1 = _get_field(self.through, 'content_object')
Expand Down Expand Up @@ -714,9 +691,4 @@ def _get_subclasses(model):
return subclasses


# `total_ordering` does not exist in Django 1.4, as such
# we special case this import to be py3k specific which
# is not supported by Django 1.4
if six.PY3:
from django.utils.functional import total_ordering
TaggableManager = total_ordering(TaggableManager)
TaggableManager = total_ordering(TaggableManager)
21 changes: 0 additions & 21 deletions taggit/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +0,0 @@
"""
Django migrations for taggit app
This package does not contain South migrations. South migrations can be found
in the ``south_migrations`` package.
"""

SOUTH_ERROR_MESSAGE = """\n
For South support, customize the SOUTH_MIGRATION_MODULES setting like so:
SOUTH_MIGRATION_MODULES = {
'taggit': 'taggit.south_migrations',
}
"""

# Ensure the user is not using Django 1.6 or below with South
try:
from django.db import migrations # noqa
except ImportError:
from django.core.exceptions import ImproperlyConfigured
raise ImproperlyConfigured(SOUTH_ERROR_MESSAGE)
34 changes: 5 additions & 29 deletions taggit/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals

import django
from django import VERSION
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import IntegrityError, models, transaction
from django.db.models.query import QuerySet
Expand All @@ -19,29 +19,6 @@ def unidecode(tag):
return tag


try:
from django.contrib.contenttypes.fields import GenericForeignKey
except ImportError: # django < 1.7
from django.contrib.contenttypes.generic import GenericForeignKey


try:
atomic = transaction.atomic
except AttributeError:
from contextlib import contextmanager

@contextmanager
def atomic(using=None):
sid = transaction.savepoint(using=using)
try:
yield
except IntegrityError:
transaction.savepoint_rollback(sid, using=using)
raise
else:
transaction.savepoint_commit(sid, using=using)


@python_2_unicode_compatible
class TagBase(models.Model):
name = models.CharField(verbose_name=_('Name'), unique=True, max_length=100)
Expand All @@ -66,7 +43,7 @@ def save(self, *args, **kwargs):
# Be oportunistic and try to save the tag, this should work for
# most cases ;)
try:
with atomic(using=using):
with transaction.atomic(using=using):
res = super(TagBase, self).save(*args, **kwargs)
return res
except IntegrityError:
Expand Down Expand Up @@ -225,7 +202,6 @@ class Meta:
verbose_name = _("Tagged Item")
verbose_name_plural = _("Tagged Items")
app_label = 'taggit'
if django.VERSION >= (1, 5):
index_together = [
["content_type", "object_id"],
]
index_together = [
["content_type", "object_id"],
]
14 changes: 5 additions & 9 deletions tests/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,32 @@
from .models import (CustomPKFood, DirectCustomPKFood, DirectFood, Food,
OfficialFood)

fields = None
if VERSION >= (1, 6):
fields = '__all__'


class FoodForm(forms.ModelForm):
class Meta:
model = Food
fields = fields
fields = '__all__'


class DirectFoodForm(forms.ModelForm):
class Meta:
model = DirectFood
fields = fields
fields = '__all__'


class DirectCustomPKFoodForm(forms.ModelForm):
class Meta:
model = DirectCustomPKFood
fields = fields
fields = '__all__'


class CustomPKFoodForm(forms.ModelForm):
class Meta:
model = CustomPKFood
fields = fields
fields = '__all__'


class OfficialFoodForm(forms.ModelForm):
class Meta:
model = OfficialFood
fields = fields
fields = '__all__'
Loading

0 comments on commit c650779

Please sign in to comment.