Refactored container types list views to new style.
This commit is contained in:
parent
1267e8a587
commit
6e8c2de3df
|
@ -1,21 +1,75 @@
|
|||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}Container: {{ container.named_id }}{% endblock %}
|
||||
{% block title %}Container Type List{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
{% if container_type_list %}
|
||||
<div>New Container Types:</div>
|
||||
<ul>
|
||||
{% for ctype in container_type_list %}
|
||||
<li><a href="{% url 'container:container_type_detail' ctype.id %}">{{ ctype.named_id }} {{ ctype.description }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<table class="table table-striped table-hover">
|
||||
<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 %}
|
||||
<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 %}
|
||||
</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 |<<</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 }}">>>| {{ 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>
|
||||
</nav>
|
||||
{% else %}
|
||||
<p>No container types are available.</p>
|
||||
{% endif %}
|
||||
</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 %}
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from django.urls import path
|
||||
|
||||
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'
|
||||
urlpatterns = [
|
||||
path('', ContainerListView.as_view(), name='list'),
|
||||
|
@ -11,5 +12,7 @@ urlpatterns = [
|
|||
path('type/', ContainerTypeListView.as_view(), name='container_type_list'),
|
||||
path('type/<int:pk>/', ContainerTypeDetailView.as_view(), name='container_type_detail'),
|
||||
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'),
|
||||
]
|
||||
|
||||
|
|
|
@ -73,3 +73,20 @@ class ContainerTypeCreateView(generic.CreateView):
|
|||
form.instance.changed_by = self.request.user
|
||||
form.instance.created_by = self.request.user
|
||||
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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue