import pylons
from decorator import decorator
from {{package}}.lib.auth import redirect_to_login

import logging
log = logging.getLogger(__name__)

def authorize(permission):
    
    """Decorator for authenticating individual actions. Takes a permission 
    instance as argument(see lib/permissions.py for examples)"""
    def wrapper(func, self, *args, **kw):
        if permission.check():
            return func(self, *args, **kw)
        pylons.session['redirect'] = pylons.request.environ['pylons.routes_dict']
        pylons.session.save()
        redirect_to_login()
    return decorator(wrapper)

