From 76614428dd27652378c39a61ff58584336ceeaf7 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Tue, 16 Feb 2016 19:13:19 -0200 Subject: [PATCH 1/4] Add barcode to comprovante de protocolo --- protocoloadm/views.py | 9 ++++++++- sapl/utils.py | 11 +++++++++++ templates/protocoloadm/comprovante.html | 6 +++++- 3 files changed, 24 insertions(+), 2 deletions(-) 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 ?? From 058d2c94c1d4777940d38c6e12b10bc862a49899 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Tue, 16 Feb 2016 19:23:30 -0200 Subject: [PATCH 2/4] Make QA check happy --- protocoloadm/urls.py | 1 + protocoloadm/views.py | 6 +++--- sapl/utils.py | 9 ++++++--- templates/protocoloadm/comprovante.html | 6 ++++-- 4 files changed, 14 insertions(+), 8 deletions(-) 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 fefe90656..8fe0a1fd3 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -1,5 +1,3 @@ -from sapl.utils import create_barcode_128_as_base64_png - from datetime import date, datetime from re import sub @@ -19,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_128_as_base64_png from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, ProposicaoSimpleForm, ProtocoloDocumentForm, ProtocoloForm, @@ -328,7 +327,8 @@ class ComprovanteProtocoloView(TemplateView): 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}) + return self.render_to_response({"protocolo": protocolo, + "barcode": barcode}) class ProtocoloMateriaView(FormMixin, GenericView): diff --git a/sapl/utils.py b/sapl/utils.py index d702a79b7..8cf0f453e 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -34,11 +34,14 @@ def xstr(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) + barcode = createBarcodeDrawing('Code128', + value=value, + barWidth=170, + height=50, + fontSize=2, + humanReadable=True) data = b64encode(barcode.asString('png')) return data.decode('utf-8') diff --git a/templates/protocoloadm/comprovante.html b/templates/protocoloadm/comprovante.html index 20ed3ae5b..d85823a66 100644 --- a/templates/protocoloadm/comprovante.html +++ b/templates/protocoloadm/comprovante.html @@ -36,11 +36,13 @@ COMPROVANTE DE PROTOCOLO -
+ +

{{ protocolo.numero|stringformat:'06d' }} -
+
+ Autenticação ?? From a934462545195e017d5bde32fa6c9414d51640a0 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Wed, 17 Feb 2016 07:42:01 -0200 Subject: [PATCH 3/4] Refactor function name and add doc string --- protocoloadm/views.py | 4 ++-- sapl/utils.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 8fe0a1fd3..9e20d93d7 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -17,7 +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_128_as_base64_png +from sapl.utils import create_barcode from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, ProposicaoSimpleForm, ProtocoloDocumentForm, ProtocoloForm, @@ -324,7 +324,7 @@ class ComprovanteProtocoloView(TemplateView): protocolo = Protocolo.objects.get(ano=ano, numero=numero) # numero is string, padd with zeros left via .zfill() - base64_data = create_barcode_128_as_base64_png(numero.zfill(6)) + base64_data = create_barcode(numero.zfill(6)) barcode = 'data:image/png;base64,{0}'.format(base64_data) return self.render_to_response({"protocolo": protocolo, diff --git a/sapl/utils.py b/sapl/utils.py index 8cf0f453e..1ede6eabf 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -32,7 +32,10 @@ def xstr(s): return '' if s is None else str(s) -def create_barcode_128_as_base64_png(value): +def create_barcode(value): + ''' + creates a base64 encoded barcode PNG image + ''' from base64 import b64encode from reportlab.graphics.barcode import createBarcodeDrawing From ba92000dc9b74b00ae92a28d6523995e1d743fac Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Wed, 17 Feb 2016 07:58:23 -0200 Subject: [PATCH 4/4] =?UTF-8?q?Adiciona=20c=C3=B3digo=20de=20autentica?= =?UTF-8?q?=C3=A7=C3=A3o=20ao=20comprovante?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocoloadm/views.py | 10 +++++++++- templates/protocoloadm/comprovante.html | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 9e20d93d7..34156ac95 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -327,8 +327,16 @@ class ComprovanteProtocoloView(TemplateView): 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}) + "barcode": barcode, + "autenticacao": autenticacao}) class ProtocoloMateriaView(FormMixin, GenericView): diff --git a/templates/protocoloadm/comprovante.html b/templates/protocoloadm/comprovante.html index d85823a66..43a2c02f2 100644 --- a/templates/protocoloadm/comprovante.html +++ b/templates/protocoloadm/comprovante.html @@ -43,7 +43,7 @@ {{ protocolo.numero|stringformat:'06d' }} - Autenticação ?? + Autenticação: {{ autenticacao }}