#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.shortcuts import render
from django.http.response import HttpResponse
from reportlab.pdfgen import canvas
from reportlab.graphics.shapes import Drawing
from reportlab.graphics.charts.barcharts import VerticalBarChart
from reportlab.lib import colors
from reportlab.graphics import renderPDF

def persona(request,id):
    if 'pdf' in request.GET:
        response = HttpResponse(content_type='application/pdf')
        response['Content-Disposition'] = 'inline; filename="persona_%s.pdf"'%id
        p=canvas.Canvas(response)
        drawing = Drawing(400, 200)
        data = [(13, 5, 20, 22, 37, 45, 19, 4),(14, 6, 21, 23, 38, 46, 20, 5)]
        bc = VerticalBarChart()
        bc.x = 50
        bc.y = 50
        bc.height = 125
        bc.width = 300
        bc.data = data
        bc.strokeColor = colors.black
        bc.valueAxis.valueMin = 0
        bc.valueAxis.valueMax = 50
        bc.valueAxis.valueStep = 10
        bc.categoryAxis.labels.boxAnchor = 'ne'
        bc.categoryAxis.labels.dx = 8
        bc.categoryAxis.labels.dy = -2
        bc.categoryAxis.labels.angle = 30
        bc.categoryAxis.categoryNames = ['Jan-99','Feb-99','Mar-99','Apr-99','May-99','Jun-99','Jul-99','Aug-99']
        drawing.add(bc)
        renderPDF.draw(drawing,p,100,480)
        p.showPage()
        p.save()
        return response
    else:
        return HttpResponse("la informacion de la persona %s" %id)
def informacion_depuracion(request):
    return HttpResponse("Aqui se muestra la informacion de depuracion")
