45
app/settings/templates/settings/device_models.html.j2
Normal file
45
app/settings/templates/settings/device_models.html.j2
Normal 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> </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">« 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 %}
|
@ -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>
|
||||
|
@ -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"),
|
||||
|
39
app/settings/views/device_models.py
Normal file
39
app/settings/views/device_models.py
Normal 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
|
Reference in New Issue
Block a user