async def delete_theme(theme_name: str): """ Deletes theme from the database """ try: SiteTheme.delete_theme(theme_name) except: raise HTTPException( status_code=400, detail=SnackResponse.error("Unable to Delete Theme")) return SnackResponse.success("Theme Deleted")
async def create_theme(data: SiteTheme): """ Creates a site color theme database entry """ try: data.save_to_db() except: raise HTTPException(status_code=400, detail=SnackResponse.error("Unable to Save Theme")) return SnackResponse.success("Theme Saved")
async def update_theme(theme_name: str, data: SiteTheme): """ Update a theme database entry """ try: data.update_document() except: raise HTTPException( status_code=400, detail=SnackResponse.error("Unable to Update Theme")) return SnackResponse.success("Theme Updated")
async def delete_theme(theme_name: str): """ Returns basic site Settings """ try: SiteTheme.delete_theme(theme_name) except: raise HTTPException( status_code=400, detail=SnackResponse.error("Unable to Delete Theme")) return SnackResponse.success("Theme Deleted")
def import_themes(self): themes_file = self.import_dir.joinpath("themes", "themes.json") with open(themes_file, "r") as f: themes: list = json.loads(f.read()) for theme in themes: new_theme = SiteTheme(**theme) try: new_theme.save_to_db() except: logger.info(f"Unable Import Theme {new_theme.name}")
def generate_default_theme(): default_colors = { "primary": "#E58325", "accent": "#00457A", "secondary": "#973542", "success": "#5AB1BB", "info": "#4990BA", "warning": "#FF4081", "error": "#EF5350", } try: SiteTheme.get_by_name("default") return "default theme exists" except: logger.info("Generating Default Theme") colors = Colors(**default_colors) default_theme = SiteTheme(name="default", colors=colors) default_theme.save_to_db()
async def get_single_theme(theme_name: str): """ Returns a named theme """ return SiteTheme.get_by_name(theme_name)
async def get_all_themes(): """ Returns all site themes """ return SiteTheme.get_all()
async def get_single_theme(theme_name: str): """ Returns basic site Settings """ return SiteTheme.get_by_name(theme_name)
def export_themes(self): all_themes = SiteTheme.get_all() if all_themes: all_themes = [x.dict() for x in all_themes] out_file = self.themes_dir.joinpath("themes.json") ExportDatabase._write_json_file(all_themes, out_file)