128 lines
4.8 KiB
Python
128 lines
4.8 KiB
Python
from django.views import generic
|
|
from .models import Container, ContainerType
|
|
from labelprinter.labels import container_label
|
|
|
|
|
|
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 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 ContainerPrintLabelView(generic.DetailView):
|
|
model = Container
|
|
template_name = 'container/container_print_label.html'
|
|
|
|
def get(self, request, **kwargs):
|
|
context = super().get(request, **kwargs)
|
|
'''
|
|
label_writer = LabelWriter(
|
|
"container/templates/label/container_label.html",
|
|
default_stylesheets=("container/templates/label/label_style.css",)
|
|
)
|
|
label_writer.write_labels([dict(named_id=kwargs['pk'], id=kwargs['pk'])], target="container_label.pdf")
|
|
'''
|
|
return context
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
from labelprinter.labels import container_label
|
|
container_description = self.object.container_type.named_id
|
|
if len(self.object.container_type.description) > 0:
|
|
container_description += ': ' + self.object.container_type.description
|
|
if len(self.object.description) > 0:
|
|
container_description += ' / ' + self.object.description
|
|
context['barcode_img'] = container_label(self.object.named_id, description=container_description, writer_options={'background': 'white',
|
|
'font_size': 10,
|
|
'foreground': 'black',
|
|
'module_height': 10.0,
|
|
'module_width': 0.2,
|
|
'quiet_zone': 2.5,
|
|
'text': 'This is the text',
|
|
'text_distance': 3.0,
|
|
'write_text': True
|
|
})
|
|
return context
|
|
|
|
|
|
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']
|
|
|
|
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
|