示例#1
0
    def get_charts(self, id_or_slug: str) -> Response:
        """Gets the chart definitions for a given dashboard
        ---
        get:
          description: >-
            Get the chart definitions for a given dashboard
          parameters:
          - in: path
            schema:
              type: string
            name: id_or_slug
          responses:
            200:
              description: Dashboard chart definitions
              content:
                application/json:
                  schema:
                    type: object
                    properties:
                      result:
                        type: array
                        items:
                          $ref: '#/components/schemas/ChartEntityResponseSchema'
            302:
              description: Redirects to the current digest
            400:
              $ref: '#/components/responses/400'
            401:
              $ref: '#/components/responses/401'
            403:
              $ref: '#/components/responses/403'
            404:
              $ref: '#/components/responses/404'
        """
        try:
            charts = DashboardDAO.get_charts_for_dashboard(id_or_slug)
            result = [
                self.chart_entity_response_schema.dump(chart)
                for chart in charts
            ]

            if is_feature_enabled("REMOVE_SLICE_LEVEL_LABEL_COLORS"):
                # dashboard metadata has dashboard-level label_colors,
                # so remove slice-level label_colors from its form_data
                for chart in result:
                    form_data = chart.get("form_data")
                    form_data.pop("label_colors", None)

            return self.response(200, result=result)
        except DashboardAccessDeniedError:
            return self.response_403()
        except DashboardNotFoundError:
            return self.response_404()
示例#2
0
 def get_charts(self, pk: int) -> Response:
     """Gets the chart definitions for a given dashboard
     ---
     get:
       description: >-
         Get the chart definitions for a given dashboard
       parameters:
       - in: path
         schema:
           type: integer
         name: pk
       responses:
         200:
           description: Dashboard chart definitions
           content:
             application/json:
               schema:
                 type: object
                 properties:
                   result:
                     type: array
                     items:
                       $ref: '#/components/schemas/ChartEntityResponseSchema'
         302:
           description: Redirects to the current digest
         400:
           $ref: '#/components/responses/400'
         401:
           $ref: '#/components/responses/401'
         404:
           $ref: '#/components/responses/404'
     """
     try:
         charts = DashboardDAO.get_charts_for_dashboard(pk)
         result = [
             self.chart_entity_response_schema.dump(chart)
             for chart in charts
         ]
         return self.response(200, result=result)
     except DashboardNotFoundError:
         return self.response_404()