diff --git a/protocoloadm/views.py b/protocoloadm/views.py index e398f9e89..fefe90656 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -1,3 +1,5 @@ +from sapl.utils import create_barcode_128_as_base64_png + from datetime import date, datetime from re import sub @@ -321,7 +323,12 @@ class ComprovanteProtocoloView(TemplateView): numero = self.kwargs['pk'] ano = self.kwargs['ano'] protocolo = Protocolo.objects.get(ano=ano, numero=numero) - return self.render_to_response({"protocolo": protocolo}) + + # numero is string, padd with zeros left via .zfill() + base64_data = create_barcode_128_as_base64_png(numero.zfill(6)) + barcode = 'data:image/png;base64,{0}'.format(base64_data) + + return self.render_to_response({"protocolo": protocolo, "barcode": barcode}) class ProtocoloMateriaView(FormMixin, GenericView): diff --git a/sapl/utils.py b/sapl/utils.py index c27a2cc37..d702a79b7 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -32,6 +32,17 @@ def xstr(s): return '' if s is None else str(s) +def create_barcode_128_as_base64_png(value): + from base64 import b64encode + from reportlab.pdfgen import canvas + from reportlab.lib.units import mm, inch + from reportlab.graphics.barcode import createBarcodeDrawing + + barcode = createBarcodeDrawing('Code128', value = value, barWidth = 170, height=50, fontSize = 2, humanReadable = True) + data = b64encode(barcode.asString('png')) + return data.decode('utf-8') + + def make_choices(*choice_pairs): assert len(choice_pairs) % 2 == 0 ipairs = iter(choice_pairs) diff --git a/templates/protocoloadm/comprovante.html b/templates/protocoloadm/comprovante.html index d08057ddb..20ed3ae5b 100644 --- a/templates/protocoloadm/comprovante.html +++ b/templates/protocoloadm/comprovante.html @@ -36,7 +36,11 @@ COMPROVANTE DE PROTOCOLO - Código de Barra +
+ +
+ {{ protocolo.numero|stringformat:'06d' }} +
Autenticação ??