From 00773e991328d43dad0e152e5fd4f0132df7b18d Mon Sep 17 00:00:00 2001 From: Patrick Gerken Date: Fri, 17 Jun 2011 16:07:58 +0200 Subject: [PATCH] Adding a paster template --- pyramid_formalchemy/paster.py | 8 +++++++ .../pyramid_fa/+package+/fa_readme.txt | 23 +++++++++++++++++++ .../pyramid_fa/+package+/fainit.py_tmpl | 21 +++++++++++++++++ .../pyramid_fa/+package+/faroutes.py_tmpl | 19 +++++++++++++++ .../pyramid_fa/+package+/forms.py_tmpl | 8 +++++++ setup.py | 4 ++++ 6 files changed, 83 insertions(+) create mode 100644 pyramid_formalchemy/paster.py create mode 100644 pyramid_formalchemy/paster_templates/pyramid_fa/+package+/fa_readme.txt create mode 100644 pyramid_formalchemy/paster_templates/pyramid_fa/+package+/fainit.py_tmpl create mode 100644 pyramid_formalchemy/paster_templates/pyramid_fa/+package+/faroutes.py_tmpl create mode 100644 pyramid_formalchemy/paster_templates/pyramid_fa/+package+/forms.py_tmpl diff --git a/pyramid_formalchemy/paster.py b/pyramid_formalchemy/paster.py new file mode 100644 index 0000000..40e9546 --- /dev/null +++ b/pyramid_formalchemy/paster.py @@ -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) diff --git a/pyramid_formalchemy/paster_templates/pyramid_fa/+package+/fa_readme.txt b/pyramid_formalchemy/paster_templates/pyramid_fa/+package+/fa_readme.txt new file mode 100644 index 0000000..906ff90 --- /dev/null +++ b/pyramid_formalchemy/paster_templates/pyramid_fa/+package+/fa_readme.txt @@ -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 diff --git a/pyramid_formalchemy/paster_templates/pyramid_fa/+package+/fainit.py_tmpl b/pyramid_formalchemy/paster_templates/pyramid_fa/+package+/fainit.py_tmpl new file mode 100644 index 0000000..594ae98 --- /dev/null +++ b/pyramid_formalchemy/paster_templates/pyramid_fa/+package+/fainit.py_tmpl @@ -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") diff --git a/pyramid_formalchemy/paster_templates/pyramid_fa/+package+/faroutes.py_tmpl b/pyramid_formalchemy/paster_templates/pyramid_fa/+package+/faroutes.py_tmpl new file mode 100644 index 0000000..46bc43c --- /dev/null +++ b/pyramid_formalchemy/paster_templates/pyramid_fa/+package+/faroutes.py_tmpl @@ -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 + diff --git a/pyramid_formalchemy/paster_templates/pyramid_fa/+package+/forms.py_tmpl b/pyramid_formalchemy/paster_templates/pyramid_fa/+package+/forms.py_tmpl new file mode 100644 index 0000000..428e4b5 --- /dev/null +++ b/pyramid_formalchemy/paster_templates/pyramid_fa/+package+/forms.py_tmpl @@ -0,0 +1,8 @@ +from formalchemy import forms +from formalchemy import tables + +class FieldSet(forms.FieldSet): + pass + +class Grid(tables.Grid): + pass diff --git a/setup.py b/setup.py index 5ca1adb..8e0c31f 100644 --- a/setup.py +++ b/setup.py @@ -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 +""" )