feat(itam): Ability to add notes to software

!8 #7
This commit is contained in:
2024-05-21 01:22:15 +09:30
parent 4d5f229fc7
commit dec2942996
2 changed files with 49 additions and 4 deletions

View File

@ -37,17 +37,17 @@
<button id="defaultOpen" class="tablinks" onclick="openCity(event, 'Details')">Details</button>
<button id="defaultOpen" 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>
<!-- Tab content -->
<form method="post">
<div id="Details" class="tabcontent">
<h3>Details</h3>
<form method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
<script>
// Get the element with id="defaultOpen" and click on it
@ -108,6 +108,23 @@
</table>
</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>
@ -157,6 +174,6 @@
{% endif %}
</table>
</div>
</form>
{% endblock %}

View File

@ -4,6 +4,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 DeviceSoftware
from itam.models.software import Software, SoftwareVersion
from itam.forms.software.update import Update as SoftwareUpdate_Form
@ -40,6 +43,7 @@ class View(OrganizationPermission, generic.UpdateView):
context_object_name = "software"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
@ -51,6 +55,9 @@ class View(OrganizationPermission, generic.UpdateView):
context['software_versions'] = software_versions
context['notes_form'] = AddNoteForm(prefix='note')
context['notes'] = Notes.objects.filter(software=self.kwargs['pk'])
context['content_title'] = self.object.name
if self.request.user.is_superuser:
@ -73,6 +80,27 @@ class View(OrganizationPermission, generic.UpdateView):
return context
def post(self, request, *args, **kwargs):
software = Software.objects.get(pk=self.kwargs['pk'])
notes = AddNoteForm(request.POST, prefix='note')
if notes.is_bound and notes.is_valid():
notes.instance.organization = software.organization
notes.instance.software = software
notes.instance.usercreated = request.user
notes.save()
return super().post(request, *args, **kwargs)
def get_success_url(self, **kwargs):
return f"/itam/software/{self.kwargs['pk']}/"