|
|
|
''' Resources (sub) package, used to connect URLs to views '''
|
|
|
|
|
|
|
|
from pyramid.security import Allow, Everyone, DENY_ALL
|
|
|
|
|
|
|
|
from .account import RegistrationResource
|
|
|
|
|
|
|
|
|
|
|
|
class RootResource:
|
|
|
|
''' The root resource for the application
|
|
|
|
|
|
|
|
:param pyramid.request.Request request: the current request object
|
|
|
|
'''
|
|
|
|
|
|
|
|
nav_active = 'welcome'
|
|
|
|
|
|
|
|
def __init__(self, request):
|
|
|
|
''' Create the root resource
|
|
|
|
|
|
|
|
:param pyramid.request.Request request: the current request object
|
|
|
|
'''
|
|
|
|
self.__name__ = None
|
|
|
|
self.__parent__ = None
|
|
|
|
self.request = request
|
|
|
|
|
|
|
|
def __acl__(self):
|
|
|
|
''' access controll list for the resource '''
|
|
|
|
return [(Allow, Everyone, 'view'), DENY_ALL]
|
|
|
|
|
|
|
|
def __getitem__(self, key):
|
|
|
|
''' retruns a child resource
|
|
|
|
|
|
|
|
:param str key: name of the child resource
|
|
|
|
:returns: child resource
|
|
|
|
:raises: KeyError if child resource is not found
|
|
|
|
'''
|
|
|
|
map = {
|
|
|
|
'register': RegistrationResource
|
|
|
|
}
|
|
|
|
child_class = map[key]
|
|
|
|
return child_class(name=key, parent=self)
|
|
|
|
|
|
|
|
|
|
|
|
def includeme(config):
|
|
|
|
'''
|
|
|
|
Initialize the resources for traversal in a Pyramid app.
|
|
|
|
|
|
|
|
Activate this setup using ``config.include('ordr2.resources')``.
|
|
|
|
'''
|
|
|
|
config.set_root_factory(RootResource)
|