From 47c859e98bd7694b9563a90b0d0e535ce0750350 Mon Sep 17 00:00:00 2001 From: Marcus Furlong Date: Sun, 5 Jan 2025 15:18:06 -0500 Subject: [PATCH] switch from obsolete django-tagging to django-taggit --- debian/control | 3 ++- .../0004_remove_host_tags_host_tags.py | 24 +++++++++++++++++++ hosts/models.py | 4 ++-- hosts/templates/hosts/host_delete.html | 4 +--- hosts/templates/hosts/host_detail.html | 4 +--- hosts/views.py | 12 +++++----- patchman/settings.py | 3 +++ requirements.txt | 1 + sbin/patchman | 2 +- setup.cfg | 1 + 10 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 hosts/migrations/0004_remove_host_tags_host_tags.py diff --git a/debian/control b/debian/control index ca0792ce..7bc1fd20 100644 --- a/debian/control +++ b/debian/control @@ -18,7 +18,8 @@ Depends: ${misc:Depends}, python3 (>= 3.10), python3-django (>= 3.2), python3-djangorestframework, python3-django-filters, python3-debian, python3-rpm, python3-progressbar, python3-lxml, python3-defusedxml, python3-requests, python3-colorama, python3-magic, python3-humanize, - python3-pip, python3-pymemcache, memcached, libapache2-mod-wsgi-py3, apache2 + python3-pip, python3-pymemcache, memcached, libapache2-mod-wsgi-py3, apache2, + python3-django-taggit Suggests: python3-django-celery, python3-mysqldb, python3-psycopg2 Description: Django-based patch status monitoring tool for linux systems. . diff --git a/hosts/migrations/0004_remove_host_tags_host_tags.py b/hosts/migrations/0004_remove_host_tags_host_tags.py new file mode 100644 index 00000000..fcf03e40 --- /dev/null +++ b/hosts/migrations/0004_remove_host_tags_host_tags.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.15 on 2025-01-05 14:30 + +from django.db import migrations +import taggit.managers + + +class Migration(migrations.Migration): + + dependencies = [ + ('taggit', '0006_rename_taggeditem_content_type_object_id_taggit_tagg_content_8fc721_idx'), + ('hosts', '0003_host_modules'), + ] + + operations = [ + migrations.RemoveField( + model_name='host', + name='tags', + ), + migrations.AddField( + model_name='host', + name='tags', + field=taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags'), + ), + ] diff --git a/hosts/models.py b/hosts/models.py index 0e477d1d..02e6f175 100644 --- a/hosts/models.py +++ b/hosts/models.py @@ -24,7 +24,7 @@ from version_utils.rpm import labelCompare except ImportError: from rpm import labelCompare -from tagging.fields import TagField +from taggit.managers import TaggableManager from packages.models import Package, PackageUpdate from domains.models import Domain @@ -55,7 +55,7 @@ class Host(models.Model): updates = models.ManyToManyField(PackageUpdate, blank=True) reboot_required = models.BooleanField(default=False) host_repos_only = models.BooleanField(default=True) - tags = TagField() + tags = TaggableManager() updated_at = models.DateTimeField(default=timezone.now) class Meta: diff --git a/hosts/templates/hosts/host_delete.html b/hosts/templates/hosts/host_delete.html index 13d367f8..b80ea170 100644 --- a/hosts/templates/hosts/host_delete.html +++ b/hosts/templates/hosts/host_delete.html @@ -23,9 +23,7 @@ Tags - {% load tagging_tags %} - {% tags_for_object host as tags %} - {% for tag in tags %} + {% for tag in host.tags.all %} {{ tag }} {% endfor %} diff --git a/hosts/templates/hosts/host_detail.html b/hosts/templates/hosts/host_detail.html index 21b4ac74..36791cf6 100644 --- a/hosts/templates/hosts/host_detail.html +++ b/hosts/templates/hosts/host_detail.html @@ -33,9 +33,7 @@ Tags - {% load tagging_tags %} - {% tags_for_object host as tags %} - {% for tag in tags %} + {% for tag in host.tags.all %} {{ tag }} {% endfor %} diff --git a/hosts/views.py b/hosts/views.py index 46a56985..0f38dcdc 100644 --- a/hosts/views.py +++ b/hosts/views.py @@ -22,7 +22,7 @@ from django.db.models import Q from django.contrib import messages -from tagging.models import Tag, TaggedItem +from taggit.models import Tag from rest_framework import viewsets from util.filterspecs import Filter, FilterBar @@ -62,7 +62,7 @@ def host_list(request): hosts = hosts.filter(os__osgroup=int(request.GET['osgroup'])) if 'tag' in request.GET: - hosts = TaggedItem.objects.get_by_model(hosts, request.GET['tag']) + hosts = hosts.filter(tags__name__in=[request.GET['tag']]) if 'reboot_required' in request.GET: reboot_required = request.GET['reboot_required'] == 'True' @@ -89,10 +89,10 @@ def host_list(request): page = paginator.page(paginator.num_pages) filter_list = [] - mytags = {} - for tag in Tag.objects.usage_for_model(Host): - mytags[tag.name] = tag.name - filter_list.append(Filter(request, 'tag', mytags)) + tags = {} + for tag in Tag.objects.all(): + tags[tag.name] = tag.name + filter_list.append(Filter(request, 'tag', tags)) filter_list.append(Filter(request, 'domain', Domain.objects.all())) filter_list.append(Filter(request, 'os', OS.objects.all())) filter_list.append(Filter(request, 'osgroup', OSGroup.objects.all())) diff --git a/patchman/settings.py b/patchman/settings.py index 4a943a2f..6bf681db 100644 --- a/patchman/settings.py +++ b/patchman/settings.py @@ -78,6 +78,7 @@ THIRD_PARTY_APPS = [ 'django_extensions', 'tagging', + 'taggit', 'bootstrap3', 'rest_framework', 'django_filters', @@ -102,6 +103,8 @@ 'PAGE_SIZE': 100, } +TAGGIT_CASE_INSENSITIVE = True + try: from celery import Celery # noqa except ImportError: diff --git a/requirements.txt b/requirements.txt index ec368528..46cfb63b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ Django==3.2.25 django-tagging==0.5.0 +django-taggit==6.1.0 django-extensions==3.2.1 django-bootstrap3==23.1 progressbar==2.5 diff --git a/sbin/patchman b/sbin/patchman index df6cd0ca..6fb90768 100755 --- a/sbin/patchman +++ b/sbin/patchman @@ -30,7 +30,7 @@ from django import setup as django_setup django_setup() from datetime import date, datetime -from tagging.models import TaggedItem +from taggit.models import TaggedItem from hosts.models import Host from packages.models import Package, PackageName, PackageUpdate diff --git a/setup.cfg b/setup.cfg index d001be97..28f45479 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,6 +5,7 @@ post-install = scripts/rpm-post-install.sh requires = /usr/bin/python3 python3-django >= 3.2.20 python3-django-tagging + python3-django-taggit python3-django-extensions python3-django-bootstrap3 python3-django-rest-framework