|
|
@ -1,11 +1,30 @@ |
|
|
|
''' Resources (sub) package, used to connect URLs to views ''' |
|
|
|
''' Resources (sub) package, used to connect URLs to views ''' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from pyramid.security import Allow, Everyone, DENY_ALL |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseResource(object): |
|
|
|
class BaseResource(object): |
|
|
|
''' |
|
|
|
''' |
|
|
|
Base resouce class for location aware resources |
|
|
|
Base resouce class for location aware resources |
|
|
|
|
|
|
|
|
|
|
|
establishes a simple dict like interface for returning child resources |
|
|
|
:param str name: |
|
|
|
|
|
|
|
url path segment that identifies this resource in its lineage |
|
|
|
|
|
|
|
:param parent: |
|
|
|
|
|
|
|
parent resource |
|
|
|
|
|
|
|
:type parent: |
|
|
|
|
|
|
|
ordr2.resources.BaseResource |
|
|
|
|
|
|
|
:param model: |
|
|
|
|
|
|
|
(optional) a model instance represented by this resource, |
|
|
|
|
|
|
|
e.g. a database entry |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Provides a dict like interface for retrieving child resources used by |
|
|
|
|
|
|
|
traversal style routing in the Pyramid web framework. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The ``nodes`` property is a dictionary to to match the next url path |
|
|
|
|
|
|
|
segment in traversal to a child class. |
|
|
|
|
|
|
|
For example: to return an AccountResouce when the next path segment is |
|
|
|
|
|
|
|
'account' use ``nodes = {'account': AccountResource}``. |
|
|
|
|
|
|
|
|
|
|
|
''' |
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
# __name__ and __parent__ properties for location awareness |
|
|
|
# __name__ and __parent__ properties for location awareness |
|
|
@ -17,22 +36,19 @@ class BaseResource(object): |
|
|
|
# 'account' use nodes = {'account': AccountResource} |
|
|
|
# 'account' use nodes = {'account': AccountResource} |
|
|
|
nodes = {} |
|
|
|
nodes = {} |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, name, parent): |
|
|
|
def __init__(self, name, parent, model=None): |
|
|
|
''' Create a base resource |
|
|
|
''' 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.__name__ = name |
|
|
|
self.__parent__ = parent |
|
|
|
self.__parent__ = parent |
|
|
|
self.request = parent.request |
|
|
|
self.request = parent.request |
|
|
|
|
|
|
|
self.model = model |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __acl__(self): |
|
|
|
|
|
|
|
''' access controll list for the resource ''' |
|
|
|
|
|
|
|
return [DENY_ALL] |
|
|
|
|
|
|
|
|
|
|
|
def __getitem__(self, key): |
|
|
|
def __getitem__(self, key): |
|
|
|
''' provides a dict like interface to access child resources |
|
|
|
''' provides the dict like interface to access child resources |
|
|
|
|
|
|
|
|
|
|
|
:param str key: |
|
|
|
:param str key: |
|
|
|
path segment for a child resource |
|
|
|
path segment for a child resource |
|
|
@ -44,20 +60,23 @@ class BaseResource(object): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RootResource(BaseResource): |
|
|
|
class RootResource(BaseResource): |
|
|
|
''' The root resource for the application ''' |
|
|
|
''' The root resource for the application |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, request): |
|
|
|
:param request: |
|
|
|
''' Create the root resource |
|
|
|
the current request object |
|
|
|
|
|
|
|
:type request: |
|
|
|
|
|
|
|
pyramid.request.Request |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
:param request: |
|
|
|
def __init__(self, request): |
|
|
|
the current request object |
|
|
|
''' Create the root resource ''' |
|
|
|
:type request: |
|
|
|
|
|
|
|
pyramid.request.Request |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
self.__name__ = None |
|
|
|
self.__name__ = None |
|
|
|
self.__parent__ = None |
|
|
|
self.__parent__ = None |
|
|
|
self.request = request |
|
|
|
self.request = request |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __acl__(self): |
|
|
|
|
|
|
|
''' access controll list for the resource ''' |
|
|
|
|
|
|
|
return [(Allow, Everyone, 'view')] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def includeme(config): |
|
|
|
def includeme(config): |
|
|
|