Example #1
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)
Example #2
0
        response = django.http.HttpResponse(ocpcarest.getCutout(webargs), content_type="image/tiff" )
        response['Content-Disposition'] = "attachment; filename={}ocpcutout.tif".format(fname)
        return response
      elif service in ['zip']:
        return django.http.HttpResponse(ocpcarest.getCutout(webargs), content_type="product/zip" )
      elif service in ['id','ids']:
        return django.http.HttpResponse(ocpcarest.getCutout(webargs))
      else:
        logger.warning("HTTP Bad request. Could not find service {}".format(service))
        return django.http.HttpResponseBadRequest("Could not find service {}".format(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", content_type='text/html')
      else:
        logger.warning("HTTP Bad request. Could not find service {}".format(service))
        return django.http.HttpResponseBadRequest("Could not find service {}".format(service))

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

  except OCPCAError, e:
    return django.http.HttpResponseNotFound(e.value)
  except MySQLdb.Error, e:
    return django.http.HttpResponseNotFound(e)
  except Exception, e:
    logger.exception("Unknown exception in getCutout.")
Example #3
0
                                                content_type="product/zip")
            elif service in ['id', 'ids']:
                return django.http.HttpResponse(ocpcarest.getCutout(webargs))
            else:
                logger.warning(
                    "HTTP Bad request. Could not find service {}".format(
                        service))
                return django.http.HttpResponseBadRequest(
                    "Could not find service {}".format(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",
                                                content_type='text/html')
            else:
                logger.warning(
                    "HTTP Bad request. Could not find service {}".format(
                        service))
                return django.http.HttpResponseBadRequest(
                    "Could not find service {}".format(service))

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