【BI报表】Superset二开相关接口文档

记录一下Superset二开相关接口信息,方便后面查询

图表配置保存接口

【BI报表】Superset二开相关接口文档_第1张图片

接口地址

/superset/explore/?form_data=%7B%22slice_id%22%3A1%7D&slice_id=1&action=overwrite&slice_name=demo&save_to_dashboard_id=1

源码文件地址

根目录\superset\views\core.py

源码及部分截图

 @has_access
    @event_logger.log_this
    @expose("/explore///", methods=["GET", "POST"])
    @expose("/explore/", methods=["GET", "POST"])
    @expose("/explore/p//", methods=["GET"])
    # pylint: disable=too-many-locals,too-many-branches,too-many-statements
    def explore(
        self,
        datasource_type: Optional[str] = None,
        datasource_id: Optional[int] = None,
        key: Optional[str] = None,
    ) -> FlaskResponse:
        initial_form_data = {}

        form_data_key = request.args.get("form_data_key")

【BI报表】Superset二开相关接口文档_第2张图片

保存与更新


        if action == "saveas" and slice_add_perm:
            ChartDAO.save(slc)
            msg = _("Chart [{}] has been saved").format(slc.slice_name)
            flash(msg, "success")
        elif action == "overwrite" and slice_overwrite_perm:
            ChartDAO.overwrite(slc)
            msg = _("Chart [{}] has been overwritten").format(slc.slice_name)
            flash(msg, "success")

添加数据集

【BI报表】Superset二开相关接口文档_第3张图片

接口地址

/api/v1/dataset/

{database: 1, schema: "datacollect", table_name: "cgmx_out"}
database: 1
schema: "datacollect"
table_name: "cgmx_out"}

源码文件地址

根目录\superset\views\core.py

源码及部分截图

数据DAO

源码文件地址

\superset\dao\base.py

源码及部分截图

create
@classmethod
    def create(cls, properties: Dict[str, Any], commit: bool = True) -> Model:
        """
        Generic for creating models
        :raises: DAOCreateFailedError
        """
        if cls.model_cls is None:
            raise DAOConfigError()
        model = cls.model_cls()  # pylint: disable=not-callable
        for key, value in properties.items():
            setattr(model, key, value)
        try:
            db.session.add(model)
            if commit:
                db.session.commit()
        except SQLAlchemyError as ex:  # pragma: no cover
            db.session.rollback()
            raise DAOCreateFailedError(exception=ex) from ex
        return model

save
    @classmethod
    def save(cls, instance_model: Model, commit: bool = True) -> Model:
        """
        Generic for saving models
        :raises: DAOCreateFailedError
        """
        if cls.model_cls is None:
            raise DAOConfigError()
        if not isinstance(instance_model, cls.model_cls):
            raise DAOCreateFailedError(
                "the instance model is not a type of the model class"
            )
        try:
            db.session.add(instance_model)
            if commit:
                db.session.commit()
        except SQLAlchemyError as ex:  # pragma: no cover
            db.session.rollback()
            raise DAOCreateFailedError(exception=ex) from ex
        return instance_model

update
 @classmethod
    def update(
        cls, model: Model, properties: Dict[str, Any], commit: bool = True
    ) -> Model:
        """
        Generic update a model
        :raises: DAOCreateFailedError
        """
        for key, value in properties.items():
            setattr(model, key, value)
        try:
            db.session.merge(model)
            if commit:
                db.session.commit()
        except SQLAlchemyError as ex:  # pragma: no cover
            db.session.rollback()
            raise DAOUpdateFailedError(exception=ex) from ex
        return model
delete
@classmethod
    def delete(cls, model: Model, commit: bool = True) -> Model:
        """
        Generic delete a model
        :raises: DAODeleteFailedError
        """
        try:
            db.session.delete(model)
            if commit:
                db.session.commit()
        except SQLAlchemyError as ex:  # pragma: no cover
            db.session.rollback()
            raise DAODeleteFailedError(exception=ex) from ex
        return model

你可能感兴趣的:(Python,软件研发,前端,python,大数据)