Skip to content

Commit

Permalink
Updated bunsen to work with Pyramid 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nek4life committed Mar 25, 2012
1 parent 233ca37 commit 71ca8df
Show file tree
Hide file tree
Showing 40 changed files with 70 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,6 +6,7 @@
*.pyc
*.pyo
*.DS_Store
/projectFilesBackup
/tester
/build
/dist
9 changes: 0 additions & 9 deletions bunsen/paster_templates/__init__.py

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions bunsen/scaffolds/__init__.py
@@ -0,0 +1,5 @@
from pyramid.scaffolds import PyramidTemplate

class BunsenTemplate(PyramidTemplate):
_template_dir = "pyramid_template"
summary = "A Pyramid project setup with URL Dispatch, Jinja2, SQLAlchemy, WTForms and more."
Expand Up @@ -4,7 +4,7 @@ import pyramid_jinja2
from pyramid.config import Configurator
from sqlalchemy import engine_from_config

from {{package}}.models import initialize_sql
from {{package}}.models import DBSession

def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
Expand All @@ -13,6 +13,7 @@ def main(global_config, **settings):

# Configure database engine
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)

# Configure Beaker sessions and caching
session_factory = pyramid_beaker.session_factory_from_settings(settings)
Expand All @@ -24,7 +25,7 @@ def main(global_config, **settings):
config.add_renderer('.html', pyramid_jinja2.renderer_factory)

# Configure static views
config.add_static_view('static', '{{package}}:static')
config.add_static_view('static', '{{package}}:static', cache_max_age=3600)

# Configure Root-Relative static asset views. For usage documenation see
# http://packages.python.org/pyramid_assetviews/#usage
Expand All @@ -46,6 +47,5 @@ def main(global_config, **settings):

# Initialize Database Tables
config.scan("{{package}}.models")
initialize_sql(engine)
return config.make_wsgi_app()

21 changes: 21 additions & 0 deletions bunsen/scaffolds/pyramid_template/+package+/models/__init__.py
@@ -0,0 +1,21 @@
import logging
import transaction
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, Text
from zope.sqlalchemy import ZopeTransactionExtension

log = logging.getLogger(__name__)

DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base()

class MyModel(Base):
__tablename__ = 'models'
id = Column(Integer, primary_key=True)
name = Column(Text, unique=True)
value = Column(Integer)

def __init__(self, name, value):
self.name = name
self.value = value
@@ -0,0 +1,32 @@
import os
import sys
import transaction

from sqlalchemy import engine_from_config

from pyramid.paster import get_appsettings
from pyramid.paster import setup_logging

from {{package}}.models import DBSession
from {{package}}.models import MyModel
from {{package}}.models import Base


def usage(argv):
cmd = os.path.basename(argv[0])
print('usage: %s <config_uri>\n'
'(example: "%s development.ini")' % (cmd, cmd))
sys.exit(1)

def main(argv=sys.argv):
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
model = MyModel(name='one', value=1)
DBSession.add(model)
Empty file.
Expand Up @@ -30,7 +30,7 @@ jinja2.directories = {{package}}:templates
custom_500_error = false

[server:main]
use = egg:Paste#http
use = egg:waitress#main
host = 127.0.0.1
port = 5000

Expand Down
Expand Up @@ -29,7 +29,7 @@ jinja2.directories = {{package}}:templates
custom_500_error = true

[server:main]
use = egg:Paste#http
use = egg:waitress#main
host = 127.0.0.1
port = 5000

Expand Down
Expand Up @@ -16,6 +16,7 @@ requires = [
'pyramid_tm',
'SQLAlchemy',
'transaction',
'waitress',
'WTForms',
'zope.sqlalchemy',
]
Expand All @@ -42,10 +43,11 @@ setup(name='{{package}}',
zip_safe=False,
test_suite='{{package}}',
install_requires = requires,
entry_points = """\
entry_points="""\
[paste.app_factory]
main = {{package}}:main
[console_scripts]
initialize_{{project}}_db = {{package}}.scripts.initializedb:main
""",
paster_plugins=['pyramid'],
)

4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -30,8 +30,8 @@
test_suite='bunsen',
install_requires = requires,
entry_points = """\
[paste.paster_create_template]
bunsen = bunsen.paster_templates:BunsenTemplate
[pyramid.scaffold]
bunsen = bunsen.scaffolds:BunsenTemplate
""",
paster_plugins=['pyramid'],
)
Expand Down

0 comments on commit 71ca8df

Please sign in to comment.