Files
pyramid_formalchemy/docs/index.txt
T
2011-06-17 18:04:47 +02:00

147 lines
4.3 KiB
Plaintext

.. pyramid_formalchemy documentation master file, created by
sphinx-quickstart on Sat Jan 15 20:18:53 2011.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
===============================================
Welcome to pyramid_formalchemy's documentation!
===============================================
About
=====
``pyramid_formalchemy`` provide a CRUD interface for ``pyramid`` based on ``FormAlchemy``
It also allow to use ``FormAlchemy`` to render forms in your application.
Installation
============
With easy_install::
$ easy_install pyramid_formalchemy
It's also highly recommended to install fa.jquery to get a nicer interface::
$ easy_install fa.jquery
Basic usage
============
Add an empty ``forms.py`` module at the root of your project.
Now you just need to include two line of configuration in the ``__init__.main()`` function of your project.
Here is the one used for testing:
.. literalinclude:: ../pyramidapp/pyramidapp/__init__.py
This will render the **basic** formalchemy interface.
It's better to enable the jquery stuff like this:
.. literalinclude:: ../pyramidapp/pyramidapp/jquery.py
:pyobject: main
That's it. Now launch your app, browse ``/admin/`` and enjoy it !
Advanced usage
===============
Custom view, factory, forms
----------------------------
In the toward examples we just pass a ``package`` parameter to
:func:`~pyramid_formalchemy.configure`. By default the function will try to
load ``package.models``, ``package.models.DBSession`` and ``package.forms`` but
you can override this. In this case you don't need to specify a package::
config.formalchemy_admin(config,
forms='formalchemy_project.forms',
models='formalchemy_project.mymodels',
session_factory='formalchemy_project.session.Session',
)
You can also change the path ``prefix`` used. pyramid_formalchemy will use
``/admin/`` by default. See :func:`~pyramid_formalchemy.configure`.
Having fun with the query_factory parameter
-------------------------------------------
.. literalinclude:: ../../formalchemy_project/__init__.py
:pyobject: main
Custom views per model
----------------------
You can also register custom CRUD views per ModelListing::
config.formalchemy_model_view('admin',
model='pyramidapp.models.Foo',
context='pyramid_formalchemy.resources.ModelListing',
renderer='templates/foolisting.pt',
attr='listing',
request_method='GET',
permission='view')
and per Model::
config.formalchemy_model_view('admin',
model='pyramidapp.models.Foo',
context='pyramid_formalchemy.resources.Model',
name='',
renderer='templates/fooshow.pt',
attr='show',
request_method='GET',
permission='view')
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
Event subscription
==================
``pyramid_formalchemy`` provides four events: ``IBeforeValidateEvent``,
``IAfterSyncEvent``, ``IBeforeDeleteEvent`` and ``IBeforeRenderEvent``.
There are also two more specific render evnts: ``IBeforeShowRenderEvent``
and ``IBeforeEditRenderEvent``. You can use ``pyramid_formalchemy.events.subscriber``
decorator to subscribe:
.. literalinclude:: ../pyramidapp/pyramidapp/events.py
Api
===
.. toctree::
:maxdepth: 1
modules/index.txt
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`