Spaces:
Runtime error
Runtime error
File size: 1,354 Bytes
231fd1a dadb34b 231fd1a ee32332 231fd1a 7204409 231fd1a 7204409 231fd1a |
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 |
from dataclasses import dataclass
from typing import Optional
from app import route_prefix
@dataclass
class PageMeta:
module_name: str
_id: Optional[str] = None
_name: Optional[str] = None
_path: Optional[str] = None
@property
def id_(self) -> str:
if not self._id:
# Split the module name and get the last part
parts = self.module_name.split(".")
if len(parts) < 2:
raise ValueError(f"Invalid module name: {self.module_name}")
self._id = parts[1]
return self._id
@property
def name(self) -> str:
if not self._name:
self._name = self.id_.replace("_", " ").capitalize()
return self._name
@property
def path(self) -> str:
if not self._path:
self._path = route_prefix + self.id_
return self._path
@classmethod
def from_module(cls, module_name: str = __name__) -> 'PageMeta':
return cls(module_name=module_name)
class BasePage:
@staticmethod
def create(module_name: str, layout):
# Create PageMeta for the page
page_meta = PageMeta.from_module(module_name)
# Create and return the page (e.g., as a Flask Blueprint)
page = {
"meta": page_meta,
"layout": layout,
}
return page |