diff --git a/protocoloadm/urls.py b/protocoloadm/urls.py index 4b7dd33e1..bc6d094d7 100644 --- a/protocoloadm/urls.py +++ b/protocoloadm/urls.py @@ -1,4 +1,5 @@ from django.conf.urls import include, url + from protocoloadm.views import (AnularProtocoloAdmView, ComprovanteProtocoloView, DetailDocumentoAdministrativo, diff --git a/protocoloadm/views.py b/protocoloadm/views.py index e398f9e89..34156ac95 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -17,6 +17,7 @@ from vanilla import GenericView import sapl from materia.models import Proposicao, TipoMateriaLegislativa from sapl.crud import build_crud +from sapl.utils import create_barcode from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, ProposicaoSimpleForm, ProtocoloDocumentForm, ProtocoloForm, @@ -321,7 +322,21 @@ 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(numero.zfill(6)) + barcode = 'data:image/png;base64,{0}'.format(base64_data) + + autenticacao = "** NULO **" + + if not protocolo.anulado: + autenticacao = str(protocolo.tipo_processo) + \ + protocolo.data.strftime("%y/%m/%d") + \ + str(protocolo.numero).zfill(6) + + return self.render_to_response({"protocolo": protocolo, + "barcode": barcode, + "autenticacao": autenticacao}) class ProtocoloMateriaView(FormMixin, GenericView): diff --git a/sapl/utils.py b/sapl/utils.py index c27a2cc37..1ede6eabf 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -32,6 +32,23 @@ def xstr(s): return '' if s is None else str(s) +def create_barcode(value): + ''' + creates a base64 encoded barcode PNG image + ''' + from base64 import b64encode + 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..43a2c02f2 100644 --- a/templates/protocoloadm/comprovante.html +++ b/templates/protocoloadm/comprovante.html @@ -36,8 +36,14 @@ COMPROVANTE DE PROTOCOLO - Código de Barra - Autenticação ?? + +
+ +
+ {{ protocolo.numero|stringformat:'06d' }} +
+ + Autenticação: {{ autenticacao }}