From 7e872958a6f1ff205c29da07e8ed7937527b8889 Mon Sep 17 00:00:00 2001 From: VictorFabreF Date: Tue, 19 Dec 2017 14:31:49 -0200 Subject: [PATCH] 1615 codigo de barras (#1648) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixes #1646 * Fixes #1615 * Gera código de barras no recibo de envio de proposição --- sapl/materia/views.py | 8 +++++++- sapl/templates/materia/recibo_proposicao.html | 1 + sapl/utils.py | 10 +++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index f21a8d64d..4f2e35b59 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -826,8 +826,14 @@ class ReciboProposicaoView(TemplateView): # FIXME hash para textos articulados _hash = 'P' + ta.hash() + '/' + str(proposicao.id) + from sapl.utils import create_barcode + base64_data = create_barcode(_hash, 100, 2000) + barcode = 'data:image/png;base64,{0}'.format(base64_data) + + context.update({'proposicao': proposicao, - 'hash': _hash}) + 'hash': _hash, + 'barcode': barcode}) return context def get(self, request, *args, **kwargs): diff --git a/sapl/templates/materia/recibo_proposicao.html b/sapl/templates/materia/recibo_proposicao.html index a2ec81039..a839250f9 100644 --- a/sapl/templates/materia/recibo_proposicao.html +++ b/sapl/templates/materia/recibo_proposicao.html @@ -67,5 +67,6 @@


________________________________________________________________ {{proposicao.autor}} + {% endblock detail_content %} diff --git a/sapl/utils.py b/sapl/utils.py index 6e690eb5e..1569cedca 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -230,17 +230,17 @@ def get_base_url(request): return "{0}://{1}".format(protocol, current_domain) -def create_barcode(value): +def create_barcode(value, width=170, height=50): ''' creates a base64 encoded barcode PNG image ''' from base64 import b64encode from reportlab.graphics.barcode import createBarcodeDrawing - + value_bytes = bytes(value, "ascii") barcode = createBarcodeDrawing('Code128', - value=value, - barWidth=170, - height=50, + value=value_bytes, + barWidth=width, + height=height, fontSize=2, humanReadable=True) data = b64encode(barcode.asString('png'))