コード例 #1
0
ファイル: views.py プロジェクト: gilsondev/sigi
def run(request, file):
    birt   = BirtReport(BIRT_REPORT_DIR + file)
    params = birt.getReportParams()
    
    if params != {}:
        return render_to_response('birt/birtForm.html', {'birt': birt, 'params': params})
    
    return HttpResponse('<html><body>Deu a louca ' + str(params) + '</body></html>')
コード例 #2
0
ファイル: views.py プロジェクト: gilsondev/sigi
def show(request):
    if not request.POST.has_key('reportFileName'):
        raise Http404
    
    rptFileName = request.POST['reportFileName']
    birt        = BirtReport(rptFileName)
    
    if not birt.rptExists():
        raise Http404
    
    if os.environ.has_key('BIRT_HOME'):
        birt_home = os.environ['BIRT_HOME']
    else:
        return HttpResponseServerError('Serviço não instalado ou indisponível.')
    
    params = ''
    
    for pName in birt.getReportParams():
        if request.POST.has_key(pName):
            params += '"%s=%s" ' % (pName, request.POST[pName])
        else:
            params += '"%s=%s" ' % (pName, '')

    output   = os.tempnam()
    fileName = os.path.split(rptFileName)[1]
    fileName = os.path.splitext(fileName)[0]

    if (request.POST['submit'] == 'Ver na tela'):
        format   = 'HTML'
        mimeType = 'text/html'
        contentDisposition = ''
    else:
        format = 'PDF'
        mimeType = 'application/pdf'
        contentDisposition = 'attachment; filename=%s.pdf' % fileName

    fileName = output + '/' + fileName + '.' + format
    
    cmd = '%s/ReportEngine/genReport.sh -f %s -p %s -o %s %s' % (birt_home, format, params, output, rptFileName)
    os.system(cmd)
    
    if not os.path.isfile(fileName):
        return HttpResponseServerError('Servidor não conseguiu produzir o relatório: %s' % fileName)
    
    resultFile = open(fileName)
    result     = resultFile.read()
    resultFile.close()
    
    response = HttpResponse(mimetype=mimeType)
    response['Content-Disposition'] = contentDisposition
    response.write(result)
              
    return response