diff options
Diffstat (limited to 'kyrias_website/__init__.py')
-rw-r--r-- | kyrias_website/__init__.py | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/kyrias_website/__init__.py b/kyrias_website/__init__.py index 474663d..5f07b65 100644 --- a/kyrias_website/__init__.py +++ b/kyrias_website/__init__.py @@ -6,49 +6,28 @@ from flask_flatpages import FlatPages from werkzeug.utils import cached_property -class CustomFlatPages(FlatPages): +class JournalFlatPages(FlatPages): def __init__(self, app=None, name=None): - super(CustomFlatPages, self).__init__(app=app, name=name) - self.app = app + super(JournalFlatPages, self).__init__(app=app, name=name) @cached_property def _pages(self): """Forget all pages and nuke our own cache""" try: - del app.__dict__['journal_entries'] - del app.__dict__['journal_tags'] + del self.__dict__['entries'] + del self.__dict__['tags'] except KeyError: pass - return super(CustomFlatPages, self)._pages - - -class CustomFlask(Flask): - def __init__(self, *args, **kwargs): - super(CustomFlask, self).__init__(*args, **kwargs) - - config = { - 'default': 'kyrias_website.config.BaseConfig', - 'development': 'kyrias_website.config.DevelopmentConfig', - } - - config_name = os.getenv('WEBSITE_CONFIGURATION', 'default') - self.config.from_object(config[config_name]) - - assets = flask_assets.Environment(self) - css = flask_assets.Bundle('base.css', filters='cssmin', output='screen.css') - assets.register('css_all', css) - - self.pages = CustomFlatPages(self, 'pages') - self.journal = CustomFlatPages(self, 'journal') + return super(JournalFlatPages, self)._pages @cached_property - def journal_entries(self): - return sorted(self.journal, key=lambda x: x.meta.get('date')) + def entries(self): + return sorted(self, key=lambda x: x.meta.get('date')) @cached_property - def journal_tags(self): + def tags(self): tags = {} - for entry in self.journal_entries: + for entry in self.entries: if 'tags' not in entry.meta: tags.setdefault('untagged', set()).add(entry) else: @@ -58,7 +37,21 @@ class CustomFlask(Flask): return tags -app = CustomFlask(__name__) +app = Flask(__name__) + +config = { + 'default': 'kyrias_website.config.BaseConfig', + 'development': 'kyrias_website.config.DevelopmentConfig', +} +config_name = os.getenv('WEBSITE_CONFIGURATION', 'development') +app.config.from_object(config[config_name]) + +assets = flask_assets.Environment(app) +css = flask_assets.Bundle('base.css', filters='cssmin', output='screen.css') +assets.register('css_all', css) + +pages = FlatPages(app, 'pages') +journal = JournalFlatPages(app, 'journal') import kyrias_website.views |