diff --git a/TheCodeLabs_FlaskUtils/TheCodeLabs_FlaskUtils/FlaskBaseApp.py b/TheCodeLabs_FlaskUtils/TheCodeLabs_FlaskUtils/FlaskBaseApp.py index d93ae3d80bfc7121fac4044069daa121d142aa32..eeccd9cba246385717015521a4c4d0f90a4fa40b 100644 --- a/TheCodeLabs_FlaskUtils/TheCodeLabs_FlaskUtils/FlaskBaseApp.py +++ b/TheCodeLabs_FlaskUtils/TheCodeLabs_FlaskUtils/FlaskBaseApp.py @@ -9,6 +9,7 @@ from flask import Flask, send_from_directory from flask import jsonify from gevent.pywsgi import WSGIServer +from TheCodeLabs_FlaskUtils.content.AbstractContentService import AbstractContentService from TheCodeLabs_FlaskUtils.menu.AbstractMenuService import AbstractMenuService @@ -20,13 +21,15 @@ class FlaskBaseApp(ABC): settingsPath='../settings.json', serveFavicon=True, serveRobotsTxt=False, - menuService: AbstractMenuService = None): + menuService: AbstractMenuService = None, + contentService: AbstractContentService = None): self._appName = appName self._rootDir = rootDir self._logger = logger self._serveFavicon = serveFavicon self._serveRobotsTxt = serveRobotsTxt self._menuService = menuService + self._contentService = contentService self._version = self.__parse_version(versionPath) self._settings = self.__parse_settings(settingsPath) diff --git a/TheCodeLabs_FlaskUtils/TheCodeLabs_FlaskUtils/content/AbstractContentService.py b/TheCodeLabs_FlaskUtils/TheCodeLabs_FlaskUtils/content/AbstractContentService.py new file mode 100644 index 0000000000000000000000000000000000000000..2eb1976a3019f9c285a3173716f5e294d40a7e1d --- /dev/null +++ b/TheCodeLabs_FlaskUtils/TheCodeLabs_FlaskUtils/content/AbstractContentService.py @@ -0,0 +1,18 @@ +import abc +from abc import ABC +from typing import List + +from TheCodeLabs_FlaskUtils.content.ContentPage import ContentPage + + +class AbstractContentService(ABC): + + @abc.abstractmethod + def get_content_pages(self) -> List[ContentPage]: + pass + + def get_content_page(self, content_id: str) -> ContentPage or None: + content_pages = [page for page in self.get_content_pages() if page.id == content_id] + if not content_pages: + return None + return content_pages[0] diff --git a/TheCodeLabs_FlaskUtils/TheCodeLabs_FlaskUtils/content/ContentPage.py b/TheCodeLabs_FlaskUtils/TheCodeLabs_FlaskUtils/content/ContentPage.py new file mode 100644 index 0000000000000000000000000000000000000000..5d0afe0740487de448543ead32b79ab1c161b2cd --- /dev/null +++ b/TheCodeLabs_FlaskUtils/TheCodeLabs_FlaskUtils/content/ContentPage.py @@ -0,0 +1,17 @@ +from dataclasses import dataclass +from typing import Dict + + +@dataclass +class ContentPage: + id: str + url: str + title: str + + content_path: str + template_path: str + + +@dataclass +class ContextContentPageExtension: + context: Dict[str, any] = None diff --git a/TheCodeLabs_FlaskUtils/setup.py b/TheCodeLabs_FlaskUtils/setup.py index 552a5d0efd2955c1f8f5e817a3ff7fbae8969071..7105ab0bfc482fb39972cd74c0b1107a980188b2 100644 --- a/TheCodeLabs_FlaskUtils/setup.py +++ b/TheCodeLabs_FlaskUtils/setup.py @@ -5,9 +5,10 @@ setup( packages=[ 'TheCodeLabs_FlaskUtils', 'TheCodeLabs_FlaskUtils.auth', + 'TheCodeLabs_FlaskUtils.content', 'TheCodeLabs_FlaskUtils.menu' ], - version='1.2.2', + version='1.2.3', license='MIT', description='Useful python classes', author='TheCodeLabs',