from flask_appbuilder import Model from sqlalchemy import Text from sqlalchemy import UniqueConstraint from flask import g from myapp import app from myapp.models.helpers import ImportMixin from sqlalchemy import Column, Integer, String from flask import Markup from myapp.models.base import MyappModelBase metadata = Model.metadata conf = app.config class Dimension_table(Model,ImportMixin,MyappModelBase): __tablename__ = 'dimension' __table_args__ = (UniqueConstraint('sqllchemy_uri', 'table_name'),) id = Column(Integer, primary_key=True) sqllchemy_uri = Column(String(255),nullable=True) table_name = Column(String(255),nullable=True,unique=True) label = Column(String(255), nullable=True) describe = Column(String(2000), nullable=True) app = Column(String(255), nullable=True) owner = Column(String(2000), nullable=True,default='') columns=Column(Text, nullable=True,default='{}') status = Column(Integer, default=1) @property def table_html(self): users='' users = users+self.owner if self.owner else users users = users.split(',') users = [user.strip() for user in users if user.strip()] url_path = conf.get('MODEL_URLS',{}).get("dimension") if g.user.is_admin() or g.user.username in users or '*' in self.owner: return Markup(f'{self.table_name}') else: return self.table_name @property def operate_html(self): url=''' 创建远程表 | 建外表示例 | 清空表记录 '''%(self.id,self.id,self.id) return Markup(url)