|
|
|
@ -1,10 +1,63 @@
@@ -1,10 +1,63 @@
|
|
|
|
|
class Root(object): |
|
|
|
|
''' Resources (sub) package, used to connect URLs to views ''' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseResource(object): |
|
|
|
|
''' |
|
|
|
|
Base resouce class for location aware resources |
|
|
|
|
|
|
|
|
|
establishes a simple dict like interface for returning child resources |
|
|
|
|
''' |
|
|
|
|
|
|
|
|
|
# __name__ and __parent__ properties for location awareness |
|
|
|
|
__name__ = None |
|
|
|
|
__parent__ = None |
|
|
|
|
|
|
|
|
|
# dict to match the next url path segment |
|
|
|
|
# for example: to return an AccountResouce when the next path segment is |
|
|
|
|
# 'account' use nodes = {'account': AccountResource} |
|
|
|
|
nodes = {} |
|
|
|
|
|
|
|
|
|
def __init__(self, name, parent): |
|
|
|
|
''' Create a base resource |
|
|
|
|
|
|
|
|
|
:param str name: |
|
|
|
|
url path segment that identifies this resource in its lineage |
|
|
|
|
:param parent: |
|
|
|
|
parent resource in the lineage |
|
|
|
|
:type parent: |
|
|
|
|
ordr2.resources.BaseResource |
|
|
|
|
''' |
|
|
|
|
self.__name__ = name |
|
|
|
|
self.__parent__ = parent |
|
|
|
|
self.request = parent.request |
|
|
|
|
|
|
|
|
|
def __getitem__(self, key): |
|
|
|
|
''' provides a dict like interface to access child resources |
|
|
|
|
|
|
|
|
|
:param str key: |
|
|
|
|
path segment for a child resource |
|
|
|
|
:rtype: |
|
|
|
|
ordr2.resources.BaseResource or KeyError |
|
|
|
|
''' |
|
|
|
|
node_class = self.nodes[key] |
|
|
|
|
return node_class(key, self) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RootResource(BaseResource): |
|
|
|
|
''' The root resource for the application ''' |
|
|
|
|
|
|
|
|
|
def __init__(self, request): |
|
|
|
|
''' Create the root resource |
|
|
|
|
|
|
|
|
|
:param request: |
|
|
|
|
the current request object |
|
|
|
|
:type request: |
|
|
|
|
pyramid.request.Request |
|
|
|
|
''' |
|
|
|
|
self.__name__ = None |
|
|
|
|
self.__parent__ = None |
|
|
|
|
self.request = request |
|
|
|
|
|
|
|
|
|
def root_factory(request): |
|
|
|
|
return Root() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def includeme(config): |
|
|
|
@ -14,5 +67,4 @@ def includeme(config):
@@ -14,5 +67,4 @@ def includeme(config):
|
|
|
|
|
Activate this setup using ``config.include('ordr2.resources')``. |
|
|
|
|
|
|
|
|
|
''' |
|
|
|
|
config.set_root_factory(root_factory) |
|
|
|
|
config.add_static_view('static', 'ordr2:static', cache_max_age=3600) |
|
|
|
|
config.set_root_factory(RootResource) |
|
|
|
|