feat(itam): Ability to add notes to operating systems

!8 #7
This commit is contained in:
2024-05-21 01:22:02 +09:30
parent 725e6b8c92
commit 4d5f229fc7
2 changed files with 53 additions and 9 deletions

View File

@ -31,19 +31,20 @@
<svg xmlns="http://www.w3.org/2000/svg" height="25px" viewBox="0 -960 960 960" width="25px" style="vertical-align: middle; margin: 0px; padding: 0px border: none; " fill="#6a6e73">
<path d="m313-480 155 156q11 11 11.5 27.5T468-268q-11 11-28 11t-28-11L228-452q-6-6-8.5-13t-2.5-15q0-8 2.5-15t8.5-13l184-184q11-11 27.5-11.5T468-692q11 11 11 28t-11 28L313-480Zm264 0 155 156q11 11 11.5 27.5T732-268q-11 11-28 11t-28-11L492-452q-6-6-8.5-13t-2.5-15q0-8 2.5-15t8.5-13l184-184q11-11 27.5-11.5T732-692q11 11 11 28t-11 28L577-480Z"/>
</svg> Back to Operating Systems</button>
<button id="defaultOpen" class="tablinks" onclick="openCity(event, 'Details')">Details</button>
<button class="tablinks" onclick="openCity(event, 'Versions')">Versions</button>
<button class="tablinks" onclick="openCity(event, 'Licences')">Licences</button>
<button class="tablinks" onclick="openCity(event, 'Installations')">Installations</button>
<button id="defaultOpen" class="tablinks" onclick="openCity(event, 'Details')">Details</button>
<button class="tablinks" onclick="openCity(event, 'Versions')">Versions</button>
<button class="tablinks" onclick="openCity(event, 'Licences')">Licences</button>
<button class="tablinks" onclick="openCity(event, 'Notes')">Notes</button>
<button class="tablinks" onclick="openCity(event, 'Installations')">Installations</button>
</div>
<form method="post">
<div id="Details" class="tabcontent">
<h3>Details</h3>
<form method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
<script>
document.getElementById("defaultOpen").click();
@ -106,6 +107,23 @@
</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>
<div id="Installations" class="tabcontent">
<h3>Installations</h3>
<table>
@ -133,5 +151,6 @@
{% endfor %}
</table>
</div>
</form>
{% endblock %}

View File

@ -5,6 +5,9 @@ from django.views import generic
from access.mixin import OrganizationPermission
from core.forms.comment import AddNoteForm
from core.models.notes import Notes
from itam.models.device import DeviceOperatingSystem
from itam.models.operating_system import OperatingSystem, OperatingSystemVersion
from itam.forms.operating_system.update import Update
@ -51,10 +54,32 @@ class View(OrganizationPermission, generic.UpdateView):
installs = DeviceOperatingSystem.objects.filter(operating_system_version__operating_system_id=self.kwargs['pk'])
context['installs'] = installs
context['notes_form'] = AddNoteForm(prefix='note')
context['notes'] = Notes.objects.filter(operatingsystem=self.kwargs['pk'])
context['content_title'] = self.object.name
return context
def post(self, request, *args, **kwargs):
operatingsystem = OperatingSystem.objects.get(pk=self.kwargs['pk'])
notes = AddNoteForm(request.POST, prefix='note')
if notes.is_bound and notes.is_valid():
notes.instance.organization = operatingsystem.organization
notes.instance.operatingsystem = operatingsystem
notes.instance.usercreated = request.user
notes.save()
return super().post(request, *args, **kwargs)
def get_success_url(self, **kwargs):
return reverse('ITAM:_operating_system_view', args=(self.kwargs['pk'],))