feat(software): ability to add software versions

!5
This commit is contained in:
2024-05-17 19:33:01 +09:30
parent 7302f99753
commit 7f35292f64
4 changed files with 52 additions and 6 deletions

View File

@ -56,7 +56,7 @@
<div id="Versions" class="tabcontent"> <div id="Versions" class="tabcontent">
<h3>Versions</h3> <h3>Versions</h3>
Not Yet Implemented <input type="button" value="New Software Version" onclick="window.location='{% url 'ITAM:_software_version_add' pk=software.id %}';">
<table> <table>
<thead> <thead>
<th>Version</th> <th>Version</th>
@ -65,9 +65,12 @@
<th>&nbsp;</th> <th>&nbsp;</th>
</thead> </thead>
<tr> <tr>
<td>1.0.0</td> {% for version in software_versions %}
<td>5</td> <td>{{ version.name }}</td>
<td><input type="checkbox" checked disabled></td> <td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
{% endfor %}
</tr> </tr>
</table> </table>
</div> </div>

View File

@ -1,7 +1,7 @@
from django.urls import path from django.urls import path
from . import views from . import views
from .views import device, device_type, software, software_category from .views import device, device_type, software, software_category, software_version
app_name = "ITAM" app_name = "ITAM"
urlpatterns = [ urlpatterns = [
@ -20,6 +20,7 @@ urlpatterns = [
path("software/", software.IndexView.as_view(), name="Software"), path("software/", software.IndexView.as_view(), name="Software"),
path("software/<int:pk>/", software.View.as_view(), name="_software_view"), path("software/<int:pk>/", software.View.as_view(), name="_software_view"),
path("software/<int:pk>/delete", software.Delete.as_view(), name="_software_delete"), path("software/<int:pk>/delete", software.Delete.as_view(), name="_software_delete"),
path("software/<int:pk>/version/add", software_version.Add.as_view(), name="_software_version_add"),
path("software/add/", software.Add.as_view(), name="_software_add"), path("software/add/", software.Add.as_view(), name="_software_add"),
path("software_category/add/", software_category.Add.as_view(), name="_software_category_add"), path("software_category/add/", software_category.Add.as_view(), name="_software_category_add"),

View File

@ -5,7 +5,7 @@ from django.views import generic
from access.mixin import OrganizationPermission from access.mixin import OrganizationPermission
from itam.models.device import DeviceSoftware from itam.models.device import DeviceSoftware
from itam.models.software import Software from itam.models.software import Software, SoftwareVersion
from itam.forms.software.update import Update as SoftwareUpdate_Form from itam.forms.software.update import Update as SoftwareUpdate_Form
class IndexView(PermissionRequiredMixin, OrganizationPermission, generic.ListView): class IndexView(PermissionRequiredMixin, OrganizationPermission, generic.ListView):
@ -43,6 +43,10 @@ class View(OrganizationPermission, generic.UpdateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
software_versions = SoftwareVersion.objects.filter(software=self.kwargs['pk'])
context['software_versions'] = software_versions
context['content_title'] = self.object.name context['content_title'] = self.object.name
if self.request.user.is_superuser: if self.request.user.is_superuser:

View File

@ -0,0 +1,38 @@
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.views import generic
from access.mixin import OrganizationPermission
from ..models.software import Software, SoftwareVersion
class Add(PermissionRequiredMixin, OrganizationPermission, generic.CreateView):
model = SoftwareVersion
permission_required = [
'access.add_softwareversion',
]
template_name = 'form.html.j2'
fields = [
'name'
]
def form_valid(self, form):
software = Software.objects.get(pk=self.kwargs['pk'])
form.instance.organization_id = software.organization.id
form.instance.software_id = self.kwargs['pk']
return super().form_valid(form)
def get_success_url(self, **kwargs):
return f"/itam/software/{self.kwargs['pk']}/"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['content_title'] = 'Add Software Version'
return context