view commentator/example.py @ 6:c95f1dfed329

some work to get commenting + captchas working together
author k0s <k0scist@gmail.com>
date Tue, 02 Mar 2010 11:44:10 -0500
parents 1c95a3fa76c1
children
line wrap: on
line source

import os

from middleware import Commentator
from paste.httpexceptions import HTTPExceptionHandler
from paste.urlparser import StaticURLParser
from pkg_resources import resource_filename


def factory(global_conf, **app_conf):
    """create a webob view and wrap it in middleware"""

    keystr = 'commentator.'
    args = dict([(key.split(keystr, 1)[-1], value)
                 for key, value in app_conf.items()
                 if key.startswith(keystr) ])
    app = StaticURLParser(app_conf['directory'])
    commentator = Commentator(app, **args)
    return HTTPExceptionHandler(commentator)

try:
    from captchamiddleware import CAPTCHAmiddleware
    
    def captcha_factory(global_conf, **app_conf):
        """create a webob view and wrap it in middleware"""

        # set up commenting on static files
        keystr = 'commentator.'
        args = dict([(key.split(keystr, 1)[-1], value)
                     for key, value in app_conf.items()
                     if key.startswith(keystr) ])
        app = StaticURLParser(app_conf['directory'])
        commentator = Commentator(app, **args)

        # install the CAPTCHAmiddleware
        keystring = 'captcha.'
        args = dict([(key.split(keystr, 1)[-1], value)
                     for key, value in app_conf.items()
                     if key.startswith(keystr) ])
        captcha = CAPTCHAmiddleware(commentator, **args)

        return HTTPExceptionHandler(captcha)
    
except ImportError:
    pass