Skip to content

Commit

Permalink
switch from obsolete django-tagging to django-taggit
Browse files Browse the repository at this point in the history
  • Loading branch information
furlongm committed Jan 6, 2025
1 parent e870dbd commit 47c859e
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 16 deletions.
3 changes: 2 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -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.
.
Expand Down
24 changes: 24 additions & 0 deletions hosts/migrations/0004_remove_host_tags_host_tags.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
4 changes: 2 additions & 2 deletions hosts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions hosts/templates/hosts/host_delete.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
<tr>
<th>Tags</th>
<td>
{% load tagging_tags %}
{% tags_for_object host as tags %}
{% for tag in tags %}
{% for tag in host.tags.all %}
<a href="{% url 'hosts:host_list' %}?tag={{ tag }}">{{ tag }}</a>
{% endfor %}
</td>
Expand Down
4 changes: 1 addition & 3 deletions hosts/templates/hosts/host_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
<tr>
<th>Tags</th>
<td>
{% load tagging_tags %}
{% tags_for_object host as tags %}
{% for tag in tags %}
{% for tag in host.tags.all %}
<a href="{% url 'hosts:host_list' %}?tag={{ tag }}">{{ tag }}</a>
{% endfor %}
</td>
Expand Down
12 changes: 6 additions & 6 deletions hosts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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()))
Expand Down
3 changes: 3 additions & 0 deletions patchman/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
THIRD_PARTY_APPS = [
'django_extensions',
'tagging',
'taggit',
'bootstrap3',
'rest_framework',
'django_filters',
Expand All @@ -102,6 +103,8 @@
'PAGE_SIZE': 100,
}

TAGGIT_CASE_INSENSITIVE = True

try:
from celery import Celery # noqa
except ImportError:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion sbin/patchman
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 47c859e

Please sign in to comment.