refactor(itam): Software Categories now uses details template
#242 closes #236
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
from django.db.models import Q
|
||||
from django import forms
|
||||
from django.urls import reverse
|
||||
|
||||
from app import settings
|
||||
|
||||
from core.forms.common import CommonModelForm
|
||||
|
||||
@ -25,3 +28,61 @@ class SoftwareCategoryForm(
|
||||
]
|
||||
|
||||
model = SoftwareCategory
|
||||
|
||||
|
||||
|
||||
class DetailForm(SoftwareCategoryForm):
|
||||
|
||||
tabs: dict = {
|
||||
"details": {
|
||||
"name": "Details",
|
||||
"slug": "details",
|
||||
"sections": [
|
||||
{
|
||||
"layout": "double",
|
||||
"left": [
|
||||
'name',
|
||||
'slug',
|
||||
'organization',
|
||||
'is_global',
|
||||
'c_created',
|
||||
'c_modified',
|
||||
],
|
||||
"right": [
|
||||
'model_notes',
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
# "notes": {
|
||||
# "name": "Notes",
|
||||
# "slug": "notes",
|
||||
# "sections": []
|
||||
# },
|
||||
}
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
self.fields['c_created'] = forms.DateTimeField(
|
||||
label = 'Created',
|
||||
input_formats=settings.DATETIME_FORMAT,
|
||||
disabled = True,
|
||||
initial = self.instance.created,
|
||||
)
|
||||
|
||||
self.fields['c_modified'] = forms.DateTimeField(
|
||||
label = 'Modified',
|
||||
input_formats=settings.DATETIME_FORMAT,
|
||||
disabled = True,
|
||||
initial = self.instance.modified,
|
||||
)
|
||||
|
||||
self.tabs['details'].update({
|
||||
"edit_url": reverse('Settings:_software_category_change', args=(self.instance.pk,))
|
||||
})
|
||||
|
||||
self.url_index_view = reverse('Settings:_software_categories')
|
||||
|
@ -189,282 +189,3 @@
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{% block contents %}
|
||||
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
|
||||
<div id="Details" class="tabcontent">
|
||||
<h3>
|
||||
Details
|
||||
{% for external_link in external_links %}
|
||||
<span style="font-weight: normal; float: right;">{% include 'icons/external_link.html.j2' with external_link=external_link %}</span>
|
||||
{% endfor %}
|
||||
</h3>
|
||||
<div style="align-items:flex-start; align-content: center; display: flexbox; width: 100%">
|
||||
|
||||
<div style="display: inline; width: 40%; margin: 30px;">
|
||||
|
||||
<div class="detail-view-field">
|
||||
<label>{{ form.name.label }}</label>
|
||||
<span>{{ form.name.value }}</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-view-field">
|
||||
<label>{{ form.device_model.label }}</label>
|
||||
<span>
|
||||
{% if device.device_model %}
|
||||
{{ device.device_model }}
|
||||
{% else %}
|
||||
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-view-field">
|
||||
<label>{{ form.serial_number.label }}</label>
|
||||
<span>
|
||||
{% if form.serial_number.value %}
|
||||
{{ form.serial_number.value }}
|
||||
{% else %}
|
||||
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-view-field">
|
||||
<label>{{ form.uuid.label }}</label>
|
||||
<span>
|
||||
{% if form.uuid.value %}
|
||||
{{ form.uuid.value }}
|
||||
{% else %}
|
||||
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-view-field">
|
||||
<label>{{ form.device_type.label }}</label>
|
||||
<span>
|
||||
{% if device.device_type %}
|
||||
{{ device.device_type }}
|
||||
{% else %}
|
||||
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-view-field">
|
||||
<label>{{ form.organization.label }}</label>
|
||||
<span>{{ device.organization }}</span>
|
||||
</div>
|
||||
|
||||
<div class="detail-view-field">
|
||||
<label>{{ form.lastinventory.label }}</label>
|
||||
<span>
|
||||
{% if form.lastinventory.value %}
|
||||
{{ form.lastinventory.value }}
|
||||
{% else %}
|
||||
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div style="display: inline; width: 40%; margin: 30px; text-align: left;">
|
||||
<div>
|
||||
<label style="font-weight: bold; width: 100%; border-bottom: 1px solid #ccc; display: block; text-align: inherit;">{{ form.model_notes.label }}</label>
|
||||
|
||||
<div style="display: inline-block; text-align: left;">
|
||||
{% if form.model_notes.value %}
|
||||
{{ form.model_notes.value | markdown | safe }}
|
||||
{% else %}
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<input type="button" value="Edit" onclick="window.location='{% url 'ITAM:_device_change' device.id %}';">
|
||||
|
||||
|
||||
<input type="button" value="Edit" onclick="window.location='{% url 'ITAM:_device_change' device.id %}';">
|
||||
{% if not tab %}
|
||||
<script>
|
||||
// Get the element with id="defaultOpen" and click on it
|
||||
document.getElementById("defaultOpen").click();
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="Software" class="tabcontent">
|
||||
<h3>Software</h3>
|
||||
<hr>
|
||||
Installed Software: {{ installed_software }}
|
||||
<input type="button" value="Add Software Action" onclick="window.location='{% url 'ITAM:_device_software_add' device.id %}';">
|
||||
<table>
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
<th>Category</th>
|
||||
<th>Action</th>
|
||||
<th>Desired Version</th>
|
||||
<th>Installed Version</th>
|
||||
<th>Installed</th>
|
||||
<th> </th>
|
||||
</thead>
|
||||
{% if softwares %}
|
||||
{% for software in softwares %}
|
||||
<tr>
|
||||
<td><a href="{% url 'ITAM:_software_view' pk=software.software_id %}">{{ software.software }}</a></td>
|
||||
<td>{{ software.software.category }}</td>
|
||||
<td>
|
||||
{% url 'ITAM:_device_software_view' device_id=device.id pk=software.id as icon_link %}
|
||||
{% if software.get_action_display == 'Install' %}
|
||||
{% include 'icons/success_text.html.j2' with icon_text=software.get_action_display icon_link=icon_link %}
|
||||
{% elif software.get_action_display == 'Remove'%}
|
||||
{% include 'icons/cross_text.html.j2' with icon_text=software.get_action_display icon_link=icon_link %}
|
||||
{% else %}
|
||||
{% include 'icons/add_link.html.j2' with icon_text='Add' icon_link=icon_link %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if software.version %}
|
||||
{{ software.version }}
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if software.installedversion %}
|
||||
{{ software.installedversion }}
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if software.installed %}
|
||||
{{ software.installed }}
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<td colspan="5">Nothing Found</td>
|
||||
{% endif %}
|
||||
</table>
|
||||
|
||||
<div class="pagination">
|
||||
<span class="step-links">
|
||||
{% if page_obj.has_previous %}
|
||||
<a href="?page=1&tab=software">« first</a>
|
||||
<a href="?page={{ page_obj.previous_page_number }}&tab=software">previous</a>
|
||||
{% endif %}
|
||||
|
||||
<span class="current">
|
||||
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
|
||||
</span>
|
||||
|
||||
{% if page_obj.has_next %}
|
||||
<a href="?page={{ page_obj.next_page_number }}&tab=software">next</a>
|
||||
<a href="?page={{ page_obj.paginator.num_pages }}&tab=software">last »</a>
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{% if tab == 'software' %}
|
||||
<script>
|
||||
// Get the element with id="defaultOpen" and click on it
|
||||
document.getElementById("SoftwareOpen").click();
|
||||
</script>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
<div id="Notes" class="tabcontent">
|
||||
<h3>
|
||||
Notes
|
||||
</h3>
|
||||
{{ notes_form }}
|
||||
<input type="submit" name="{{notes_form.prefix}}" value="Submit" />
|
||||
<div class="comments">
|
||||
{% if notes %}
|
||||
{% for note in notes%}
|
||||
{% include 'note.html.j2' %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if tab == 'notes' %}
|
||||
<script>
|
||||
// Get the element with id="defaultOpen" and click on it
|
||||
document.getElementById("NotesOpen").click();
|
||||
</script>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
<div id="ConfigManagement" class="tabcontent">
|
||||
<h3>Configuration Management</h3>
|
||||
<div>
|
||||
<textarea cols="90" rows="30" readonly>{{ config }}</textarea>
|
||||
</div>
|
||||
<br />
|
||||
<hr />
|
||||
<table class="data">
|
||||
<tr>
|
||||
<th>Group</th>
|
||||
<th>Added</th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
{% if config_groups %}
|
||||
{% for group in config_groups %}
|
||||
<tr>
|
||||
<td><a href="{% url 'Config Management:_group_view' pk=group.group.id %}">{{ group.group }}</a></td>
|
||||
<td>{{ group.created }}</td>
|
||||
<td><a href="{% url 'Config Management:_group_delete_host' group_id=group.group.id pk=group.id %}">Delete</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="3">Nothing Found</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
|
||||
{% if tab == 'configmanagement' %}
|
||||
<script>
|
||||
// Get the element with id="defaultOpen" and click on it
|
||||
document.getElementById("ConfigManagementOpen").click();
|
||||
</script>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
150
app/itam/templates/itam/software_categories.html.j2
Normal file
150
app/itam/templates/itam/software_categories.html.j2
Normal file
@ -0,0 +1,150 @@
|
||||
{% extends 'detail.html.j2' %}
|
||||
|
||||
{% load json %}
|
||||
{% load markdown %}
|
||||
|
||||
|
||||
{% block tabs %}
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
<div id="details" class="content-tab">
|
||||
|
||||
{% include 'content/section.html.j2' with tab=form.tabs.details %}
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="versions" class="content-tab">
|
||||
|
||||
{% include 'content/section.html.j2' with tab=form.tabs.versions %}
|
||||
|
||||
<input type="button" value="New Software Version" onclick="window.location='{% url 'ITAM:_software_version_add' pk=software.id %}';">
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<th>Version</th>
|
||||
<th>Installations</th>
|
||||
<th>Vulnerable</th>
|
||||
<th> </th>
|
||||
</thead>
|
||||
{% for version in software_versions %}
|
||||
<tr>
|
||||
<td><a href="{% url 'ITAM:_software_version_view' software_id=software.id pk=version.id %}">{{ version.name }}</a></td>
|
||||
<td>{{ version.installs }}</td>
|
||||
<td>{% include 'icons/issue_link.html.j2' with issue=3 %}</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="licences" class="content-tab">
|
||||
|
||||
{% include 'content/section.html.j2' with tab=form.tabs.licences %}
|
||||
|
||||
{% include 'icons/issue_link.html.j2' with issue=4 %}
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Available</th>
|
||||
<th> </th>
|
||||
</thead>
|
||||
<tr>
|
||||
<td>GPL-3</td>
|
||||
<td>Open Source</td>
|
||||
<td>1 / 5</td>
|
||||
<th> </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>MIT</td>
|
||||
<td>Open Source</td>
|
||||
<td>Unlimited</td>
|
||||
<th> </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Windows Device</td>
|
||||
<td>CAL</td>
|
||||
<td>11 / 15</td>
|
||||
<th> </th>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="notes" class="content-tab">
|
||||
|
||||
{% include 'content/section.html.j2' with tab=form.tabs.notes %}
|
||||
|
||||
{{ notes_form }}
|
||||
<input type="submit" name="{{notes_form.prefix}}" value="Submit" />
|
||||
<div class="comments">
|
||||
{% if notes %}
|
||||
{% for note in notes%}
|
||||
{% include 'note.html.j2' %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="installations" class="content-tab">
|
||||
|
||||
{% include 'content/section.html.j2' with tab=form.tabs.installations %}
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<th>Device</th>
|
||||
<th>Organization</th>
|
||||
<th title="Not Set/Install/Remove">Action</th>
|
||||
<th>Installed Version</th>
|
||||
<th title="Date Software Installed">Install Date</th>
|
||||
<th> </th>
|
||||
</thead>
|
||||
{% if device_software %}
|
||||
{% for device in device_software %}
|
||||
<tr>
|
||||
<td><a href="{% url 'ITAM:_device_view' pk=device.device.id %}">{{ device.device }}</a></td>
|
||||
<td>{{ device.organization }}</td>
|
||||
<td>
|
||||
{% if device.get_action_display == 'Install' %}
|
||||
{% include 'icons/success_text.html.j2' with icon_text=device.get_action_display %}
|
||||
{% elif device.get_action_display == 'Remove'%}
|
||||
{% include 'icons/cross_text.html.j2' with icon_text=device.get_action_display %}
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if device.installedversion %}
|
||||
{{ device.installedversion }}
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if device.installed %}
|
||||
{{ device.installed }}
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="6">Nothing Found</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
@ -4,13 +4,13 @@ from django.utils.decorators import method_decorator
|
||||
|
||||
from core.views.common import AddView, ChangeView, DeleteView
|
||||
|
||||
from itam.forms.software_category import SoftwareCategoryForm
|
||||
from itam.forms.software_category import DetailForm, SoftwareCategoryForm
|
||||
from itam.models.software import Software, SoftwareCategory
|
||||
|
||||
from settings.models.user_settings import UserSettings
|
||||
|
||||
|
||||
class View(ChangeView):
|
||||
class Change(ChangeView):
|
||||
|
||||
context_object_name = "software"
|
||||
|
||||
@ -19,7 +19,6 @@ class View(ChangeView):
|
||||
model = SoftwareCategory
|
||||
|
||||
permission_required = [
|
||||
'itam.view_softwarecategory',
|
||||
'itam.change_softwarecategory',
|
||||
]
|
||||
|
||||
@ -48,6 +47,38 @@ class View(ChangeView):
|
||||
|
||||
|
||||
|
||||
class View(ChangeView):
|
||||
|
||||
context_object_name = "software"
|
||||
|
||||
form_class = DetailForm
|
||||
|
||||
model = SoftwareCategory
|
||||
|
||||
permission_required = [
|
||||
'itam.view_softwarecategory',
|
||||
]
|
||||
|
||||
template_name = 'itam/software_categories.html.j2'
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context['model_delete_url'] = reverse('Settings:_software_category_delete', args=(self.kwargs['pk'],))
|
||||
|
||||
context['content_title'] = self.object.name
|
||||
|
||||
return context
|
||||
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
|
||||
return reverse('Settings:_software_category_view', args=(self.kwargs['pk'],))
|
||||
|
||||
|
||||
|
||||
|
||||
class Add(AddView):
|
||||
|
||||
form_class = SoftwareCategoryForm
|
||||
|
@ -46,6 +46,7 @@ urlpatterns = [
|
||||
path("software_category", software_categories.Index.as_view(), name="_software_categories"),
|
||||
path("software_category/<int:pk>", software_category.View.as_view(), name="_software_category_view"),
|
||||
path("software_category/add/", software_category.Add.as_view(), name="_software_category_add"),
|
||||
path("software_category/<int:pk>/edit", software_category.Change.as_view(), name="_software_category_change"),
|
||||
path("software_category/<int:pk>/delete", software_category.Delete.as_view(), name="_software_category_delete"),
|
||||
|
||||
path("manufacturers", manufacturer.Index.as_view(), name="_manufacturers"),
|
||||
|
Reference in New Issue
Block a user