mirror of
https://github.com/wassname/pyramid_formalchemy.git
synced 2026-07-25 13:20:47 +08:00
improve docs
This commit is contained in:
@@ -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
|
||||
---
|
||||
|
||||
|
||||
@@ -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
|
||||
===
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user