Browse Source

Gera código de barras no recibo de envio de proposição

pull/1648/head
VictorFabreF 8 years ago
parent
commit
99a87df2f1
  1. 8
      sapl/materia/views.py
  2. 1
      sapl/templates/materia/recibo_proposicao.html
  3. 6
      sapl/utils.py

8
sapl/materia/views.py

@ -826,8 +826,14 @@ class ReciboProposicaoView(TemplateView):
# FIXME hash para textos articulados # FIXME hash para textos articulados
_hash = 'P' + ta.hash() + '/' + str(proposicao.id) _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, context.update({'proposicao': proposicao,
'hash': _hash}) 'hash': _hash,
'barcode': barcode})
return context return context
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):

1
sapl/templates/materia/recibo_proposicao.html

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

6
sapl/utils.py

@ -230,7 +230,7 @@ def get_base_url(request):
return "{0}://{1}".format(protocol, current_domain) 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 creates a base64 encoded barcode PNG image
''' '''
@ -239,8 +239,8 @@ def create_barcode(value):
value_bytes = bytes(value, "ascii") value_bytes = bytes(value, "ascii")
barcode = createBarcodeDrawing('Code128', barcode = createBarcodeDrawing('Code128',
value=value_bytes, value=value_bytes,
barWidth=170, barWidth=width,
height=50, height=height,
fontSize=2, fontSize=2,
humanReadable=True) humanReadable=True)
data = b64encode(barcode.asString('png')) data = b64encode(barcode.asString('png'))

Loading…
Cancel
Save