Source

muyhomepage2 / muyhomepage2 / pagehandlers / handler.py

Full commit

from muyhomepage2 import util

class PageHandler(object):
    def __init__(self, page):
        self.page = page

    def content(self):
        raise NotImplementedError('PageHandler.content')

    @property
    def tags(self):
        return sorted(self.page.tags)

    @property
    def createdon(self):
        return self.page.created()

    @property
    def modifiedon(self):
        return self.page.modified()

    def finalname(self):
        if 'x-force-file-name' in self.page.headers:
            return self.page.headers['x-force-file-name']
        return '%s.html' % util.encodetitle(self.page.title)

    def template(self):
        return None

    def extension(self, website, config):
        raise NotImplementedError('PageHandler.extension')


def handle_action(registry, default, page):
    """ Return a PageHandler object based on the given ``page``'s action
    header. If the action header is not present construct a handler
    based on the ``default``. The value of the action header must map
    to a key in the ``registry`` otherwise.
    """
    if 'action' not in page.headers:
        handler = default
    else:
        handler = registry[page.headers['action']]
    return handler(page)