Browse Source

Merge pull request #203 from interlegis/199-barcode_comprovante

199 - barcode para comprovante de Protocolo
pull/207/merge
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
84b3a647d1
  1. 1
      protocoloadm/urls.py
  2. 17
      protocoloadm/views.py
  3. 17
      sapl/utils.py
  4. 10
      templates/protocoloadm/comprovante.html

1
protocoloadm/urls.py

@ -1,4 +1,5 @@
from django.conf.urls import include, url
from protocoloadm.views import (AnularProtocoloAdmView,
ComprovanteProtocoloView,
DetailDocumentoAdministrativo,

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

17
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)

10
templates/protocoloadm/comprovante.html

@ -36,8 +36,14 @@
<tr> <td colspan="2" align="center"><b>COMPROVANTE DE PROTOCOLO</b></td> </tr>
<tr>
<td>Código de Barra</td>
<td align="center">Autenticação ??</td>
<td>
<center>
<img src="{{barcode}}" height="50px" width="170px">
<br>
{{ protocolo.numero|stringformat:'06d' }}
</center>
</td>
<td align="center">Autenticação: {{ autenticacao }}</td>
</tr>
<tr>

Loading…
Cancel
Save