homelog/container/views.py

105 lines
3.1 KiB
Python
Raw Normal View History

from django.views import generic
2022-03-09 17:13:09 +00:00
from .models import Container, ContainerType
2022-03-24 14:54:04 +00:00
from blabel import LabelWriter
class ContainerListView(generic.ListView):
model = Container
template_name = 'container/container_list.html'
context_object_name = 'container_list'
paginate_by = 20
2022-03-09 17:13:09 +00:00
'''
def get_queryset(self):
# Return the last five created containers
return Container.objects.order_by('-created_ts')[:5]
'''
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
2022-03-24 14:54:04 +00:00
class ContainerPrintLabelView(generic.DetailView):
model = Container
template_name = 'container/container_print_label.html'
def get(self, **kwargs):
super().get(kwargs)
label_writer = LabelWriter(
'templates/label/container_label.html',
default_stylesheets=("templates/label/label_style.css",)
)
label_writer.write_labels(kwargs['pk'], target="container_label.pdf")
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 ContainerTypeDetailView(generic.DetailView):
model = ContainerType
context_object_name = 'container_type'
template_name = 'container/container_type_detail.html'
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
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 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