From 1267e8a587c686f5f8227fd626b88c8807a0e183 Mon Sep 17 00:00:00 2001 From: Dirk Jahnke Date: Thu, 17 Mar 2022 10:27:31 +0100 Subject: [PATCH] Refactored container views to new style. --- asset/templates/asset/asset_list.html | 3 +- asset/urls.py | 3 +- asset/views.py | 4 +- .../templates/container/container_edit.html | 32 -------- .../templates/container/container_form.html | 18 +++++ .../templates/container/container_index.html | 33 -------- .../templates/container/container_list.html | 74 ++++++++++++++++++ ...pe_index.html => container_type_list.html} | 0 container/urls.py | 18 ++--- container/views.py | 75 +++++++++++++------ homelog/templates/homelog/home.html | 4 +- 11 files changed, 161 insertions(+), 103 deletions(-) delete mode 100644 container/templates/container/container_edit.html create mode 100644 container/templates/container/container_form.html delete mode 100644 container/templates/container/container_index.html create mode 100644 container/templates/container/container_list.html rename container/templates/container/{container_type_index.html => container_type_list.html} (100%) diff --git a/asset/templates/asset/asset_list.html b/asset/templates/asset/asset_list.html index 73f6385..649566e 100644 --- a/asset/templates/asset/asset_list.html +++ b/asset/templates/asset/asset_list.html @@ -5,7 +5,6 @@ {% block content %}
-
New Assets:
{% if asset_list %} @@ -16,7 +15,7 @@ {% for asset in asset_list %} - + diff --git a/asset/urls.py b/asset/urls.py index 75e384a..b5d4bac 100644 --- a/asset/urls.py +++ b/asset/urls.py @@ -6,9 +6,8 @@ app_name = 'asset' urlpatterns = [ path('', AssetListView.as_view(), name='list'), path('add/', AssetCreateView.as_view(), name='add'), - path('/', AssetUpdateView.as_view(), name='asset-update'), + path('/', AssetUpdateView.as_view(), name='update'), path('/', AssetUpdateView.as_view(), name='detail'), - path('/save', views.asset_save, name='asset-save'), path('/delete/', AssetDeleteView.as_view(), name='delete'), ] diff --git a/asset/views.py b/asset/views.py index 0c079db..b4cf42e 100644 --- a/asset/views.py +++ b/asset/views.py @@ -27,7 +27,7 @@ class AssetUpdateView(UpdateView): class AssetDeleteView(DeleteView): model = Asset - success_url = reverse_lazy('asset-index') + success_url = reverse_lazy('asset:list') class AssetListView(generic.ListView): @@ -48,4 +48,4 @@ def asset_save(request, asset_id): asset.description = request.POST['description'] asset.quantity = request.POST['quantity'] asset.save(); - return HttpResponseRedirect(reverse('asset:index')) + return HttpResponseRedirect(reverse('asset:list')) diff --git a/container/templates/container/container_edit.html b/container/templates/container/container_edit.html deleted file mode 100644 index ecf3a9d..0000000 --- a/container/templates/container/container_edit.html +++ /dev/null @@ -1,32 +0,0 @@ -{% extends "base.html" %} -{% load static %} - -{% block title %}Edit Container: {{ object.named_id }}{% endblock %} - -{% block content %} -
- -
-
- -

Container: {{ container.named_id }}

-
{{ container.description }}
-
Color: {{ container.color }}
- -
-
- - -
- -
- Edit - Delete -
- -
- - -
-{% endblock content %} - diff --git a/container/templates/container/container_form.html b/container/templates/container/container_form.html new file mode 100644 index 0000000..02e26a7 --- /dev/null +++ b/container/templates/container/container_form.html @@ -0,0 +1,18 @@ +{% extends "base.html" %} +{% load static %} + +{% block title %}Edit Container: {{ container.named_id }}{% endblock %} + +{% block content %} +
+
+{% csrf_token %} + {{ form.as_p }} + + + +
+{% endblock content %} diff --git a/container/templates/container/container_index.html b/container/templates/container/container_index.html deleted file mode 100644 index d61d75a..0000000 --- a/container/templates/container/container_index.html +++ /dev/null @@ -1,33 +0,0 @@ -{% extends "base.html" %} -{% load static %} - -{% block title %}Container: {{ container.named_id }}{% endblock %} - -{% block content %} -
-
New Container:
- {% if container_list %} - - {% else %} -

No container are available.

- {% endif %} -
-
- {% if container_type_list %} -
New Container Types:
- -
- {% else %} -

No container types are available.

- {% endif %} - -{% endblock content %} - diff --git a/container/templates/container/container_list.html b/container/templates/container/container_list.html new file mode 100644 index 0000000..d3f464d --- /dev/null +++ b/container/templates/container/container_list.html @@ -0,0 +1,74 @@ +{% extends "base.html" %} +{% load static %} + +{% block title %}Container: {{ container.named_id }}{% endblock %} + +{% block content %} +
+ {% if container_list %} +
{{ asset.named_id }}: {{ asset.description }}
{{ asset.named_id }}: {{ asset.description }}
{{ asset.quantity }} Delete
+ + + + + + + + + + + + + + {% for container in container_list %} + + + + + + + + + + + {% endfor %} + +
ContainerTypeSize (mm)CoverColorDescriptionChangedAction
{{ container.named_id }}
{{ container.container_type.named_id }}
{{ container.container_type.width }}x{{ container.container_type.length }}x{{ container.container_type.height }}
{% if container.container_type.has_cover %}yes{%else %}--{% endif %}
{{ container.color }}
{{ container.description }}
{{ container.changed_ts | date:'H:i:s d.m.Y' }}
Delete
+ + {% else %} +

