Create label image for container
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
<div class="row">
|
||||
|
||||
<div class="col-sm-12">
|
||||
<a class="btn btn-primary" href="{% url 'container:edit' container.id %}" role="button">Edit</a>
|
||||
<a class="btn btn-primary" href="{% url 'container:update' container.id %}" role="button">Edit</a>
|
||||
<a class="btn btn-primary" href="{% url 'container:delete' container.id %}" role="button">Delete</a>
|
||||
</div>
|
||||
|
||||
|
@@ -29,7 +29,11 @@
|
||||
<td><div>{{ container.color }}</div></td>
|
||||
<td><div>{{ container.description }}</div></td>
|
||||
<td><div>{{ container.changed_ts | date:'H:i:s d.m.Y' }}</div></td>
|
||||
<td><a class="btn btn-outline-primary btn-sm" href="{% url 'container:delete' container.id %}" role="button">Delete</a></td>
|
||||
<td>
|
||||
<a class="btn btn-outline-primary btn-sm" href="{% url 'container:delete' container.id %}" role="button">Delete</a>
|
||||
<a class="btn btn-outline-primary btn-sm" href="{% url 'container:detail' container.id %}" role="button">View</a>
|
||||
<a class="btn btn-outline-primary btn-sm" href="{% url 'container:print_label' container.id %}" role="button">Label</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
22
container/templates/container/container_print_label.html
Normal file
22
container/templates/container/container_print_label.html
Normal file
@@ -0,0 +1,22 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}Container: {{ container.named_id }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
===== Print Label Content =====
|
||||
|
||||
<!-- Action buttons -->
|
||||
<div class="row">
|
||||
|
||||
<div class="col-sm-12">
|
||||
Label created for container {{ container.named_id }} of type {{ container.container_type.named_id }}
|
||||
<br />
|
||||
<img class="img-fluid shadow p-3 mb-5 bg-body rounded" src="{{ barcode_img }}">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- End Action buttons -->
|
||||
|
||||
</div>
|
||||
{% endblock content %}
|
@@ -1,13 +1,15 @@
|
||||
from django.urls import path
|
||||
|
||||
from container.views import ContainerListView, ContainerUpdateView, ContainerCreateView, ContainerDetailView, ContainerDeleteView
|
||||
from container.views import ContainerListView, ContainerUpdateView, ContainerCreateView, ContainerDetailView, ContainerDeleteView, ContainerPrintLabelView
|
||||
from container.views import ContainerTypeListView, ContainerTypeDetailView, ContainerTypeCreateView, ContainerTypeUpdateView, ContainerTypeDeleteView
|
||||
|
||||
app_name = 'container'
|
||||
urlpatterns = [
|
||||
path('', ContainerListView.as_view(), name='list'),
|
||||
path('<int:pk>/', ContainerDetailView.as_view(), name='detail'),
|
||||
path('add/', ContainerCreateView.as_view(), name='add'),
|
||||
path('edit/<int:pk>/', ContainerUpdateView.as_view(), name='update'),
|
||||
path('label/<int:pk>/', ContainerPrintLabelView.as_view(), name='print_label'),
|
||||
path('delete/<int:pk>/', ContainerDeleteView.as_view(), name='delete'),
|
||||
path('type/', ContainerTypeListView.as_view(), name='container_type_list'),
|
||||
path('type/<int:pk>/', ContainerTypeDetailView.as_view(), name='container_type_detail'),
|
||||
|
@@ -1,6 +1,7 @@
|
||||
from django.views import generic
|
||||
from .models import Container, ContainerType
|
||||
from blabel import LabelWriter
|
||||
from labelprinter.labels import container_label
|
||||
|
||||
|
||||
class ContainerListView(generic.ListView):
|
||||
model = Container
|
||||
@@ -48,13 +49,36 @@ class ContainerPrintLabelView(generic.DetailView):
|
||||
model = Container
|
||||
template_name = 'container/container_print_label.html'
|
||||
|
||||
def get(self, **kwargs):
|
||||
super().get(kwargs)
|
||||
def get(self, request, **kwargs):
|
||||
context = super().get(request, **kwargs)
|
||||
'''
|
||||
label_writer = LabelWriter(
|
||||
'templates/label/container_label.html',
|
||||
default_stylesheets=("templates/label/label_style.css",)
|
||||
"container/templates/label/container_label.html",
|
||||
default_stylesheets=("container/templates/label/label_style.css",)
|
||||
)
|
||||
label_writer.write_labels(kwargs['pk'], target="container_label.pdf")
|
||||
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):
|
||||
@@ -101,4 +125,3 @@ class ContainerTypeUpdateView(generic.UpdateView):
|
||||
|
||||
class ContainerTypeDeleteView(generic.DetailView):
|
||||
model = ContainerType
|
||||
|
||||
|
Reference in New Issue
Block a user