Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support other errata sources #633

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions hosts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class Host(models.Model):
tags = TagField()
updated_at = models.DateTimeField(default=timezone.now)

from hosts.managers import HostManager
objects = HostManager()

class Meta:
verbose_name = 'Host'
verbose_name_plural = 'Hosts'
Expand Down
4 changes: 2 additions & 2 deletions hosts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class Meta:
'updated_at', 'bugfix_update_count', 'security_update_count')

def get_bugfix_update_count(self, obj):
return len([u for u in obj.updates.all() if not u.security])
return obj.updates.filter(security=False).count()

def get_security_update_count(self, obj):
return len([u for u in obj.updates.all() if u.security])
return obj.updates.filter(security=True).count()


class HostRepoSerializer(serializers.HyperlinkedModelSerializer):
Expand Down
6 changes: 3 additions & 3 deletions hosts/templatetags/report_alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
from datetime import timedelta

from django.conf import settings

from django.template import Library
from django.utils.html import format_html
from django.templatetags.static import static
from django.utils import timezone

from util import has_setting_of_type

register = Library()


@register.simple_tag
def report_alert(lastreport):
html = ''
alert_icon = static('img/icon-alert.gif')
if hasattr(settings, 'DAYS_WITHOUT_REPORT') and \
isinstance(settings.DAYS_WITHOUT_REPORT, int):
if has_setting_of_type('DAYS_WITHOUT_REPORT', int):
days = settings.DAYS_WITHOUT_REPORT
else:
days = 14
Expand Down
66 changes: 66 additions & 0 deletions operatingsystems/fixtures/os.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[
{
"model": "operatingsystems.os",
"fields": {
"name": "Rocky Linux 9.3",
"osgroup": [
"Rocky Linux 9",
"Blue Onyx"
]
}
},
{
"model": "operatingsystems.os",
"fields": {
"name": "Rocky Linux 8.9",
"osgroup": [
"Rocky Linux 8",
"Green Obsidian"
]
}
},
{
"model": "operatingsystems.os",
"fields": {
"name": "Debian 12.5",
"osgroup": [
"Debian 12",
"bookworm"
]
}
},
{
"model": "operatingsystems.os",
"fields": {
"name": "Arch Linux",
"osgroup": null
}
},
{
"model": "operatingsystems.os",
"fields": {
"name": "openSUSE Leap 15.5",
"osgroup": null
}
},
{
"model": "operatingsystems.os",
"fields": {
"name": "AlmaLinux 8.10",
"osgroup": [
"AlmaLinux 8",
"Cerulean Leopard"
]
}
},
{
"model": "operatingsystems.os",
"fields": {
"name": "AlmaLinux 9.5",
"osgroup": [
"AlmaLinux 9",
"Teal Serval"
]
}
}
]
58 changes: 58 additions & 0 deletions operatingsystems/fixtures/osgroup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"model": "operatingsystems.osgroup",
"fields": {
"name": "CentOS 7",
"codename": "",
"repos": []
}
},
{
"model": "operatingsystems.osgroup",
"fields": {
"name": "CentOS 8",
"codename": "",
"repos": []
}
},
{
"model": "operatingsystems.osgroup",
"fields": {
"name": "Rocky Linux 8",
"codename": "Green Obsidian",
"repos": []
}
},
{
"model": "operatingsystems.osgroup",
"fields": {
"name": "Rocky Linux 9",
"codename": "Blue Onyx",
"repos": []
}
},
{
"model": "operatingsystems.osgroup",
"fields": {
"name": "AlmaLinux 8",
"codename": "Cerulean Leopard",
"repos": []
}
},
{
"model": "operatingsystems.osgroup",
"fields": {
"name": "AlmaLinux 9",
"codename": "Teal Serval",
"repos": []
}
},
{
"model": "operatingsystems.osgroup",
"fields": {
"name": "Debian 12",
"codename": "bookworm",
"repos": []
}
}
]
22 changes: 22 additions & 0 deletions operatingsystems/managers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 Marcus Furlong <[email protected]>
#
# This file is part of Patchman.
#
# Patchman is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 only.
#
# Patchman is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Patchman. If not, see <http://www.gnu.org/licenses/>

from django.db import models


class OSGroupManager(models.Manager):
def get_by_natural_key(self, name, codename):
return self.get(name=name, codename=codename)
18 changes: 18 additions & 0 deletions operatingsystems/migrations/0003_osgroup_codename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.15 on 2025-01-13 18:55

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('operatingsystems', '0002_initial'),
]

operations = [
migrations.AddField(
model_name='osgroup',
name='codename',
field=models.CharField(blank=True, max_length=255),
),
]
17 changes: 17 additions & 0 deletions operatingsystems/migrations/0004_alter_osgroup_unique_together.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.15 on 2025-01-13 19:57

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('operatingsystems', '0003_osgroup_codename'),
]

operations = [
migrations.AlterUniqueTogether(
name='osgroup',
unique_together={('name', 'codename')},
),
]
13 changes: 12 additions & 1 deletion operatingsystems/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,29 @@ class OSGroup(models.Model):

name = models.CharField(max_length=255, unique=True)
repos = models.ManyToManyField(Repository, blank=True)
codename = models.CharField(max_length=255, blank=True)

from operatingsystems.managers import OSGroupManager
objects = OSGroupManager()

class Meta:
verbose_name = 'Operating System Group'
verbose_name_plural = 'Operating System Groups'
unique_together = ('name', 'codename')
ordering = ('name',)

def __str__(self):
return self.name
if self.codename:
return f'{self.name} ({self.codename})'
else:
return self.name

def get_absolute_url(self):
return reverse('operatingsystems:osgroup_detail', args=[str(self.id)])

def natural_key(self):
return (self.name, self.codename)


class OS(models.Model):

Expand Down
14 changes: 11 additions & 3 deletions packages/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@


class ErratumAdmin(admin.ModelAdmin):
readonly_fields = ('packages',)
readonly_fields = ('packages', 'references')


admin.site.register(Package)
class PackageAdmin(admin.ModelAdmin):
readonly_fields = ('name',)


class PackageUpdateAdmin(admin.ModelAdmin):
readonly_fields = ('oldpackage', 'newpackage')


admin.site.register(Package, PackageAdmin)
admin.site.register(PackageName)
admin.site.register(PackageUpdate)
admin.site.register(PackageUpdate, PackageUpdateAdmin)
admin.site.register(Erratum, ErratumAdmin)
admin.site.register(ErratumReference)
19 changes: 19 additions & 0 deletions packages/migrations/0002_erratumreference_er_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.15 on 2025-01-12 21:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('packages', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='erratumreference',
name='er_type',
field=models.CharField(default=None, max_length=255),
preserve_default=False,
),
]
1 change: 1 addition & 0 deletions packages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def __str__(self):

class ErratumReference(models.Model):

er_type = models.CharField(max_length=255)
url = models.URLField(max_length=255)

def __str__(self):
Expand Down
Loading
Loading