How can I generate a report with reportlab from a view? [closed]

1

What I'm looking for is to generate a report from the following view:

class CuentaCondominioView(TemplateView):

    template_name = 'administrador/cuenta_condominio.html'

    def dispatch(self, request, *args, **kwargs):
        if request.user.id:
            usuarioIngreso = Usuario.objects.get(id=request.user.id)
            if usuarioIngreso.rol == 1:
                return redirect(settings.LOGIN_URL)
            return super(self.__class__, self).dispatch(request, *args, **kwargs)
        else:
                return redirect(settings.LOGIN_URL)

    def get_context_data(self, **kwargs):
        if kwargs.get('condominio'):
            usuario=self.request.user.id
            uc=Usuario.objects.get(pk=usuario)
            fuente=uc.condominio_asociado
        if kwargs.get('administrador'):
            fuente=kwargs.get('pk')
        context = super(CuentaCondominioView, self).get_context_data(**kwargs)

        try:
            context['condominio'] = Condominio.objects.get(pk=fuente)
            context['cuenta'] = CuentaCondominio.objects.get(condominio_id=context['condominio'].id)
            temp = Transaccion.objects.filter(CuentaCondominio_id=context['cuenta'].id)[:1]        
            context['ultimopago'] = Transaccion.objects.get(pk=temp)
        except Transaccion.DoesNotExist:
            context['ultimopago'] = 0            
        except Condominio.DoesNotExist:
            context['condominio'] = 0
        try:
            context['usuarios'] = Usuario.objects.filter(condominio_asociado=context['condominio'].id)
        except Usuario.DoesNotExist:
            context['usuarios'] = 0
        try:
            reserva=FondoReservaCondominio.objects.filter(condominio_id=context['condominio'].id).latest('id')
            context['saldo_reserva'] = reserva.saldo
        except FondoReservaCondominio.DoesNotExist:
            context['saldo_reserva'] = 0
        return context

This view calls a template where I have a button called "Generate pdf", this calls a function or view called CuentaPdf, what I want is that this button generates a pdf from the CuentaCondominioView view without having to repeat the same logic which he uses to consult the data. Thanks

    
asked by Saul Valecillos 09.07.2016 в 21:00
source

0 answers