Exemplo n.º 1
0
def preview(self, request, webargs):
    ci = CutoutInfo()
    jhlib = JHTDBLib()
    #Parse web args into cutout info object
    ci=jhlib.parsewebargs(webargs)
    template = loader.get_template('jhtdb/preview.html')
    #Verify token
    #sample link
    #getdata_link = "http://dsp033.pha.jhu.edu:8000/jhtdb/getcutout/edu.jhu.ssh-c11eeb58/isotropic1024coarse/pcvo,/0,1/0,64/0,64/0,64/vtk/"
    #This is kind of a hack, but we have to set the link up properly for the template.
    getdata_link = webargs.replace("cvo", "pcvo")    
    if (jhlib.verify(ci.authtoken)):
        context = RequestContext(request, { 'getdata_link': getdata_link})
        response = HttpResponse(template.render(context))
    else:
        response = HttpResponse("Error: token is invalid")
    return response
Exemplo n.º 2
0
def getcutout(request, webargs):
    ci = CutoutInfo()
    ci.ipaddr = request.META.get('REMOTE_ADDR', '')
    jhlib = JHTDBLib()
    #Parse web args into cutout info object
    ci=jhlib.parsewebargs(webargs)
    numpoints = ci.xlen * ci.ylen * ci.zlen
    if ((numpoints > 16777215) and (ci.filetype == 'hdf5')): #task out anything larger than 256x256x256 and ignore shape
        ipaddr = request.META.get('REMOTE_ADDR', '')
        getcutout = Getbigcutout()
        task = getcutout.delay(webargs, ipaddr)
        #Test without celery
        #getcutout.run(webargs, ipaddr)
        print ("Task id is  ")
        print task.task_id
        print ("From IP: ")
        print ipaddr
        template = loader.get_template('poll_for_download.html')
        #print("returning http response. with task id  %s" % task.task_id)
        html = template.render({'task_id': task.task_id}, request)
        return HttpResponse(html)
    else:
        #Verify token (remove in the future--handled by stored procedure now.
        if (jhlib.verify(ci.authtoken)):
            if (ci.filetype == "vtk"):
                #vtkfile = VTKData().getvtk(ci) #Note: This could be a .vtr, .vti, or .zip depending on the request!
                #Set the filename to the dataset name, and the suffix to the suffix of the temp file
                #response['Content-Disposition'] = 'attachment;filename=' +  ci.dataset +'.' + vtkfile.name.split('.').pop()
                #Since VTK can have different file types, getvtk makes those decisions and returns the HTTP response with the correct file info.
                response = VTKData().getvtk(ci)
            else:
                #Serve up an HDF5 file
                h5file = HDFData().gethdf(ci)
                response = HttpResponse(h5file, content_type='application/x-hdf;subtype=bag')
                attach = 'attachment;filename=' + ci.dataset + '.h5'
                response['Content-Disposition'] = attach
        else:
            response = HttpResponse("Error: token is invalid")
        print ("returing file")
        return response
    print("Shouldn't get here")