Refactored container types list views to new style.

This commit is contained in:
Dirk Jahnke 2022-03-17 10:42:20 +01:00
parent 1267e8a587
commit 6e8c2de3df
3 changed files with 83 additions and 9 deletions

View File

@ -1,21 +1,75 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load static %} {% load static %}
{% block title %}Container: {{ container.named_id }}{% endblock %} {% block title %}Container Type List{% endblock %}
{% block content %} {% block content %}
<div class="container"> <div class="container">
{% if container_type_list %} {% if container_type_list %}
<div>New Container Types:</div> <table class="table table-striped table-hover">
<ul> <thead>
<tr>
<th scope="col">Container Type</th>
<th scope="col">Description</th>
<th scope="col">Size (mm)</th>
<th scope="col">Inner Size (mm)</th>
<th scope="col">Cover</th>
<th scope="col">holds Container</th>
<th scope="col">Changed</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
{% for ctype in container_type_list %} {% for ctype in container_type_list %}
<li><a href="{% url 'container:container_type_detail' ctype.id %}">{{ ctype.named_id }} {{ ctype.description }}</a></li> <tr>
<td><a href="{% url 'container:container_type_detail' ctype.id %}"><div>{{ ctype.named_id }}</div></a></td>
<td><div>{{ ctype.description }}</div></td>
<td><div>{% if ctype.width %}{{ ctype.width }}x{{ ctype.length }}x{{ ctype.height }}{% endif %}</div></td>
<td><div>{% if ctype.inner_width %}{{ ctype.inner_width }}x{{ ctype.inner_length }}x{{ ctype.inner_height }}{% endif %}</div></td>
<td><div>{% if ctype.has_cover %}yes{%else %}--{% endif %}</div></td>
<td><div>{% if ctype.contains_container %}yes{%else %}--{% endif %}</div></td>
<td><div>{{ ctype.changed_ts | date:'H:i:s d.m.Y' }}</div></td>
<td><a class="btn btn-outline-primary btn-sm" href="{% url 'container:container_type_delete' ctype.id %}" role="button">Delete</a></td>
</tr>
{% endfor %} {% endfor %}
</tbody>
</table>
<nav aria-label="Page navigation">
<ul class="pagination">
{% if page_obj.has_previous %}
<li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">previous</a></li>
{% else %}
<li class="page-item disabled"><a class="page-link" href="#" aria-disabled="true">previous</a></li>
{% endif %}
<li class="page-item"><a class="page-link" href="?page=1">1 |&lt;&lt;</a></li>
<li class="page-item disabled"><a class="page-link" href="#" aria-disabled="true">...</a></li>
<li class="page-item"><a class="page-link" href="#" aria-disabled="true">{{ page_obj.number }}</a></li>
<li class="page-item disabled"><a class="page-link" href="#" aria-disabled="true">...</a></li>
<li class="page-item"><a class="page-link" href="?page={{ paginator.num_pages }}">&gt;&gt;| {{ paginator.num_pages }}</a></li>
{% if page_obj.has_next %}
<li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">next</a></li>
{% else %}
<li class="page-item disabled"><a class="page-link" href="#" aria-disabled="true">next</a></li>
{% endif %}
</ul> </ul>
</div> </nav>
{% else %} {% else %}
<p>No container types are available.</p> <p>No container types are available.</p>
{% endif %} {% endif %}
</div> </div>
<div class="row p-4"></div>
<!-- Action buttons -->
<div class="row">
<div class="col-sm-12">
<a class="btn btn-primary" href="{% url 'container:container_type_add' %}" role="button">+ Container Type</a>
<a class="btn btn-primary" href="{% url 'container:add' %}" role="button">+ Container</a>
<a class="btn btn-primary" href="{% url 'asset:add' %}" role="button">+ Asset</a>
</div>
</div>
<!-- End Action buttons -->
</div>
{% endblock content %} {% endblock content %}

View File

@ -1,7 +1,8 @@
from django.urls import path from django.urls import path
from container.views import ContainerListView, ContainerUpdateView, ContainerCreateView, ContainerDetailView, ContainerDeleteView from container.views import ContainerListView, ContainerUpdateView, ContainerCreateView, ContainerDetailView, ContainerDeleteView
from container.views import ContainerTypeListView, ContainerTypeDetailView, ContainerTypeCreateView from container.views import ContainerTypeListView, ContainerTypeDetailView, ContainerTypeCreateView, ContainerTypeUpdateView, ContainerTypeDeleteView
app_name = 'container' app_name = 'container'
urlpatterns = [ urlpatterns = [
path('', ContainerListView.as_view(), name='list'), path('', ContainerListView.as_view(), name='list'),
@ -11,5 +12,7 @@ urlpatterns = [
path('type/', ContainerTypeListView.as_view(), name='container_type_list'), path('type/', ContainerTypeListView.as_view(), name='container_type_list'),
path('type/<int:pk>/', ContainerTypeDetailView.as_view(), name='container_type_detail'), path('type/<int:pk>/', ContainerTypeDetailView.as_view(), name='container_type_detail'),
path('type/add/', ContainerTypeCreateView.as_view(), name='container_type_add'), path('type/add/', ContainerTypeCreateView.as_view(), name='container_type_add'),
path('type/edit/<int:pk>/', ContainerTypeUpdateView.as_view(), name='container_type_update'),
path('type/delete/<int:pk>/', ContainerTypeDeleteView.as_view(), name='container_type_delete'),
] ]

View File

@ -73,3 +73,20 @@ class ContainerTypeCreateView(generic.CreateView):
form.instance.changed_by = self.request.user form.instance.changed_by = self.request.user
form.instance.created_by = self.request.user form.instance.created_by = self.request.user
return super().form_valid(form) return super().form_valid(form)
class ContainerTypeUpdateView(generic.UpdateView):
model = ContainerType
# template_name = 'container/detail.html'
fields = ['named_id', 'description', 'width', 'length', 'height', 'inner_width', 'inner_length', 'inner_height',
'has_cover', 'contains_container']
def form_valid(self, form):
form.instance.changed_by = self.request.user
return super().form_valid(form)
class ContainerTypeDeleteView(generic.DetailView):
model = ContainerType