mirror of
https://github.com/wassname/pyramid_formalchemy.git
synced 2026-08-11 11:23:53 +08:00
use include() and configure()
This commit is contained in:
+17
-1
@@ -1,2 +1,18 @@
|
||||
*.pyc
|
||||
.Python
|
||||
bin/
|
||||
lib/
|
||||
dist/
|
||||
eggs/
|
||||
parts/
|
||||
var/
|
||||
develop-eggs/
|
||||
docs/_build/
|
||||
docs/modules/
|
||||
include/
|
||||
.installed.cfg
|
||||
*.egg-info
|
||||
*.pt.py
|
||||
*.swp
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.log
|
||||
|
||||
@@ -23,3 +23,4 @@ initialization =
|
||||
os.chdir('pyramidapp')
|
||||
scripts=
|
||||
nosetests=nosetests
|
||||
paster=paster_serve
|
||||
|
||||
@@ -1,4 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
def include_formalchemy(config):
|
||||
pass
|
||||
def include(config):
|
||||
config.load_zcml('pyramid_formalchemy:configure.zcml')
|
||||
|
||||
def configure(config, models=None, forms=None, session_factory=None, package=None):
|
||||
"""configure formalchemy's admin interface"""
|
||||
if models:
|
||||
models = config.maybe_dotted(models)
|
||||
if forms:
|
||||
forms = config.maybe_dotted(forms)
|
||||
if session_factory:
|
||||
session_factory = config.maybe_dotted(session_factory)
|
||||
|
||||
if package:
|
||||
if not models:
|
||||
models = config.maybe_dotted('%s.models' % package)
|
||||
if not forms:
|
||||
forms = config.maybe_dotted('%s.forms' % package)
|
||||
if not session_factory:
|
||||
session_factory = config.maybe_dotted('%s.models.DBSession' % package)
|
||||
|
||||
config.registry.settings.update({
|
||||
'fa.models': models,
|
||||
'fa.forms': forms,
|
||||
'fa.session_factory': session_factory,
|
||||
})
|
||||
|
||||
config.add_route('fa_admin', '/admin/*traverse',
|
||||
factory='pyramid_formalchemy.resources.AdminView')
|
||||
|
||||
|
||||
Binary file not shown.
@@ -2,6 +2,7 @@ from pyramid.config import Configurator
|
||||
from sqlalchemy import engine_from_config
|
||||
|
||||
from pyramidapp.models import initialize_sql
|
||||
import pyramid_formalchemy
|
||||
|
||||
def main(global_config, **settings):
|
||||
""" This function returns a Pyramid WSGI application.
|
||||
@@ -12,14 +13,8 @@ def main(global_config, **settings):
|
||||
config.add_static_view('static', 'pyramidapp:static')
|
||||
config.add_route('home', '/', view='pyramidapp.views.my_view',
|
||||
view_renderer='templates/mytemplate.pt')
|
||||
config.load_zcml('pyramid_formalchemy:configure.zcml')
|
||||
config.add_route('fa_admin', '/admin/*traverse',
|
||||
factory='pyramid_formalchemy.resources.AdminView')
|
||||
config.registry.settings.update({
|
||||
'fa.models': config.maybe_dotted('pyramidapp.models'),
|
||||
'fa.forms': config.maybe_dotted('pyramidapp.forms'),
|
||||
'fa.session_factory': config.maybe_dotted('pyramidapp.models.DBSession'),
|
||||
})
|
||||
pyramid_formalchemy.include(config)
|
||||
pyramid_formalchemy.configure(config, package='pyramidapp')
|
||||
return config.make_wsgi_app()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user