示例#1
0
def downloaddata(request):
  
  try:
    pd = ocpcaproj.OCPCAProjectsDB()
    
    if request.method == 'POST':
      #import pdb;pdb.set_trace()                                                       
      form= dataUserForm(request.POST)
      if form.is_valid():
        curtoken=request.POST.get('token')
        if curtoken=="other":
          curtoken=request.POST.get('other')
          
        format = form.cleaned_data['format']
        resolution = form.cleaned_data['resolution']
        xmin=form.cleaned_data['xmin']
        xmax=form.cleaned_data['xmax']
        ymin=form.cleaned_data['ymin']
        ymax=form.cleaned_data['ymax']
        zmin=form.cleaned_data['zmin']
        zmax=form.cleaned_data['zmax']
        webargs= curtoken+"/"+format+"/"+str(resolution)+"/"+str(xmin)+","+str(xmax)+"/"+str(ymin)+","+str(ymax)+"/"+str(zmin)+","+str(zmax)+"/"
          
        if format=='hdf5':
          return django.http.HttpResponse(ocpcarest.getCutout(webargs), mimetype="product/hdf5" )
        elif format=='npz':
          return django.http.HttpResponse(ocpcarest.getCutout(webargs), mimetype="product/npz" )
        else:
          return django.http.HttpResponse(ocpcarest.getCutout(webargs), mimetype="product/zip" )
          
      else:
        return redirect(downloaddata)
        #return render_to_response('download.html',context_instance=RequestContext(request))
    else:
      # Load Download page with public tokens                                           
      pd = ocpcaproj.OCPCAProjectsDB()
      form = dataUserForm()
      tokens = pd.getPublic ()
      context = {'form': form ,'publictokens': tokens}
      return render_to_response('download.html',context,context_instance=RequestContext(request))
      #return render_to_response('download.html', { 'dts': datasets },context_instance=\
          #         RequestContext(request))                                                                
  except OCPCAError, e:
    #return django.http.HttpResponseNotFound(e.value)                                   
    messages.error(request, e.value)
    #form = dataUserForm()                                                              
    tokens = pd.getPublic ()
    return redirect(downloaddata)
示例#2
0
def cutout (request, webargs):
  """Restful URL for all read services to annotation projects"""

  [ token , sym, cutoutargs ] = webargs.partition ('/')
  [ service, sym, rest ] = cutoutargs.partition ('/')

  try:
    # GET methods
    if request.method == 'GET':
      if service in GET_SLICE_SERVICES:
        return django.http.HttpResponse(ocpcarest.getCutout(webargs), mimetype="image/png" )
      elif service == 'ts':
        return django.http.HttpResponse(ocpcarest.getCutout(webargs), mimetype="product/hdf5" )
      elif service=='hdf5':
        return django.http.HttpResponse(ocpcarest.getCutout(webargs), mimetype="product/hdf5" )
      elif service=='npz':
        return django.http.HttpResponse(ocpcarest.getCutout(webargs), mimetype="product/npz" )
      elif service=='zip':
        return django.http.HttpResponse(ocpcarest.getCutout(webargs), mimetype="product/zip" )
      elif service in GET_ANNO_SERVICES:
        return django.http.HttpResponse(ocpcarest.getCutout(webargs), mimetype="image/png" )
      elif service=='id':
        return django.http.HttpResponse(ocpcarest.getCutout(webargs))
      elif service=='ids':
        return django.http.HttpResponse(ocpcarest.getCutout(webargs))
      else:
        logger.warning ("HTTP Bad request. Could not find service %s" % service )
        return django.http.HttpResponseBadRequest ("Could not find service %s" % service )

    # RBTODO control caching?
    # POST methods
    elif request.method == 'POST':
      if service in POST_SERVICES:
        django.http.HttpResponse(ocpcarest.putCutout(webargs,request.body))
        return django.http.HttpResponse ("Success", mimetype='text/html')
      else:
        logger.warning ("HTTP Bad request. Could not find service %s" % service )
        return django.http.HttpResponseBadRequest ("Could not find service %s" % service )

    else:
      logger.warning ("Invalid HTTP method %s.  Not GET or POST." % request.method )
      return django.http.HttpResponseBadRequest ("Invalid HTTP method %s.  Not GET or POST." % request.method )

  except OCPCAError, e:
    return django.http.HttpResponseNotFound(e.value)
示例#3
0
文件: views.py 项目: j6k4m8/ndstore
  try:
    m = re.match(r"(\w+)/(?P<channel>[\w+,/-]+)?/?(xy|xz|yz|tiff|hdf5|jpeg|blosc|npz|zip|id|ids|xyanno|xzanno|yzanno)/([\w,/-]+)$", webargs)
    [token, channel, service, cutoutargs] = [i for i in m.groups()]

    if channel is None:
      webargs = '{}/default/{}/{}'.format(token, service, cutoutargs)

  except Exception, e:
    logger.warning("Incorrect format for arguments {}. {}".format(webargs, e))
    raise OCPCAError("Incorrect format for arguments {}. {}".format(webargs, e))

  try:
    # GET methods
    if request.method == 'GET':
      if service in GET_SLICE_SERVICES+GET_ANNO_SERVICES:
        return django.http.HttpResponse(ocpcarest.getCutout(webargs), content_type="image/png" )
      elif service in ['hdf5']:
        fname = re.sub ( r',','_', webargs )
        fname = re.sub ( r'/','-', fname )
        response = django.http.HttpResponse(ocpcarest.getCutout(webargs), content_type="product/hdf5" )
        response['Content-Disposition'] = "attachment; filename={}ocpcutout.h5".format(fname)
        return response
      elif service in ['blosc']:
        fname = re.sub ( r',','_', webargs )
        fname = re.sub ( r'/','-', fname )
        response = django.http.HttpResponse(ocpcarest.getCutout(webargs), content_type="product/blosc" )
        response['Content-Disposition'] = "attachment; filename={}ocpcutout.blosc".format(fname)
        return response
      elif service in ['jpeg']:
        fname = re.sub ( r',','_', webargs )
        fname = re.sub ( r'/','-', fname )
示例#4
0
        [token, channel, service, cutoutargs] = [i for i in m.groups()]

        if channel is None:
            webargs = '{}/default/{}/{}'.format(token, service, cutoutargs)

    except Exception, e:
        logger.warning("Incorrect format for arguments {}. {}".format(
            webargs, e))
        raise OCPCAError("Incorrect format for arguments {}. {}".format(
            webargs, e))

    try:
        # GET methods
        if request.method == 'GET':
            if service in GET_SLICE_SERVICES + GET_ANNO_SERVICES:
                return django.http.HttpResponse(ocpcarest.getCutout(webargs),
                                                content_type="image/png")
            elif service in ['hdf5']:
                fname = re.sub(r',', '_', webargs)
                fname = re.sub(r'/', '-', fname)
                response = django.http.HttpResponse(
                    ocpcarest.getCutout(webargs), content_type="product/hdf5")
                response[
                    'Content-Disposition'] = "attachment; filename={}ocpcutout.h5".format(
                        fname)
                return response
            elif service in ['blosc']:
                fname = re.sub(r',', '_', webargs)
                fname = re.sub(r'/', '-', fname)
                response = django.http.HttpResponse(
                    ocpcarest.getCutout(webargs), content_type="product/blosc")