[Python-modules-commits] [django-taggit] 02/05: New upstream version 0.21.3

Michal Cihar nijel at moszumanska.debian.org
Thu Nov 17 10:36:25 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 e8dbd6b9247a9cee2e7de6f2b52b46ec5a0f9e99
Author: Michal Čihař <nijel at debian.org>
Date:   Thu Nov 17 11:20:43 2016 +0100

    New upstream version 0.21.3
---
 CHANGELOG.txt                            |  5 ++++
 PKG-INFO                                 |  2 +-
 django_taggit.egg-info/PKG-INFO          |  2 +-
 django_taggit.egg-info/SOURCES.txt       |  4 ++-
 taggit/__init__.py                       |  2 +-
 taggit/views.py                          | 47 ++++++++++++++++++++++++++------
 tests/settings.py                        |  7 +++++
 tests/templates/tests/food_tag_list.html | 10 +++++++
 tests/tests.py                           | 42 +++++++++++++++++++++++++++-
 tests/urls.py                            |  8 ++++++
 10 files changed, 116 insertions(+), 13 deletions(-)

diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index c2ec059..2b37b17 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,6 +1,11 @@
 Changelog
 =========
 
+0.21.3 (2016-10-07)
+~~~~~~~~~~~~~~~~~~~
+ * Fix list view
+  * https://github.com/alex/django-taggit/pull/444
+
 0.21.2 (2016-08-31)
 ~~~~~~~~~~~~~~~~~~~
  * Update Python version classifiers in setup.py
diff --git a/PKG-INFO b/PKG-INFO
index 544af85..57749c7 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: django-taggit
-Version: 0.21.2
+Version: 0.21.3
 Summary: django-taggit is a reusable Django application for simple tagging.
 Home-page: http://github.com/alex/django-taggit/tree/master
 Author: Alex Gaynor
diff --git a/django_taggit.egg-info/PKG-INFO b/django_taggit.egg-info/PKG-INFO
index 544af85..57749c7 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.21.2
+Version: 0.21.3
 Summary: django-taggit is a reusable Django application for simple tagging.
 Home-page: http://github.com/alex/django-taggit/tree/master
 Author: Alex Gaynor
diff --git a/django_taggit.egg-info/SOURCES.txt b/django_taggit.egg-info/SOURCES.txt
index 523dd59..76ebc25 100644
--- a/django_taggit.egg-info/SOURCES.txt
+++ b/django_taggit.egg-info/SOURCES.txt
@@ -68,5 +68,7 @@ tests/forms.py
 tests/models.py
 tests/settings.py
 tests/tests.py
+tests/urls.py
 tests/migrations/0001_initial.py
-tests/migrations/__init__.py
\ No newline at end of file
+tests/migrations/__init__.py
+tests/templates/tests/food_tag_list.html
\ No newline at end of file
diff --git a/taggit/__init__.py b/taggit/__init__.py
index 148c72b..9b368b2 100644
--- a/taggit/__init__.py
+++ b/taggit/__init__.py
@@ -1,3 +1,3 @@
-VERSION = (0, 21, 2)
+VERSION = (0, 21, 3)
 
 default_app_config = 'taggit.apps.TaggitAppConfig'
diff --git a/taggit/views.py b/taggit/views.py
index 5b6c0c4..07d4d73 100644
--- a/taggit/views.py
+++ b/taggit/views.py
@@ -10,11 +10,42 @@ from taggit.models import Tag, TaggedItem
 def tagged_object_list(request, slug, queryset, **kwargs):
     if callable(queryset):
         queryset = queryset()
