def grafica(request): print "Genero el PDF[grafica]" response = HttpResponse(content_type='application/pdf') pdf_name = "Grafica.pdf" # llamado clientes # la linea 26 es por si deseas descargar el pdf a tu computadora response['Content-Disposition'] = 'attachment; filename=%s' % pdf_name buff = BytesIO() doc = SimpleDocTemplate( buff, pagesize=letter, rightMargin=40, leftMargin=40, topMargin=60, bottomMargin=18, ) courses = [] styles = getSampleStyleSheet() header = Paragraph("Total de Cursos", styles['Heading2']) courses.append(header) styles = getSampleStyleSheet() d = Drawing(600, 300) conteo = Course.objects.count() # for i in Course.objects.all(): # print conteo data = [(conteo, )] bc = VerticalBarChart() bc.x = 50 bc.y = 50 bc.height = 200 bc.width = 300 bc.data = data bc.strokeColor = colors.blue bc.valueAxis.valueMin = 0 bc.valueAxis.valueMax = 10 bc.valueAxis.valueStep = 1 #paso de distancia entre punto y punto bc.categoryAxis.labels.boxAnchor = 'ne' bc.categoryAxis.labels.dx = 8 bc.categoryAxis.labels.dy = -2 bc.categoryAxis.labels.angle = 30 bc.categoryAxis.categoryNames = ['Cursos'] bc.groupSpacing = 10 bc.barSpacing = 2 d.add(bc) pprint.pprint(bc.getProperties()) courses.append(d) doc.build(courses) response.write(buff.getvalue()) buff.close() return response
def reporte4_pdf(request, pk_proyecto): from reportlab.graphics.shapes import Drawing, Rect, String, Group, Line from reportlab.graphics.charts.barcharts import VerticalBarChart proy = Proyecto.objects.get(id=pk_proyecto) story = [] estilo = getSampleStyleSheet() import pprint estiloHoja = getSampleStyleSheet() cabecera = estiloHoja['Heading2'] cabecera.pageBreakBefore = 0 cabecera.keepWithNext = 0 cabecera.backColor = colors.white cabecera.spaceAfter = 0 cabecera.spaceBefore = 0 parrafo = Paragraph('', cabecera) story.append(parrafo) parrafo = Paragraph('CUARTO INFORME DEL' + '"' + proy.nombre_largo + '" : ', cabecera) story.append(parrafo) parrafo = Paragraph('_' * 66, cabecera) story.append(parrafo) cabecera2 = estiloHoja['Heading2'] cabecera2.pageBreakBefore = 0 cabecera2.keepWithNext = 0 cabecera2.backColor = colors.white parrafo = Paragraph( 'GRAFICO DE TIEMPO ESTIMADO Y EJECUTADO POR SPRINT DEL PROYECTO' + '"' + proy.nombre_largo + '"', cabecera2) story.append(parrafo) d = Drawing(400, 200) sprints = Sprint.objects.filter(proyecto=proy) print sprints listasprint = [] listaplan = [] listaejec = [] for sp in sprints: listasprint.append(sp.nombre) US = UserStory.objects.filter(sprint=sp) print US tarea = Tarea.objects.filter(user_story_id= US) totalus = 0 sumatarea = 0 for u in US: totalus += u.estimacion for t in tarea: sumatarea += t.horas_de_trabajo listaejec.append(totalus) listaplan.append(sumatarea) mayor = 0 for j in listaejec: if j > mayor: mayor = j for j in listaplan: if j > mayor: mayor = j data = [listaplan, listaejec] 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 = mayor + 10 bc.valueAxis.valueStep = 10 #paso de distancia entre punto y punto bc.categoryAxis.labels.boxAnchor = 'ne' bc.categoryAxis.labels.dx = 8 bc.categoryAxis.labels.dy = -2 bc.categoryAxis.labels.angle = 30 bc.categoryAxis.categoryNames = listasprint bc.groupSpacing = 10 bc.barSpacing = 2 d.add(bc) pprint.pprint(bc.getProperties()) story.append(d) cabecera2 = estiloHoja['Heading2'] cabecera2.pageBreakBefore = 0 cabecera2.keepWithNext = 0 cabecera2.backColor = colors.white parrafo = Paragraph('ROJO = TIEMPO ESTIMADO', cabecera2) story.append(parrafo) cabecera2 = estiloHoja['Heading2'] cabecera2.pageBreakBefore = 0 cabecera2.keepWithNext = 0 cabecera2.backColor = colors.white parrafo = Paragraph('VERDE = TIEMPO EJECUTADO', cabecera2) story.append(parrafo) story.append(Spacer(0, 20)) parrafo = Paragraph('_' * 66, cabecera) story.append(parrafo) #parrafo = Paragraph('FIN DE CUARTO INFORME' + ' ' * 100 + '(' + str(datetime.date.today()) + ')', cabecera) parrafo = Paragraph('FIN DE CUARTO INFORME', cabecera) story.append(parrafo) buff = BytesIO() doc = SimpleDocTemplate(buff, pagesize=letter, rightMargin=40, leftMargin=40, topMargin=60, bottomMargin=18, ) doc.build(story) response = HttpResponse(content_type='application/pdf') pdf_name = "Reporte.pdf" response.write(buff.getvalue()) buff.close() return response