import os import flask_assets from flask import Flask from flask_flatpages import FlatPages from werkzeug.utils import cached_property class JournalFlatPages(FlatPages): def __init__(self, app=None, name=None): super(JournalFlatPages, self).__init__(app=app, name=name) @cached_property def _pages(self): """Forget all pages and nuke our own cache""" try: del self.__dict__['entries'] del self.__dict__['tags'] except KeyError: pass return super(JournalFlatPages, self)._pages @cached_property def entries(self): return sorted(self, key=lambda x: x.meta.get('date')) @cached_property def tags(self): tags = {} for entry in self.entries: if 'tags' not in entry.meta: tags.setdefault('untagged', set()).add(entry) else: for tag in entry.meta.get('tags'): tags.setdefault(tag, set()).add(entry) return tags 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 if __name__ == '__main__': app.run(port=5000)