add AllComputersView

This commit is contained in:
Andreas Zweili 2019-08-02 16:54:32 +02:00
parent 15eea784ac
commit be7cfb7da9
7 changed files with 55 additions and 1 deletions

View File

@ -0,0 +1,9 @@
from django_filters import FilterSet
from .models import Computer
class ComputerFilter(FilterSet):
class Meta:
model = Computer
fields = {"name": ["contains"], "owner": ["exact"]}

View File

@ -0,0 +1,23 @@
{% extends "inventory/base.html" %}
{% load render_table from django_tables2 %}
{% block section_title %}List of Computers{% endblock %}
{% block content %}
<div class="ui form">
<form action="" method="get" class="ui form">
<div class="fields">
<div class="field">
{{ filter.form.name__contains.label_tag }}
{{ filter.form.name__contains }}
</div>
<div class="field">
{{ filter.form.owner.label_tag }}
{{ filter.form.owner }}
</div>
<div class="field">
<button type="submit" class="ui button">Submit</button>
</div>
</div>
</form>
</div>
{% render_table table %}
{% endblock %}

View File

@ -8,6 +8,7 @@
<body> <body>
<div class="ui container"> <div class="ui container">
<a href="{% url 'customers' %}">Home</a> | <a href="{% url 'customers' %}">Home</a> |
<a href="{% url 'all_computers' %}">All Computers</a> |
<h1>{% block section_title %}Device Inventory{% endblock %}</h1> <h1>{% block section_title %}Device Inventory{% endblock %}</h1>
{% block content %}{% endblock %} {% block content %}{% endblock %}
<footer> <footer>

View File

@ -17,4 +17,5 @@ urlpatterns = [
name='nets'), name='nets'),
path('net/<int:pk>/', views.net_detail_view, name='net'), path('net/<int:pk>/', views.net_detail_view, name='net'),
path('backup/<int:pk>/', views.backup_detail_view, name='backup'), path('backup/<int:pk>/', views.backup_detail_view, name='backup'),
path('computers/all/', views.AllComputersView.as_view(), name='all_computers')
] ]

View File

@ -3,12 +3,15 @@ from django.shortcuts import get_object_or_404, render
from django.views.generic import ListView, DetailView from django.views.generic import ListView, DetailView
from guardian.shortcuts import get_objects_for_user from guardian.shortcuts import get_objects_for_user
from django_tables2 import RequestConfig from django_tables2 import RequestConfig
from django_filters.views import FilterView
from django_tables2.views import SingleTableMixin
from .decorators import computer_view_permission from .decorators import computer_view_permission
from .models import (Device, Computer, ComputerRamRelation, from .models import (Device, Computer, ComputerRamRelation,
ComputerDiskRelation, ComputerCpuRelation, ComputerDiskRelation, ComputerCpuRelation,
ComputerSoftwareRelation, Customer, Net, RaidInComputer, ComputerSoftwareRelation, Customer, Net, RaidInComputer,
Backup) Backup)
from .tables import CustomersTable, ComputersTable, DevicesTable, NetsTable, NetDetailTable, BackupDetailTable from .tables import CustomersTable, ComputersTable, DevicesTable, NetsTable, NetDetailTable, BackupDetailTable
from .filters import ComputerFilter
def device_detail_view(request, device_id): def device_detail_view(request, device_id):
@ -80,3 +83,17 @@ def backup_detail_view(request, pk):
table = BackupDetailTable(Backup.objects.filter(pk=pk)) table = BackupDetailTable(Backup.objects.filter(pk=pk))
RequestConfig(request).configure(table) RequestConfig(request).configure(table)
return render(request, 'inventory/backup_details.html', {'backup': table}) return render(request, 'inventory/backup_details.html', {'backup': table})
class AllComputersView(SingleTableMixin, FilterView):
table_class = ComputersTable
model = Computer
template_name = "inventory/all_computers.html"
filterset_class = ComputerFilter
def get_queryset(self):
return get_objects_for_user(self.request.user,
'inventory.view_computer',
klass=Computer)

View File

@ -30,7 +30,8 @@ INSTALLED_APPS = [
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'inventory.apps.InventoryConfig', 'inventory.apps.InventoryConfig',
'guardian', 'guardian',
'django_tables2' 'django_tables2',
'django_filters',
] ]
MIDDLEWARE = [ MIDDLEWARE = [

View File

@ -3,3 +3,5 @@ Django==2.2
pyaml pyaml
pytz pytz
django-guardian django-guardian
django-tables2
django-filter