Commits

aodag  committed c37dadc

formalchemy

  • Participants
  • Parent commits 7380d60

Comments (0)

Files changed (9)

 *~
 *.egg-info
 *.py[oc]
+syntax: glob
+*.db

File development.ini

 [app:main]
 use = egg:quicktasks
+sqlalchemy.url = sqlite:///%(here)s/quicktasks.db
+sqlalchemy.echo = true
 
 [server:main]
 use = egg:pyramid#wsgiref

File quicktasks/README_FORMALCHEMY.txt

+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.
+
+You should add pyramid_fanstatic and fa.jquery as dependencies in your
+setup.py.
+
+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
+
+

File quicktasks/__init__.py

 from pyramid.config import Configurator
+import sqlahelper
+from sqlalchemy import engine_from_config
 
 def main(global_conf, **settings):
+    engine = engine_from_config(settings)
+    sqlahelper.add_engine(engine)
     config = Configurator(settings=settings)
     config.include('pyramid_tm')
     config.include('pyramid_rpc.jsonrpc')
+    config.include('pyramid_fanstatic')
+    config.include('.fainit')
     return config.make_wsgi_app()

File quicktasks/faforms.py

+from formalchemy import forms
+from formalchemy import tables
+
+class FieldSet(forms.FieldSet):
+    pass
+
+class Grid(tables.Grid):
+    pass

File quicktasks/fainit.py

+from quicktasks import models, faforms
+import logging
+
+log = logging.getLogger(__name__)
+
+
+def includeme(config):
+    config.include('pyramid_formalchemy')
+
+    try:
+        # Add fanstatic tween if available
+        config.include('pyramid_fanstatic')
+    except ImportError:
+        log.warn('You should install pyramid_fanstatic or register a fanstatic'
+                 ' middleware by hand')
+
+    try:
+        # Adding the jquery libraries if available
+        config.include('fa.jquery')
+    except ImportError:
+        model_view = 'pyramid_formalchemy.views.ModelView'
+    else:
+        model_view = 'fa.jquery.pyramid.ModelView'
+
+    session_factory = getattr(models, "DBSession", None)
+    if session_factory is not None:
+        # pyramid_alchemy
+        session_factory = 'quicktasks.models.DBSession'
+    else:
+        # Akhet
+        session_factory = 'quicktasks.models.Session'
+
+    # register session and model_view for later use
+    settings = {'package': 'quicktasks',
+                'view': model_view,
+                'session_factory': session_factory,
+               }
+    config.registry.settings['quicktasks.fa_config'] = settings
+
+    config.formalchemy_admin("/admin", models=models, forms=faforms,
+                             **settings)
+
+    # Adding the package specific routes
+    config.include('quicktasks.faroutes')
+
+    log.info('formalchemy_admin registered at /admin')

File quicktasks/faroutes.py

+from quicktasks import models
+import logging
+
+log = logging.getLogger(__name__)
+
+
+def includeme(config):
+    settings = config.registry.settings.get('quicktasks.fa_settings}}', {})
+
+    # Example to add a specific model
+    #config.formalchemy_model("/my_model", package='quicktasks',
+    #                         model='quicktasks.models.MyModel')
+    #                         **settings)
+
+    log.info('quicktasks.faroutes loaded')

File quicktasks/scripts.py

+import sys
+from pyramid.paster import bootstrap
+
+def populate():
+    app = bootstrap(sys.argv[1])
+    from . import models as m
+    m.Base.metadata.create_all()
     "formalchemy",
     "pyramid_beaker",
     "pyramid_rpc",
+    "pyramid_fanstatic",
+    "pyramid_formalchemy",
+    "fa.jquery",
 ]
 
 points = {
     "paste.app_factory": [
         "main=quicktasks:main",
     ],
+    "console_scripts": [
+        "populate_quicktasks=quicktasks.scripts:populate",
+    ],
 }
 
 setup(name="quicktasks",