def GET(self, metricId=None):
        """ Returns a dict sufficient for importing a new model from scratch """
        try:
            if metricId is not None:
                try:
                    with web.ctx.connFactory() as conn:
                        metricRow = (repository.getMetric(
                            conn,
                            metricId,
                            fields=[
                                schema.metric.c.uid, schema.metric.c.datasource
                            ]))
                    nativeMetrics = [self._exportNativeMetric(metricRow)]
                except app_exceptions.ObjectNotFoundError:
                    raise web.notfound("ObjectNotFoundError Metric not found: "
                                       "Metric ID: %s" % metricId)
            else:
                with web.ctx.connFactory() as conn:
                    metricRowList = repository.getAllModels(conn)
                if metricRowList:
                    nativeMetrics = [
                        self._exportNativeMetric(metricRow)
                        for metricRow in metricRowList
                    ]
                else:
                    nativeMetrics = []

            self.addStandardHeaders()

            web.header("Content-Description", "Taurus Export")
            web.header("Expires", "0")
            web.header("Cache-Control",
                       "must-revalidate, post-check=0, pre-check=0")

            data = web.input(filename=None)

            if data.filename:
                web.header("Content-Disposition",
                           "attachment;filename=%s" % (data.filename))

            returned = utils.jsonEncode(nativeMetrics)

            web.header("Content-length", len(returned))
            return returned
        except web.HTTPError as ex:
            log.info(str(ex) or repr(ex))
            raise ex
        except Exception as ex:
            log.exception("GET Failed")
            raise web.internalerror(str(ex) or repr(ex))
  def GET(self, metricId=None):
    """ Returns a dict sufficient for importing a new model from scratch """
    try:
      if metricId is not None:
        try:
          with web.ctx.connFactory() as conn:
            metricRow = (
              repository.getMetric(conn,
                                   metricId,
                                   fields=[schema.metric.c.uid,
                                           schema.metric.c.datasource]))
          nativeMetrics = [self._exportNativeMetric(metricRow)]
        except app_exceptions.ObjectNotFoundError:
          raise web.notfound("ObjectNotFoundError Metric not found: "
                             "Metric ID: %s" % metricId)
      else:
        with web.ctx.connFactory() as conn:
          metricRowList = repository.getAllModels(conn)
        if metricRowList:
          nativeMetrics = [self._exportNativeMetric(metricRow)
                           for metricRow in metricRowList]
        else:
          nativeMetrics = []

      self.addStandardHeaders()

      web.header("Content-Description", "Taurus Export")
      web.header("Expires", "0")
      web.header("Cache-Control", "must-revalidate, post-check=0, pre-check=0")

      data = web.input(filename=None)

      if data.filename:
        web.header("Content-Disposition", "attachment;filename=%s" % (
          data.filename))

      returned = utils.jsonEncode(nativeMetrics)

      web.header("Content-length", len(returned))
      return returned
    except web.HTTPError as ex:
      log.info(str(ex) or repr(ex))
      raise ex
    except Exception as ex:
      log.exception("GET Failed")
      raise web.internalerror(str(ex) or repr(ex))
 def getAllModels():
     with web.ctx.connFactory() as conn:
         return repository.getAllModels(conn, getMetricDisplayFields(conn))
 def getAllModels():
   with web.ctx.connFactory() as conn:
     return repository.getAllModels(conn, getMetricDisplayFields(conn))