improve docs

This commit is contained in:
Gael Pasgrimaud
2011-04-14 17:30:54 +02:00
parent 99345e516b
commit 4187ec357c
5 changed files with 39 additions and 4 deletions
+6
View File
@@ -1,3 +1,9 @@
0.2
---
- Take care of permissions. You can now use an __acl__ attribute in your SA
models to restrict access
0.1
---
+20
View File
@@ -55,6 +55,26 @@ you can override this. In this case you don't need to specify a package::
You can also change the path ``prefix`` used. pyramid_formalchemy will use
``/admin/`` by default. See :func:`~pyramid_formalchemy.configure`.
Setting permissions
===================
pyramid_formalchemy take care of some ``__acl__`` attributes.
Setting permissions for the globale interface
---------------------------------------------
You just need to subclass the default factory in your application:
.. literalinclude:: ../pyramidapp/pyramidapp/security.py
Setting permissions per model
-----------------------------
You can also add an ``__acl__`` attribute to your model class:
.. literalinclude:: ../pyramidapp/pyramidapp/models.py
:pyobject: Bar
Api
===
+6 -1
View File
@@ -8,6 +8,7 @@ from pyramid.security import Allow, Authenticated, ALL_PERMISSIONS
from pyramidapp.models import initialize_sql
class ModelsWithACL(Models):
"""A factory to override the default security setting"""
__acl__ = [
(Allow, 'admin', ALL_PERMISSIONS),
(Allow, Authenticated, 'view'),
@@ -21,16 +22,20 @@ def main(global_config, **settings):
"""
engine = engine_from_config(settings, 'sqlalchemy.')
initialize_sql(engine)
# configure the security stuff
config = Configurator(settings=settings,
authentication_policy=RemoteUserAuthenticationPolicy(),
authorization_policy=ACLAuthorizationPolicy())
config.add_static_view('static', 'pyramidapp:static')
config.add_route('home', '/', view='pyramidapp.views.my_view',
view_renderer='templates/mytemplate.pt')
# pyramid_formalchemy's configuration
config.include('pyramid_formalchemy')
config.formalchemy_admin('admin', package='pyramidapp', factory=ModelsWithACL)
config.formalchemy_admin('admin', package='pyramidapp',
factory=ModelsWithACL) # use the secure factory
return config.make_wsgi_app()
+4
View File
@@ -30,6 +30,10 @@ class Test_1_UI(unittest.TestCase):
def test_crud(self):
# index
resp = self.app.get('/admin')
self.assertEqual(resp.status_int, 302)
assert '/admin/' in resp.location, resp
resp = self.app.get('/admin/')
resp.mustcontain('/admin/Foo')
resp = resp.click('Foo')
+3 -3
View File
@@ -6,12 +6,12 @@ here = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(here, 'README.txt')).read()
CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()
requires = ['pyramid>=1.0', 'WebError', 'FormAlchemy>=1.3.5']
requires = ['pyramid>=1.0', 'WebError', 'FormAlchemy>=1.3.7']
setup(name='pyramid_formalchemy',
version='0.1',
version='0.2',
description='FormAlchemy plugins and helpers for Pyramid',
long_description=README + '\n\n' + CHANGES,
long_description=README + '\n\nCHANGES\n=======\n\n' + CHANGES,
classifiers=[
"Programming Language :: Python",
"Framework :: Pylons",