Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def Expedientes_reportes_csv(request):
- # Create the HttpResponse object with the appropriate CSV header.
- if request.method == 'GET':
- fecha1 = request.GET.get('desde')
- fecha2 = request.GET.get('hasta')
- dato = request.GET.get('cuenta')
- tipo = request.GET.get('tipo')
- qs = expediente.objects.all()
- filtros2 = {}
- if fecha1 or fecha2 or dato:
- if fecha1:
- if fecha2:
- filtros2.update({"fecha__range": (fecha1, fecha2)})
- logging.info('Entrada a if para 2 fechas')
- else:
- filtros2.update({"fecha__date": (fecha1)})
- logging.info('Entrada a if para fecha1')
- elif fecha2:
- filtros2.update({"fecha__date": (fecha2)})
- logging.info('Entrada a if para fecha2')
- if dato:
- filtros2.update({"cuenta": (dato)})
- logging.info('dato en elif')
- logging.debug(dato)
- else:
- qs_hoy = qs.filter(fecha__date=date.today())
- logging.info('sin datos a pedir trae por defecto el dia')
- # logging.debug(str(qs_hoy))
- qs_filtrado = qs.filter(**filtros2).order_by('cuenta', 'nsolicitud')
- logging.info('preparacion del queryset')
- logging.debug(str(filtros2))
- # logging.debug(str(qs_filtrado))
- response = HttpResponse(content_type='text/csv')
- response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
- writer = csv.writer(response)
- writer.writerow(['First row', 'Foo', 'Bar', 'Baz'])
- writer.writerow(['Second row', 'A', 'B', 'C', '"Testing"', "Here's a quote"])
- return response
Advertisement
Add Comment
Please, Sign In to add comment