Пример #1
0
    def get_context_data(self, **kwargs):
        context = super(ComprovanteProtocoloView,
                        self).get_context_data(**kwargs)
        protocolo = Protocolo.objects.get(pk=self.kwargs['pk'])
        # numero is string, padd with zeros left via .zfill()
        base64_data = create_barcode(str(protocolo.numero).zfill(6))
        barcode = 'data:image/png;base64,{0}'.format(base64_data)

        autenticacao = _("** NULO **")

        if not protocolo.anulado:
            if protocolo.timestamp:
                data = protocolo.timestamp.strftime("%Y/%m/%d")
            else:
                data = protocolo.data.strftime("%Y/%m/%d")

            # data is not i18n sensitive 'Y-m-d' is the right format.
            autenticacao = str(protocolo.tipo_processo) + \
                data + str(protocolo.numero).zfill(6)

        context.update({
            "protocolo": protocolo,
            "barcode": barcode,
            "autenticacao": autenticacao
        })
        return context
Пример #2
0
def protocolo_pre_save(sender, instance, using, **kwargs):
    logger = logging.getLogger(__name__)

    import inspect
    funcs = list(
        filter(lambda x: x == 'revision_pre_delete_signal',
               map(lambda x: x[3], inspect.stack())))

    if funcs:
        return

    if hasattr(instance, 'not_send_mail') and instance.not_send_mail:
        return
    if instance.email and instance.conteudo_protocolado:
        try:
            if instance.timestamp:
                data = instance.timestamp.strftime("%Y/%m/%d")
            else:
                data = instance.data.strftime("%Y/%m/%d")

            base64_data = create_barcode(str(instance.numero).zfill(6))
            barcode = 'data:image/png;base64,{0}'.format(base64_data)
            autenticacao = str(instance.tipo_processo) + \
                data + str(instance.numero).zfill(6)

            if not settings.DEBUG:
                send_mail(
                    'Protocolo: {}'.format(instance.epigrafe),
                    'email/comprovante_protocolo.html', {
                        'protocolo': instance,
                        'barcode': barcode,
                        'autenticacao': autenticacao
                    }, EMAIL_SEND_USER,
                    instance.email)  # '*****@*****.**')  #
            else:
                send_mail(
                    'Protocolo: {}'.format(instance.epigrafe),
                    'email/comprovante_protocolo.html', {
                        'protocolo': instance,
                        'barcode': barcode,
                        'autenticacao': autenticacao
                    }, EMAIL_SEND_USER, '*****@*****.**')  #

            logger.info('Um Email com comprovante de protocolo foi enviado '
                        '%s - email: %s - interessado: %s' %
                        (instance.pk, instance.email, instance.interessado))

            instance.comprovante_automatico_enviado = True
        except Exception as e:
            logger.error("""
                Erro no envio de email de comprovante de protocolo.
                para: {} 
                {}
                {}
                --------------------
                {}
                """.format(instance.email, instance,
                           instance.conteudo_protocolado, e))
Пример #3
0
    def get_context_data(self, **kwargs):
        context = super(ComprovanteProtocoloView, self).get_context_data(
            **kwargs)
        protocolo = Protocolo.objects.get(pk=self.kwargs['pk'])
        # numero is string, padd with zeros left via .zfill()
        base64_data = create_barcode(str(protocolo.numero).zfill(6))
        barcode = 'data:image/png;base64,{0}'.format(base64_data)

        autenticacao = _("** NULO **")

        if not protocolo.anulado:
            # data is not i18n sensitive 'Y-m-d' is the right format.
            autenticacao = str(protocolo.tipo_processo) + \
                protocolo.data.strftime("%Y/%m/%d") + \
                str(protocolo.numero).zfill(6)

        context.update({"protocolo": protocolo,
                        "barcode": barcode,
                        "autenticacao": autenticacao})
        return context