muyhomepage2 / muyhomepage2 / pagehandlers / handler.py

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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.