2022-03-10 10:33:06 +00:00
|
|
|
from django.views import generic
|
2022-03-09 17:13:09 +00:00
|
|
|
from .models import Container, ContainerType
|
2022-03-09 10:33:05 +00:00
|
|
|
|
2022-03-17 09:27:31 +00:00
|
|
|
|
|
|
|
class ContainerListView(generic.ListView):
|
|
|
|
model = Container
|
|
|
|
template_name = 'container/container_list.html'
|
2022-03-10 10:33:06 +00:00
|
|
|
context_object_name = 'container_list'
|
2022-03-17 09:27:31 +00:00
|
|
|
paginate_by = 20
|
2022-03-09 17:13:09 +00:00
|
|
|
|
2022-03-17 09:27:31 +00:00
|
|
|
'''
|
2022-03-10 10:33:06 +00:00
|
|
|
def get_queryset(self):
|
|
|
|
# Return the last five created containers
|
|
|
|
return Container.objects.order_by('-created_ts')[:5]
|
2022-03-17 09:27:31 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-03-10 10:33:06 +00:00
|
|
|
|
2022-03-17 09:27:31 +00:00
|
|
|
class ContainerDetailView(generic.DetailView):
|
|
|
|
model = Container
|
|
|
|
|
|
|
|
|
|
|
|
class ContainerDeleteView(generic.DetailView):
|
|
|
|
model = Container
|
|
|
|
|
|
|
|
|
|
|
|
class ContainerTypeListView(generic.ListView):
|
|
|
|
template_name = 'container/container_type_list.html'
|
2022-03-10 10:33:06 +00:00
|
|
|
context_object_name = 'container_type_list'
|
2022-03-17 09:27:31 +00:00
|
|
|
paginate_by = 20
|
|
|
|
model = ContainerType
|
2022-03-10 10:33:06 +00:00
|
|
|
|
2022-03-17 09:27:31 +00:00
|
|
|
'''
|
2022-03-10 10:33:06 +00:00
|
|
|
def get_queryset(self):
|
|
|
|
# Return the last five created container types
|
|
|
|
return ContainerType.objects.order_by('-created_ts')[:5]
|
2022-03-17 09:27:31 +00:00
|
|
|
'''
|
2022-03-10 10:33:06 +00:00
|
|
|
|
|
|
|
|
2022-03-17 09:27:31 +00:00
|
|
|
class ContainerTypeDetailView(generic.DetailView):
|
2022-03-10 10:33:06 +00:00
|
|
|
model = ContainerType
|
|
|
|
context_object_name = 'container_type'
|
|
|
|
template_name = 'container/container_type_detail.html'
|
|
|
|
|
|
|
|
|
2022-03-17 09:27:31 +00:00
|
|
|
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']
|
2022-03-09 10:33:05 +00:00
|
|
|
|
2022-03-17 09:27:31 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
form.instance.changed_by = self.request.user
|
|
|
|
form.instance.created_by = self.request.user
|
|
|
|
return super().form_valid(form)
|
2022-03-17 09:42:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|