Browse Source

1615 codigo de barras (#1648)

* Fixes #1646

* Fixes #1615

* Gera código de barras no recibo de envio de proposição
pull/1650/head
VictorFabreF 7 years ago
committed by Edward
parent
commit
7e872958a6
  1. 8
      sapl/materia/views.py
  2. 1
      sapl/templates/materia/recibo_proposicao.html
  3. 10
      sapl/utils.py

8
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):

1
sapl/templates/materia/recibo_proposicao.html

@ -67,5 +67,6 @@
</tr>
<tr> <td align="center"><br /><br /><br /><b>________________________________________________________________</b></td> </tr>
<tr> <td align="center">{{proposicao.autor}}</td> </tr>
<tr> <td align="center"><img src="{{barcode}}"width="600px" height="50px"/></td> </tr>
</table>
{% endblock detail_content %}

10
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'))

Loading…
Cancel
Save