-    tag = get_object_or_404(Tag, slug=slug)
-    qs = queryset.filter(pk__in=TaggedItem.objects.filter(
-        tag=tag, content_type=ContentType.objects.get_for_model(queryset.model)
-    ).values_list("object_id", flat=True))
-    if "extra_context" not in kwargs:
-        kwargs["extra_context"] = {}
-    kwargs["extra_context"]["tag"] = tag
-    return ListView.as_view(request, qs, **kwargs)
+    queryset_model = ContentType.objects.get_for_model(queryset.model)
+    kwargs["slug"] = slug
+    tag_list_view = type(
+        str('TagListView'),
+        (TagListMixin, ListView),
+        {
+            'model': queryset_model,
+            'queryset': queryset
+        }
+    )
+    return tag_list_view.as_view()(request, **kwargs)
+
+
+class TagListMixin(object):
+    tag_suffix = '_tag'
+
+    def dispatch(self, request, *args, **kwargs):
+        slug = kwargs.pop('slug')
+        self.tag = get_object_or_404(Tag, slug=slug)
+        return super(TagListMixin, self).dispatch(request, *args, **kwargs)
+
+    def get_queryset(self, **kwargs):
+        qs = super(TagListMixin, self).get_queryset(**kwargs)
+        return qs.filter(
+            pk__in=TaggedItem.objects.filter(
+                tag=self.tag, content_type=ContentType.objects.get_for_model(qs.model)
+            ).values_list("object_id", flat=True))
+
+    def get_template_names(self):
+        if self.tag_suffix:
+            self.template_name_suffix = self.tag_suffix + self.template_name_suffix
+        return super(TagListMixin, self).get_template_names()
+
+    def get_context_data(self, **kwargs):
+        context = super(TagListMixin, self).get_context_data(**kwargs)
+        if "extra_context" not in context:
+            context["extra_context"] = {}
+        context["extra_context"]["tag"] = self.tag
+        return context
diff --git a/tests/settings.py b/tests/settings.py
index 68fdfe3..544f299 100644
--- a/tests/settings.py
+++ b/tests/settings.py
@@ -11,6 +11,13 @@ INSTALLED_APPS = [
     'tests',
 ]
 
+TEMPLATES = [
+    {
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
+        'APP_DIRS': True,
+    }
+]
+
 MIDDLEWARE_CLASSES = []
 
 SECRET_KEY = 'secretkey'
diff --git a/tests/templates/tests/food_tag_list.html b/tests/templates/tests/food_tag_list.html
new file mode 100644
index 0000000..566549b
--- /dev/null
+++ b/tests/templates/tests/food_tag_list.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/tests/tests.py b/tests/tests.py
index eae8a4d..01109ab 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -12,7 +12,7 @@ from django.core import serializers
 from django.core.exceptions import ImproperlyConfigured, ValidationError
 from django.core.management import call_command
 from django.db import connection, models
-from django.test import TestCase, TransactionTestCase
+from django.test import RequestFactory, TestCase, TransactionTestCase
 from django.test.utils import override_settings
 from django.utils.encoding import force_text
 
@@ -28,6 +28,7 @@ from .models import (Article, Child, CustomManager, CustomPKFood,
 
 from taggit.managers import TaggableManager, _TaggableManager
 from taggit.models import Tag, TaggedItem
+from taggit.views import tagged_object_list, TagListMixin
 from taggit.utils import (_related_model, _remote_field, edit_string_for_tags,
                           parse_tags)
 
@@ -958,3 +959,42 @@ class DjangoCheckTests(UnitTestCase):
 
     def test_django_checks(self):
         call_command('check', tag=['models'])
+
+
+from django.views.generic.list import ListView
+
+
+class FoodTagListView(TagListMixin, ListView):
+    model = Food
+
+
+ at override_settings(ROOT_URLCONF='tests.urls')
+class TagListViewTests(BaseTaggingTestCase, TestCase):
+    model = Food
+
+    def setUp(self):
+        self.factory = RequestFactory()
+        self.slug = 'green'
+        self.apple = self.model.objects.create(name='apple')
+        self.apple.tags.add(self.slug)
+        self.strawberry = self.model.objects.create(name='strawberry')
+        self.strawberry.tags.add('red')
+
+    def test_url_request_returns_view(self):
+        request = self.factory.get('/food/tags/{}/'.format(self.slug))
+        queryset = self.model.objects.all()
+        response = tagged_object_list(request, self.slug, queryset)
+        self.assertEqual(response.status_code, 200)
+        self.assertIn(self.apple, response.context_data['object_list'])
+        self.assertNotIn(self.strawberry, response.context_data['object_list'])
+        self.assertEqual(
+            self.apple.tags.first(),
+            response.context_data['extra_context']['tag']
+        )
+
+    def test_list_view_returns_single(self):
+        response = self.client.get('/food/tags/{}/'.format(self.slug))
+        self.assertEqual(response.status_code, 200)
+        self.assertIn(self.apple, response.context_data['object_list'])
+        self.assertNotIn(self.strawberry, response.context_data['object_list'])
+
diff --git a/tests/urls.py b/tests/urls.py
new file mode 100644
index 0000000..6fe427f
--- /dev/null
+++ b/tests/urls.py
@@ -0,0 +1,8 @@
+from django.conf.urls import url
+
+from .tests import FoodTagListView
+
+urlpatterns = [
+    url(r'^food/tags/(?P<slug>[a-z0-9_-]+)/$', FoodTagListView.as_view(),
+        name='food-tag-list'),
+]

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/django-taggit.git



More information about the Python-modules-commits mailing list