split the various lists into seperate pages

This commit is contained in:
Andreas Zweili 2017-12-29 12:33:05 +01:00
parent 03adc4b76f
commit 5a30aa8814
6 changed files with 58 additions and 41 deletions

View File

@ -6,7 +6,9 @@
<meta charset="utf-8">
</head>
<body>
<a href="{% url 'index' %}">Home</a>
<a href="{% url 'computers' %}">Computers</a> |
<a href="{% url 'devices' %}">Devices</a> |
<a href="{% url 'cronjobs' %}">Cron Jobs</a>
<h1>{% block section_title %}Device Inventory{% endblock %}</h1>
{% block content %}{% endblock %}
<footer>

View File

@ -0,0 +1,18 @@
{% extends "inventory/base.html" %}
{% block content %}
{% if computer_list %}
<h3>Computer List</h3>
<table class="sortable">
<tr>
<th>Hostname</th>
<th>IP</th>
</tr>
{% for computer in computer_list %}
<tr>
<td><a href="{% url 'computer' computer.id %}">{{ computer.name }}</a></td>
<td>{{ computer.ip }}</td>
</tr>
{% endfor %}
</table>
{% endif %}
{% endblock %}

View File

@ -1,27 +1,6 @@
{% extends "inventory/base.html" %}
{% block content %}
{% if device_list or computer_list %}
<h3>Device List</h3>
<ul>
{% for device in device_list %}
<li><a href="{% url 'device' device.id %}">{{ device.name }}</a></li>
{% endfor %}
</ul>
<h3>Computer List</h3>
<table class="sortable">
<tr>
<th>Hostname</th>
<th>IP</th>
</tr>
{% for computer in computer_list %}
<tr>
<td><a href="{% url 'computer' computer.id %}">{{ computer.name }}</a></td>
<td>{{ computer.ip }}</td>
</tr>
{% endfor %}
</table>
{% endif %}
{% if cronjob_list %}
{% if cronjob_list %}
<h3>Cron Job List</h3>
<table class="sortable">
<tr>

View File

@ -0,0 +1,11 @@
{% extends "inventory/base.html" %}
{% block content %}
{% if device_list %}
<h3>Device List</h3>
<ul>
{% for device in device_list %}
<li><a href="{% url 'device' device.id %}">{{ device.name }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}

View File

@ -1,9 +1,9 @@
from django.conf.urls import url
from . import views
from inventory import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^$', views.ComputerList.as_view(), name='computers'),
url(r'^device/(?P<device_id>[0-9]+)/$',
views.device_details,
name='device'),
@ -13,4 +13,6 @@ urlpatterns = [
url(r'^cronjob/(?P<cronjob_id>[0-9]+)/$',
views.cronjob_details,
name='cronjob'),
url(r'^cronjobs/$', views.CronJobList.as_view(), name='cronjobs'),
url(r'^devices/$', views.DeviceList.as_view(), name='devices'),
]

View File

@ -1,20 +1,9 @@
from django.shortcuts import get_object_or_404, render
from .models import (GeneralDevice, Computer, CronJob,
ComputerRamRelation,
ComputerDiskRelation,
ComputerCpuRelation)
def index(request):
device_list = GeneralDevice.objects.all()
computer_list = Computer.objects.all().order_by('ip')
cronjob_list = CronJob.objects.all().order_by('host')
return render(request,
'inventory/index.html',
{'device_list': device_list,
'computer_list': computer_list,
'cronjob_list': cronjob_list})
from django.views.generic import ListView
from inventory.models import (GeneralDevice, Computer, CronJob,
ComputerRamRelation,
ComputerDiskRelation,
ComputerCpuRelation)
def device_details(request, device_id):
@ -41,3 +30,19 @@ def cronjob_details(request, cronjob_id):
cronjob = get_object_or_404(CronJob, pk=cronjob_id)
return render(request, 'inventory/cronjob_details.html',
{'cronjob': cronjob})
class ComputerList(ListView):
model = Computer
template_name = 'inventory/computer_list.html'
class CronJobList(ListView):
model = CronJob
template_name = 'inventory/cronjob_list.html'
class DeviceList(ListView):
model = GeneralDevice
context_object_name = 'device_list'
template_name = 'inventory/device_list.html'