feat(itam): Add device model

!10 closes #12
This commit is contained in:
2024-05-23 21:26:50 +09:30
parent ef463b845d
commit 99a559fe6d
20 changed files with 519 additions and 38 deletions

View File

@ -0,0 +1,45 @@
{% extends 'base.html.j2' %}
{% block content_header_icon %}{% endblock %}
{% block body %}
<input type="button" value="<< Back to settings" onclick="window.location='{% url 'Settings:Settings' %}';">
<input type="button" value="New Device Model" onclick="window.location='{% url 'Settings:_device_model_add' %}';">
<table class="data">
<tr>
<th>Name</th>
<th>Manufacturer</th>
<th>Organization</th>
<th>&nbsp;</th>
</tr>
{% for item in list %}
<tr>
<td><a href="{% url 'Settings:_device_model_view' pk=item.id %}">{{ item.name }}</a></td>
<td>{{ item.manufacturer }}</td>
<td>{% if item.is_global %}Global{% else %}{{ item.organization }}{% endif %}</td>
<td><a href="{% url 'Settings:_device_model_delete' pk=item.id %}">Delete</a></td>
</tr>
{% endfor %}
</table>
<div class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
<a href="?page=1">&laquo; first</a>
<a href="?page={{ page_obj.previous_page_number }}">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 }}">next</a>
<a href="?page={{ page_obj.paginator.num_pages }}">last &raquo;</a>
{% endif %}
</span>
</div>
{% endblock %}

View File

@ -43,6 +43,7 @@ div#content article h3 {
<h3>ITAM</h3>
<ul>
<li><a href="{% url 'Settings:_device_types' %}">Device Types</a></li>
<li><a href="{% url 'Settings:_device_models' %}">Device Models</a></li>
<li><a href="{% url 'Settings:_software_categories' %}">Software Categories</a></li>
</ul>
</article>

View File

@ -1,14 +1,19 @@
from django.urls import path
from .views import home, device_types, manufacturer, software_categories
from .views import home, device_models, device_types, manufacturer, software_categories
from itam.views import device_type, software_category
from itam.views import device_type, device_model, software_category
app_name = "Settings"
urlpatterns = [
path("", home.View.as_view(), name="Settings"),
path("device_models", device_models.Index.as_view(), name="_device_models"),
path("device_model/<int:pk>", device_model.View.as_view(), name="_device_model_view"),
path("device_model/add/", device_model.Add.as_view(), name="_device_model_add"),
path("device_model/<int:pk>/delete", device_model.Delete.as_view(), name="_device_model_delete"),
path("device_type/", device_types.Index.as_view(), name="_device_types"),
path("device_type/<int:pk>", device_type.View.as_view(), name="_device_type_view"),
path("device_type/add/", device_type.Add.as_view(), name="_device_type_add"),

View File

@ -0,0 +1,39 @@
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.db.models import Q
from django.views import generic
from access.mixin import OrganizationPermission
from itam.models.device_models import DeviceModel
class Index(PermissionRequiredMixin, OrganizationPermission, generic.ListView):
model = DeviceModel
permission_required = 'itam.view_devicetype'
template_name = 'settings/device_models.html.j2'
context_object_name = "list"
paginate_by = 10
def get_queryset(self):
if self.request.user.is_superuser:
return self.model.objects.filter().order_by('name')
else:
return self.model.objects.filter(Q(organization__in=self.user_organizations()) | Q(is_global = True)).order_by('name')
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['content_title'] = 'Device Models'
return context