From ee42fd962c5abc7ed18f729ded42ee1f56397678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartolom=C3=A9=20S=C3=A1nchez=20Salado?= Date: Sun, 12 Dec 2021 18:13:23 +0100 Subject: [PATCH 1/4] Use smart_str instead of deprecated smart_text Django function --- tagging/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tagging/models.py b/tagging/models.py index 02550eec..d16a61ec 100644 --- a/tagging/models.py +++ b/tagging/models.py @@ -5,7 +5,7 @@ from django.contrib.contenttypes.models import ContentType from django.db import connection from django.db import models -from django.utils.encoding import smart_text +from django.utils.encoding import smart_str from django.utils.translation import gettext_lazy as _ from tagging import settings @@ -519,4 +519,4 @@ class Meta: verbose_name_plural = _('tagged items') def __str__(self): - return '%s [%s]' % (smart_text(self.object), smart_text(self.tag)) + return '%s [%s]' % (smart_str(self.object), smart_str(self.tag)) From 9c47683ec67ad2fbf82f1dce6384b156f64f55bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartolom=C3=A9=20S=C3=A1nchez=20Salado?= Date: Sun, 12 Dec 2021 18:14:35 +0100 Subject: [PATCH 2/4] Use re_path instead of deprecated url Django function --- tagging/tests/urls.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tagging/tests/urls.py b/tagging/tests/urls.py index aa127d5f..7db3e7e1 100644 --- a/tagging/tests/urls.py +++ b/tagging/tests/urls.py @@ -1,5 +1,5 @@ """Test urls for tagging.""" -from django.conf.urls import url +from django.urls import re_path from tagging.tests.models import Article from tagging.views import TaggedObjectList @@ -11,10 +11,10 @@ class StaticTaggedObjectList(TaggedObjectList): urlpatterns = [ - url(r'^static/$', StaticTaggedObjectList.as_view()), - url(r'^static/related/$', StaticTaggedObjectList.as_view( + re_path(r'^static/$', StaticTaggedObjectList.as_view()), + re_path(r'^static/related/$', StaticTaggedObjectList.as_view( related_tags=True)), - url(r'^no-tag/$', TaggedObjectList.as_view(model=Article)), - url(r'^no-query-no-model/$', TaggedObjectList.as_view()), - url(r'^(?P[^/]+(?u))/$', TaggedObjectList.as_view(model=Article)), + re_path(r'^no-tag/$', TaggedObjectList.as_view(model=Article)), + re_path(r'^no-query-no-model/$', TaggedObjectList.as_view()), + re_path(r'^(?P[^/]+(?u))/$', TaggedObjectList.as_view(model=Article)), ] From 6550f6c04c0d2d67049e8cc3263623811207c66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartolom=C3=A9=20S=C3=A1nchez=20Salado?= Date: Sun, 12 Dec 2021 18:26:03 +0100 Subject: [PATCH 3/4] Add support for Django 4 compatibility --- .travis.yml | 4 ++++ tagging/models.py | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6a8073df..1b79bc79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: python python: - 3.7 - 3.8 + - 3.9 services: - postgresql - mysql @@ -15,6 +16,9 @@ env: - DJANGO=3.0 DATABASE_ENGINE=sqlite - DJANGO=3.0 DATABASE_ENGINE=postgres - DJANGO=3.0 DATABASE_ENGINE=mysql + - DJANGO=4.0 DATABASE_ENGINE=sqlite + - DJANGO=4.0 DATABASE_ENGINE=postgres + - DJANGO=4.0 DATABASE_ENGINE=mysql install: - pip install -U setuptools zc.buildout diff --git a/tagging/models.py b/tagging/models.py index d16a61ec..50995c8d 100644 --- a/tagging/models.py +++ b/tagging/models.py @@ -5,6 +5,7 @@ from django.contrib.contenttypes.models import ContentType from django.db import connection from django.db import models +from django.db.models.query_utils import Q from django.utils.encoding import smart_str from django.utils.translation import gettext_lazy as _ @@ -155,8 +156,9 @@ def usage_for_model(self, model, counts=False, min_count=None, filters = {} queryset = model._default_manager.filter() - for f in filters.items(): - queryset.query.add_filter(f) + for k, v in filters.items(): + # Add support for both Django 4 and inferior versions + queryset.query.add_q(Q((k, v))) usage = self.usage_for_queryset(queryset, counts, min_count) return usage From e7ea893e5d75bf5224ac21b21d8770d211016736 Mon Sep 17 00:00:00 2001 From: Nikolas Nyby Date: Fri, 12 Apr 2024 15:37:26 -0400 Subject: [PATCH 4/4] Unofficial version 0.5.1 Adding django 4.2 support. --- .gitignore | 161 ++++++++++++++++++++++++++++++++++++++++- CHANGELOG.txt | 5 ++ tagging/__init__.py | 2 +- tagging/tests/tests.py | 6 +- 4 files changed, 169 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index accb26a4..68bc17f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,160 @@ -docs/_build +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 6a104b4c..ea649837 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -2,6 +2,11 @@ Django Tagging Changelog ======================== +Version 0.5.1, 6th April 2024: +------------------------------ + +* Add Django 4.2 support + Version 0.5.0, 6th March 2020: ------------------------------ diff --git a/tagging/__init__.py b/tagging/__init__.py index 54d89f9f..1bfb9fe3 100644 --- a/tagging/__init__.py +++ b/tagging/__init__.py @@ -1,7 +1,7 @@ """ Django-tagging """ -__version__ = '0.5.0' +__version__ = '0.5.1' __license__ = 'BSD License' __author__ = 'Jonathan Buchanan' diff --git a/tagging/tests/tests.py b/tagging/tests/tests.py index 57d8bca9..ef4e1808 100644 --- a/tagging/tests/tests.py +++ b/tagging/tests/tests.py @@ -1139,7 +1139,7 @@ def test_tag_d_validation(self): def test_tag_get_from_model(self): FormTest.objects.create(tags='test3 test2 test1') FormTest.objects.create(tags='toto titi') - self.assertEquals(FormTest.tags, 'test1 test2 test3 titi toto') + self.assertEqual(FormTest.tags, 'test1 test2 test3 titi toto') ######### @@ -1194,7 +1194,7 @@ def get_view(self, url, queries=1, code=200, template='tests/article_list.html'): with self.assertNumQueries(queries): response = self.client.get(url) - self.assertEquals(response.status_code, code) + self.assertEqual(response.status_code, code) if code == 200: self.assertTrue(isinstance(response.context['tag'], Tag)) @@ -1214,7 +1214,7 @@ def test_view_dynamic(self): def test_view_related(self): response = self.get_view('/static/related/', queries=2, expected_items=2) - self.assertEquals(len(response.context['related_tags']), 2) + self.assertEqual(len(response.context['related_tags']), 2) def test_view_no_queryset_no_model(self): self.assertRaises(ImproperlyConfigured, self.get_view,