@ -33,7 +33,7 @@ class View(OrganizationPermission, generic.UpdateView):
|
|||||||
|
|
||||||
def get_success_url(self, **kwargs):
|
def get_success_url(self, **kwargs):
|
||||||
|
|
||||||
return f"/itam/device/{self.kwargs['pk']}/"
|
return f"/settings/device_type/{self.kwargs['pk']}"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ class Add(PermissionRequiredMixin, OrganizationPermission, generic.CreateView):
|
|||||||
|
|
||||||
def get_success_url(self, **kwargs):
|
def get_success_url(self, **kwargs):
|
||||||
|
|
||||||
return f"/itam/device/"
|
return f"/settings/device_type/"
|
||||||
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
@ -61,3 +61,28 @@ class Add(PermissionRequiredMixin, OrganizationPermission, generic.CreateView):
|
|||||||
context['content_title'] = 'Add Device Type'
|
context['content_title'] = 'Add Device Type'
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
class Delete(PermissionRequiredMixin, OrganizationPermission, generic.DeleteView):
|
||||||
|
model = DeviceType
|
||||||
|
permission_required = [
|
||||||
|
'access.delete_device_type',
|
||||||
|
]
|
||||||
|
template_name = 'form.html.j2'
|
||||||
|
# fields = [
|
||||||
|
# 'name',
|
||||||
|
# 'organization',
|
||||||
|
# 'is_global'
|
||||||
|
# ]
|
||||||
|
|
||||||
|
|
||||||
|
def get_success_url(self, **kwargs):
|
||||||
|
|
||||||
|
return f"/settings/device_type/"
|
||||||
|
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
|
context['content_title'] = 'Delete ' + self.object.name
|
||||||
|
|
||||||
|
return context
|
||||||
|
@ -51,7 +51,7 @@ class View(OrganizationPermission, generic.UpdateView):
|
|||||||
|
|
||||||
def get_success_url(self, **kwargs):
|
def get_success_url(self, **kwargs):
|
||||||
|
|
||||||
return f"/itam/software/{self.kwargs['pk']}/"
|
return f"/settings/software_category/{self.kwargs['pk']}/"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ class Add(PermissionRequiredMixin, OrganizationPermission, generic.CreateView):
|
|||||||
|
|
||||||
def get_success_url(self, **kwargs):
|
def get_success_url(self, **kwargs):
|
||||||
|
|
||||||
return f"/itam/software/"
|
return f"/settings/software_category"
|
||||||
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
@ -81,7 +81,7 @@ class Add(PermissionRequiredMixin, OrganizationPermission, generic.CreateView):
|
|||||||
return context
|
return context
|
||||||
|
|
||||||
class Delete(PermissionRequiredMixin, OrganizationPermission, generic.DeleteView):
|
class Delete(PermissionRequiredMixin, OrganizationPermission, generic.DeleteView):
|
||||||
model = Software
|
model = SoftwareCategory
|
||||||
permission_required = [
|
permission_required = [
|
||||||
'access.delete_software',
|
'access.delete_software',
|
||||||
]
|
]
|
||||||
@ -95,7 +95,7 @@ class Delete(PermissionRequiredMixin, OrganizationPermission, generic.DeleteView
|
|||||||
|
|
||||||
def get_success_url(self, **kwargs):
|
def get_success_url(self, **kwargs):
|
||||||
|
|
||||||
return f"/itam/software/"
|
return f"/settings/software_category"
|
||||||
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
44
app/settings/templates/settings/software_categories.html.j2
Normal file
44
app/settings/templates/settings/software_categories.html.j2
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
{% 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 Software Category" onclick="window.location='{% url 'Settings:_software_category_add' %}';">
|
||||||
|
<table class="data">
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Organization</th>
|
||||||
|
<th> </th>
|
||||||
|
</tr>
|
||||||
|
{% for item in list %}
|
||||||
|
<tr>
|
||||||
|
<td><a href="{% url 'Settings:_software_category_view' pk=item.id %}">{{ item.name }}</a></td>
|
||||||
|
<td>{% if item.is_global %}Global{% else %}{{ item.organization }}{% endif %}</td>
|
||||||
|
<td><a href="{% url 'Settings:_software_category_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">« 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 »</a>
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -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_software_category_create_has_organization():
|
||||||
|
""" Software Category must be assigned an organization """
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip(reason="to be written")
|
||||||
|
def test_software_category_edit_has_organization():
|
||||||
|
""" Software Category must be assigned an organization """
|
||||||
|
pass
|
@ -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_software_category_auth_view(user):
|
||||||
|
""" Check correct permission for view """
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip(reason="to be written")
|
||||||
|
def test_software_category_auth_add(user):
|
||||||
|
""" Check correct permission for add """
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip(reason="to be written")
|
||||||
|
def test_software_category_auth_change(user):
|
||||||
|
""" Check correct permission for change """
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip(reason="to be written")
|
||||||
|
def test_software_category_auth_delete(user):
|
||||||
|
""" Check correct permission for delete """
|
||||||
|
pass
|
@ -1,8 +1,8 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from .views import home, device_types
|
from .views import home, device_types, software_categories
|
||||||
|
|
||||||
from itam.views import device_type
|
from itam.views import device_type, software_category
|
||||||
|
|
||||||
app_name = "Settings"
|
app_name = "Settings"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
@ -14,4 +14,9 @@ urlpatterns = [
|
|||||||
path("device_type/add/", device_type.Add.as_view(), name="_device_type_add"),
|
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"),
|
path("device_type/<int:pk>/delete", device_type.Delete.as_view(), name="_device_type_delete"),
|
||||||
|
|
||||||
|
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>/delete", software_category.Delete.as_view(), name="_software_category_delete"),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
@ -3,6 +3,7 @@ from django.db.models import Q
|
|||||||
from django.views import generic
|
from django.views import generic
|
||||||
|
|
||||||
|
|
||||||
|
from access.mixin import OrganizationPermission
|
||||||
from itam.models.device import DeviceType
|
from itam.models.device import DeviceType
|
||||||
|
|
||||||
|
|
||||||
|
36
app/settings/views/software_categories.py
Normal file
36
app/settings/views/software_categories.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
|
from django.views import generic
|
||||||
|
|
||||||
|
from access.mixin import OrganizationPermission
|
||||||
|
|
||||||
|
from itam.models.software import SoftwareCategory
|
||||||
|
|
||||||
|
|
||||||
|
class Index(PermissionRequiredMixin, OrganizationPermission, generic.ListView):
|
||||||
|
|
||||||
|
model = SoftwareCategory
|
||||||
|
|
||||||
|
permission_required = 'itam.view_software'
|
||||||
|
|
||||||
|
template_name = 'settings/software_categories.html.j2'
|
||||||
|
|
||||||
|
context_object_name = "list"
|
||||||
|
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
|
||||||
|
if self.request.user.is_superuser:
|
||||||
|
|
||||||
|
return self.model.objects.filter().order_by('name')
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
return self.model.objects.filter(organization=self.user_organizations()).order_by('name')
|
||||||
|
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
|
context['content_title'] = 'Software Categories'
|
||||||
|
|
||||||
|
return context
|
Reference in New Issue
Block a user