No new assets are available.

+ {% endif %} +
+
+ +
+ + + +
+ + + +{% endblock content %} + diff --git a/container/templates/container/container_type_index.html b/container/templates/container/container_type_list.html similarity index 100% rename from container/templates/container/container_type_index.html rename to container/templates/container/container_type_list.html diff --git a/container/urls.py b/container/urls.py index e43b6cd..7e84868 100644 --- a/container/urls.py +++ b/container/urls.py @@ -1,15 +1,15 @@ from django.urls import path -from . import views - +from container.views import ContainerListView, ContainerUpdateView, ContainerCreateView, ContainerDetailView, ContainerDeleteView +from container.views import ContainerTypeListView, ContainerTypeDetailView, ContainerTypeCreateView app_name = 'container' urlpatterns = [ - path('', views.IndexView.as_view(), name='index'), - path('/', views.DetailView.as_view(), name='detail'), - path('edit//', views.EditView.as_view(), name='edit'), - path('delete//', views.DeleteView.as_view(), name='delete'), - path('add/', views.AddView.as_view(), name='add'), - path('type/', views.TypeIndexView.as_view(), name='container_type_index'), - path('type//', views.TypeDetailView.as_view(), name='container_type_detail'), + path('', ContainerListView.as_view(), name='list'), + path('add/', ContainerCreateView.as_view(), name='add'), + path('edit//', ContainerUpdateView.as_view(), name='update'), + path('delete//', ContainerDeleteView.as_view(), name='delete'), + path('type/', ContainerTypeListView.as_view(), name='container_type_list'), + path('type//', ContainerTypeDetailView.as_view(), name='container_type_detail'), + path('type/add/', ContainerTypeCreateView.as_view(), name='container_type_add'), ] diff --git a/container/views.py b/container/views.py index fef7737..0913786 100644 --- a/container/views.py +++ b/container/views.py @@ -1,42 +1,75 @@ -from django.shortcuts import render -from django.http import HttpResponse -from django.template import loader -from django.http import Http404 -from django.urls import reverse from django.views import generic - from .models import Container, ContainerType -class IndexView(generic.ListView): - template_name = 'container/container_index.html' - context_object_name = 'container_list' +class ContainerListView(generic.ListView): + model = Container + template_name = 'container/container_list.html' + context_object_name = 'container_list' + paginate_by = 20 + + ''' def get_queryset(self): # Return the last five created containers return Container.objects.order_by('-created_ts')[:5] + ''' -class TypeIndexView(generic.ListView): - template_name = 'container/container_type_index.html' + +class ContainerCreateView(generic.CreateView): + model = Container + # template_name = 'container/detail.html' + fields = ['named_id', 'description', 'color', 'container_type'] + + def form_valid(self, form): + form.instance.changed_by = self.request.user + form.instance.created_by = self.request.user + return super().form_valid(form) + + +class ContainerUpdateView(generic.UpdateView): + model = Container + # template_name = 'container/detail.html' + fields = ['named_id', 'description', 'color', 'container_type'] + + def form_valid(self, form): + form.instance.changed_by = self.request.user + return super().form_valid(form) + + +class ContainerDetailView(generic.DetailView): + model = Container + + +class ContainerDeleteView(generic.DetailView): + model = Container + + +class ContainerTypeListView(generic.ListView): + template_name = 'container/container_type_list.html' context_object_name = 'container_type_list' + paginate_by = 20 + model = ContainerType + ''' def get_queryset(self): # Return the last five created container types return ContainerType.objects.order_by('-created_ts')[:5] + ''' -class DetailView(generic.DetailView): - model = Container - # template_name = 'container/detail.html' -class TypeDetailView(generic.DetailView): +class ContainerTypeDetailView(generic.DetailView): model = ContainerType context_object_name = 'container_type' template_name = 'container/container_type_detail.html' -class EditView(generic.DetailView): - model = Container -class DeleteView(generic.DetailView): - model = Container +class ContainerTypeCreateView(generic.CreateView): + model = ContainerType + # template_name = 'container/detail.html' + fields = ['named_id', 'description', 'width', 'length', 'height', 'inner_width', 'inner_length', 'inner_height', + 'has_cover', 'contains_container'] -class AddView(generic.DetailView): - model = Container + def form_valid(self, form): + form.instance.changed_by = self.request.user + form.instance.created_by = self.request.user + return super().form_valid(form) diff --git a/homelog/templates/homelog/home.html b/homelog/templates/homelog/home.html index e7a5317..420782d 100644 --- a/homelog/templates/homelog/home.html +++ b/homelog/templates/homelog/home.html @@ -4,8 +4,8 @@ {% block content %}

This is HOME

-Container Types
-Container
+Container Types
+Container
Assets