Exemplo n.º 1
0
def decode_dashboards(o):
    """
    Function to be passed into json.loads obj_hook parameter
    Recreates the dashboard object from a json representation.
    """
    import superset.models.core as models
    from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn

    if "__Dashboard__" in o:
        return models.Dashboard(**o["__Dashboard__"])
    elif "__Slice__" in o:
        return models.Slice(**o["__Slice__"])
    elif "__TableColumn__" in o:
        return TableColumn(**o["__TableColumn__"])
    elif "__SqlaTable__" in o:
        return SqlaTable(**o["__SqlaTable__"])
    elif "__SqlMetric__" in o:
        return SqlMetric(**o["__SqlMetric__"])
    elif "__datetime__" in o:
        return datetime.strptime(o["__datetime__"], "%Y-%m-%dT%H:%M:%S")
    else:
        return o
Exemplo n.º 2
0
def decode_dashboards(o):
    """
    Function to be passed into json.loads obj_hook parameter
    Recreates the dashboard object from a json representation.
    """
    import superset.models.core as models
    from superset import security_manager
    from superset.connectors.sqla.models import (
        SqlaTable,
        SqlMetric,
        TableColumn,
    )

    if '__Dashboard__' in o:
        return models.Dashboard(**o['__Dashboard__'])
    elif '__Slice__' in o:
        return models.Slice(**o['__Slice__'])
    elif '__TableColumn__' in o:
        return TableColumn(**o['__TableColumn__'])
    elif '__SqlaTable__' in o:
        return SqlaTable(**o['__SqlaTable__'])
    elif '__SqlMetric__' in o:
        return SqlMetric(**o['__SqlMetric__'])
    elif '__Database__' in o:
        return models.Database(**o['__Database__'])
    elif '__User__' in o:
        return security_manager.user_model(**o['__User__'])
    elif '__Role__' in o:
        return security_manager.role_model(**o['__Role__'])
    elif '__ViewMenu__' in o:
        return security_manager.viewmenu_model(**o['__ViewMenu__'])
    elif '__PermissionView__' in o:
        return security_manager.permissionview_model(**o['__PermissionView__'])
    elif '__datetime__' in o:
        return datetime.strptime(o['__datetime__'], '%Y-%m-%dT%H:%M:%S')
    else:
        return o
Exemplo n.º 3
0
def decode_dashboards(o):
    """
    Function to be passed into json.loads obj_hook parameter
    Recreates the dashboard object from a json representation.
    """
    import superset.models.core as models
    from superset.connectors.sqla.models import (
        SqlaTable,
        SqlMetric,
        TableColumn,
    )

    if '__Dashboard__' in o:
        d = models.Dashboard()
        d.__dict__.update(o['__Dashboard__'])
        return d
    elif '__Slice__' in o:
        d = models.Slice()
        d.__dict__.update(o['__Slice__'])
        return d
    elif '__TableColumn__' in o:
        d = TableColumn()
        d.__dict__.update(o['__TableColumn__'])
        return d
    elif '__SqlaTable__' in o:
        d = SqlaTable()
        d.__dict__.update(o['__SqlaTable__'])
        return d
    elif '__SqlMetric__' in o:
        d = SqlMetric()
        d.__dict__.update(o['__SqlMetric__'])
        return d
    elif '__datetime__' in o:
        return datetime.strptime(o['__datetime__'], '%Y-%m-%dT%H:%M:%S')
    else:
        return o