Refactored container views to new style.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user