Spaces:
Runtime error
Runtime error
File size: 1,845 Bytes
1f2a564 5e27e41 1f2a564 5e27e41 1f2a564 5e27e41 1f2a564 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | from abc import abstractmethod
from typing import Optional
import streamlit as st
from sqlalchemy import String, Date, Integer, Double
from sqlalchemy.orm.attributes import InstrumentedAttribute
class StreamlitHelper:
@classmethod
def get_column_configurations(cls):
config = {}
for k in cls.__dict__:
v = cls.__dict__[k]
if isinstance(v, InstrumentedAttribute):
config.update(cls._get_column_configuration(v))
return config
@classmethod
def _get_column_configuration(cls, column):
pre_conf = cls._get_column_configuration0(column)
if pre_conf and len(pre_conf) > 0:
return pre_conf
comment: str = column.comment
disabled = True
if comment and "可修改" in comment:
disabled = False
if isinstance(column.type, String):
return {
column.name: st.column_config.TextColumn(
disabled=disabled, help=comment
)
}
elif isinstance(column.type, Integer) or isinstance(column.type, Double):
return {
column.name: st.column_config.NumberColumn(
disabled=disabled, help=comment
)
}
elif isinstance(column.type, Date):
return {
column.name: st.column_config.DateColumn(
disabled=disabled, help=comment
)
}
else:
return {
column.name: st.column_config.TextColumn(
disabled=disabled, help=comment
)
}
@classmethod
@abstractmethod
def _get_column_configuration0(cls, column) -> Optional[dict]:
pass
|