Adding a paster template

This commit is contained in:
Patrick Gerken
2011-06-17 16:07:58 +02:00
parent a3e37cb878
commit 00773e9913
6 changed files with 83 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
from tempita import paste_script_template_renderer
from pyramid.paster import PyramidTemplate
class PyramidFormAlchemyTemplate(PyramidTemplate):
_template_dir = ('pyramid_formalchemy', 'paster_templates/pyramid_fa')
summary = "Pyramid application template to extend other templates with "
"formalchemy"
template_renderer = staticmethod(paste_script_template_renderer)
@@ -0,0 +1,23 @@
This script does not want to tell you how your app should be set up.
As such, it does not set an app up for you.
Please use this template together with other templates, like akhet,
pyramid_routesalchemy or pyramid_alchemy.
To finally include FormAlchemy, modify your main method were you
create the wsgi application, and include {{package}}.fainit to the
configuration, like that:
>>> config.include("{{package}}.fainit")
If you are using pyramid_routesalchemy or pyramid_alchemy,
you must modify the models.py. For FormAlchemy to be able to use the
Model, the Model must have a constructer that can be called without
any argument.
So open up models.py and either remove the constructor of MyModel,
or add default values.
If you are using akhet, nothing special needs to be done.
After this modifications, you should find the FormAlchemy Admin
Interface under /admin
@@ -0,0 +1,21 @@
from {{package}} import models, forms
def includeme(config):
config.include('pyramid_formalchemy')
# Adding the jquery libraries
config.include('fa.jquery')
# Adding the package specific routes
config.include('{{package}}.faroutes')
try:
# pyramid_alchemy
session_factory = models.DBSession
except AttributeError:
# akhet
session_factory = models.Session
config.formalchemy_admin("/admin",
models=models,
forms=forms,
session_factory=session_factory,
view="fa.jquery.pyramid.ModelView")
@@ -0,0 +1,19 @@
from {{package}} import models
def includeme(config):
try:
# pyramid_alchemy
session_factory = models.DBSession
except AttributeError:
# akhet
session_factory = models.Session
try:
# Example for pyramid_routesalchemy and akhet
from {{package}}.models import MyModel
config.formalchemy_model("/my_model", package='{{package}}',
model='{{package}}.models.MyModel',
session_factory=session_factory,
view='fa.jquery.pyramid.ModelView')
except ImportError:
pass
@@ -0,0 +1,8 @@
from formalchemy import forms
from formalchemy import tables
class FieldSet(forms.FieldSet):
pass
class Grid(tables.Grid):
pass
+4
View File
@@ -26,5 +26,9 @@ setup(name='pyramid_formalchemy',
include_package_data=True,
zip_safe=False,
install_requires=requires,
entry_points = """
[paste.paster_create_template]
pyramid_fa = pyramid_formalchemy.paster:PyramidFormAlchemyTemplate
"""
)