Browse Source

added resource sub package

rework
Holger Frey 7 years ago
parent
commit
d154d74c4a
  1. 6
      ordr/__init__.py
  2. 33
      ordr/resources/__init__.py

6
ordr/__init__.py

@ -3,10 +3,6 @@ from pyramid.config import Configurator
__version__ = '0.0.1' __version__ = '0.0.1'
def root_factory(request):
''' dummy root factory '''
return dict()
def main(global_config, **settings): def main(global_config, **settings):
""" This function returns a Pyramid WSGI application. """ This function returns a Pyramid WSGI application.
@ -14,7 +10,7 @@ def main(global_config, **settings):
config = Configurator(settings=settings) config = Configurator(settings=settings)
config.include('pyramid_jinja2') config.include('pyramid_jinja2')
config.include('.models') config.include('.models')
config.include('.resources')
config.add_static_view('static', 'static', cache_max_age=3600) config.add_static_view('static', 'static', cache_max_age=3600)
config.set_root_factory(root_factory)
config.scan() config.scan()
return config.make_wsgi_app() return config.make_wsgi_app()

33
ordr/resources/__init__.py

@ -0,0 +1,33 @@
''' Resources (sub) package, used to connect URLs to views '''
from pyramid.security import Allow, Everyone, DENY_ALL
class RootResource:
''' The root resource for the application
:param pyramid.request.Request request: the current request object
'''
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 includeme(config):
'''
Initialize the resources for traversal in a Pyramid app.
Activate this setup using ``config.include('ordr2.resources')``.
'''
config.set_root_factory(RootResource)