refactor(itam): move device types to settings app

!10
This commit is contained in:
2024-05-23 19:16:08 +09:30
parent ac233e432f
commit c83b883673
5 changed files with 140 additions and 1 deletions

View File

@ -0,0 +1,43 @@
{% 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 Type" onclick="window.location='{% url 'Settings:_device_type_add' %}';">
<table class="data">
<tr>
<th>Name</th>
<th>Organization</th>
<th>&nbsp;</th>
</tr>
{% for item in list %}
<tr>
<td><a href="{% url 'Settings:_device_type_view' pk=item.id %}">{{ item.name }}</a></td>
<td>{% if item.is_global %}Global{% else %}{{ item.organization }}{% endif %}</td>
<td><a href="{% url 'Settings:_device_type_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

@ -0,0 +1,19 @@
from django.test import TestCase, Client
import pytest
import unittest
import requests
@pytest.mark.skip(reason="to be written")
def test_device_type_create_has_organization():
""" Device Type must be assigned an organization """
pass
@pytest.mark.skip(reason="to be written")
def test_device_type_edit_has_organization():
""" Device Type must be assigned an organization """
pass

View File

@ -0,0 +1,32 @@
# from django.conf import settings
# from django.shortcuts import reverse
from django.test import TestCase, Client
import pytest
import unittest
import requests
@pytest.mark.skip(reason="to be written")
def test_device_type_auth_view(user):
""" Check correct permission for view """
pass
@pytest.mark.skip(reason="to be written")
def test_device_type_auth_add(user):
""" Check correct permission for add """
pass
@pytest.mark.skip(reason="to be written")
def test_device_type_auth_change(user):
""" Check correct permission for change """
pass
@pytest.mark.skip(reason="to be written")
def test_device_type_auth_delete(user):
""" Check correct permission for delete """
pass

View File

@ -1,10 +1,17 @@
from django.urls import path
from .views import home
from .views import home, device_types
from itam.views import device_type
app_name = "Settings"
urlpatterns = [
path("", home.View.as_view(), name="Settings"),
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"),
path("device_type/<int:pk>/delete", device_type.Delete.as_view(), name="_device_type_delete"),
]

View File

@ -0,0 +1,38 @@
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.db.models import Q
from django.views import generic
from itam.models.device import DeviceType
class Index(PermissionRequiredMixin, OrganizationPermission, generic.ListView):
model = DeviceType
permission_required = 'itam.view_devicetype'
template_name = 'settings/device_types.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 Types'
return context