feat(device): configurable software version

!5
This commit is contained in:
2024-05-17 21:10:15 +09:30
parent b0e69ee64b
commit b811eedb33
7 changed files with 84 additions and 7 deletions

View File

@ -0,0 +1,22 @@
from django import forms
from django.db.models import Q
from itam.models.device import DeviceSoftware
from itam.models.software import Software, SoftwareVersion
class SoftwareUpdate(forms.ModelForm):
class Meta:
model = DeviceSoftware
fields = [
'action',
'version',
]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['version'].queryset = SoftwareVersion.objects.filter(software_id=self.instance.software.id)

View File

@ -0,0 +1,19 @@
# Generated by Django 5.0.6 on 2024-05-17 10:18
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('itam', '0002_alter_softwareversion_name'),
]
operations = [
migrations.AddField(
model_name='devicesoftware',
name='version',
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='itam.softwareversion'),
),
]

View File

@ -2,7 +2,7 @@ from django.db import models
from access.fields import *
from access.models import TenancyObject
from itam.models.software import Software
from itam.models.software import Software, SoftwareVersion
@ -98,11 +98,19 @@ class Device(DeviceCommonFieldsName):
state = 'absent'
software = {
print(f"here: {software.version}")
software_action = {
"name": software.software.slug,
"state": state
}
config['software'] = config['software'] + [ software ]
if software.version:
software_action['version'] = software.version.name
config['software'] = config['software'] + [ software_action ]
return config
@ -140,3 +148,12 @@ class DeviceSoftware(DeviceCommonFields):
choices=Actions,
default=None,
)
version = models.ForeignKey(
SoftwareVersion,
on_delete=models.CASCADE,
default = None,
null = True,
blank= True
)

View File

@ -68,5 +68,9 @@ class SoftwareVersion(SoftwareCommonFields):
unique = False,
)
def __str__(self):
return self.name

View File

@ -67,6 +67,7 @@
<thead>
<th>Name</th>
<th>Action</th>
<th>Version</th>
<th>Installed</th>
<th>&nbsp;</th>
</thead>
@ -75,7 +76,13 @@
<td><a href="{% url 'ITAM:_software_view' pk=software.software_id %}">{{ software.software }}</a></td>
<td><a href="{% url 'ITAM:_device_software_view' device_id=device.id pk=software.id %}">{{ software.get_action_display }}</a></td>
<td>
{% if software.version %}
{{ software.version }}
{% else %}
Any
{% endif %}
</td>
<td>
{% include 'icons/success_text.html.j2' with icon_text='success' %}{% include 'icons/cross_text.html.j2' with icon_text='cross' %}{% include 'icons/change_text.html.j2' with icon_text='change' %}
</td>
<td>&nbsp;</td>

View File

@ -114,6 +114,7 @@
<th>Device</th>
<th>Organization</th>
<th title="Not Set/Install/Remove">Action</th>
<th>Version</th>
<th title="Date Software Installed">Installed</th>
<th>&nbsp;</th>
</thead>
@ -130,6 +131,13 @@
{{ device.get_action_display }}
{% endif %}
</td>
<td>
{% if device.version %}
{{ device.version }}
{% else %}
Any
{% endif %}
</td>
<td>Not Implemented</td>
<td>&nbsp;</td>
</tr>

View File

@ -9,6 +9,7 @@ from access.models import Organization
from ..models.device import Device, DeviceSoftware
from itam.forms.device_softwareadd import SoftwareAdd
from itam.forms.device_softwareupdate import SoftwareUpdate
class IndexView(PermissionRequiredMixin, OrganizationPermission, generic.ListView):
@ -76,13 +77,12 @@ class SoftwareView(OrganizationPermission, generic.UpdateView):
]
template_name = 'form.html.j2'
fields = [
'action',
]
context_object_name = "devicesoftware"
form_class = SoftwareUpdate
def form_valid(self, form):
device = Device.objects.get(pk=self.kwargs['device_id'])