add ordering and change date strategy
This commit is contained in:
parent
6bb4d47eeb
commit
a66a8636fe
4 changed files with 14 additions and 9 deletions
|
|
@ -32,9 +32,13 @@ class ObjectModel(BaseModel):
|
||||||
updated: Optional[datetime] = None
|
updated: Optional[datetime] = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_all(cls: Type[T]) -> List[T]:
|
def get_all(cls: Type[T], order_by=None) -> List[T]:
|
||||||
try:
|
try:
|
||||||
result = repo_query(f"SELECT * FROM {cls.table_name}")
|
if order_by:
|
||||||
|
order = f" ORDER BY {order_by}"
|
||||||
|
else:
|
||||||
|
order = ""
|
||||||
|
result = repo_query(f"SELECT * FROM {cls.table_name} {order}")
|
||||||
objects = []
|
objects = []
|
||||||
for obj in result:
|
for obj in result:
|
||||||
try:
|
try:
|
||||||
|
|
@ -73,6 +77,7 @@ class ObjectModel(BaseModel):
|
||||||
logger.debug(f"Validating {self.__class__.__name__}")
|
logger.debug(f"Validating {self.__class__.__name__}")
|
||||||
self.model_validate(self.model_dump(), strict=True)
|
self.model_validate(self.model_dump(), strict=True)
|
||||||
data = self._prepare_save_data()
|
data = self._prepare_save_data()
|
||||||
|
data["updated"] = datetime.now().isoformat()
|
||||||
|
|
||||||
if self.needs_embedding():
|
if self.needs_embedding():
|
||||||
embedding_content = self.get_embedding_content()
|
embedding_content = self.get_embedding_content()
|
||||||
|
|
@ -80,6 +85,7 @@ class ObjectModel(BaseModel):
|
||||||
data["embedding"] = get_embedding(embedding_content)
|
data["embedding"] = get_embedding(embedding_content)
|
||||||
|
|
||||||
if self.id is None:
|
if self.id is None:
|
||||||
|
data["created"] = datetime.now().isoformat()
|
||||||
logger.debug("Creating new record")
|
logger.debug("Creating new record")
|
||||||
repo_result = repo_create(self.__class__.table_name, data)
|
repo_result = repo_create(self.__class__.table_name, data)
|
||||||
else:
|
else:
|
||||||
|
|
@ -108,8 +114,8 @@ class ObjectModel(BaseModel):
|
||||||
|
|
||||||
def _prepare_save_data(self) -> Dict[str, Any]:
|
def _prepare_save_data(self) -> Dict[str, Any]:
|
||||||
data = self.model_dump()
|
data = self.model_dump()
|
||||||
del data["created"]
|
# del data["created"]
|
||||||
del data["updated"]
|
# del data["updated"]
|
||||||
return {key: value for key, value in data.items() if value is not None}
|
return {key: value for key, value in data.items() if value is not None}
|
||||||
|
|
||||||
def delete(self) -> bool:
|
def delete(self) -> bool:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
from datetime import datetime
|
|
||||||
from typing import ClassVar, List, Literal, Optional
|
from typing import ClassVar, List, Literal, Optional
|
||||||
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
@ -36,7 +35,6 @@ class PodcastConfig(ObjectModel):
|
||||||
voice1: Optional[str] = None
|
voice1: Optional[str] = None
|
||||||
voice2: Optional[str] = None
|
voice2: Optional[str] = None
|
||||||
model: str
|
model: str
|
||||||
created: Optional[datetime] = Field(default_factory=datetime.now)
|
|
||||||
|
|
||||||
def generate_episode(self, episode_name, text, instructions=None):
|
def generate_episode(self, episode_name, text, instructions=None):
|
||||||
self.user_instructions = (
|
self.user_instructions = (
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ st.title("📒 My Notebooks")
|
||||||
st.caption("Here are all your notebooks")
|
st.caption("Here are all your notebooks")
|
||||||
|
|
||||||
|
|
||||||
notebooks = Notebook.get_all()
|
notebooks = Notebook.get_all(order_by="updated desc")
|
||||||
|
|
||||||
for notebook in notebooks:
|
for notebook in notebooks:
|
||||||
if notebook.archived:
|
if notebook.archived:
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ version_sidebar()
|
||||||
episodes_tab, templates_tab = st.tabs(["Episodes", "Templates"])
|
episodes_tab, templates_tab = st.tabs(["Episodes", "Templates"])
|
||||||
|
|
||||||
with episodes_tab:
|
with episodes_tab:
|
||||||
episodes = PodcastEpisode.get_all()
|
episodes = PodcastEpisode.get_all(order_by="created desc")
|
||||||
for episode in episodes:
|
for episode in episodes:
|
||||||
with st.container(border=True):
|
with st.container(border=True):
|
||||||
episode_name = episode.name if episode.name else "No Name"
|
episode_name = episode.name if episode.name else "No Name"
|
||||||
|
|
@ -98,8 +98,9 @@ with templates_tab:
|
||||||
st.rerun()
|
st.rerun()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
st.error(e)
|
st.error(e)
|
||||||
|
st.exception(e)
|
||||||
|
|
||||||
for pd_config in PodcastConfig.get_all():
|
for pd_config in PodcastConfig.get_all(order_by="created desc"):
|
||||||
with st.expander(pd_config.name):
|
with st.expander(pd_config.name):
|
||||||
pd_config.name = st.text_input(
|
pd_config.name = st.text_input(
|
||||||
"Template Name", value=pd_config.name, key=f"name_{pd_config.id}"
|
"Template Name", value=pd_config.name, key=f"name_{pd_config.id}"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue