save point (see note)

Added 'db' command, tweaked pyramid scaffold a bit (added 'initialize' command
there),  removed migrate 'schema' repository in preparation for alembic.
This commit is contained in:
Lance Edgar 2012-03-25 13:48:13 -05:00
parent 69e92c13db
commit 727b9a5fa7
20 changed files with 270 additions and 144 deletions

View file

@ -12,7 +12,6 @@ from pyramid.config import Configurator
import edbob
from {{package}}._version import __version__
from {{package}}.db import DBSession
def main(global_config, **settings):
@ -37,6 +36,7 @@ def main(global_config, **settings):
# Configure Pyramid
config = Configurator(settings=settings)
config.include('edbob.pyramid')
config.include('{{package}}.subscribers')
config.scan()
# Configure Beaker
@ -49,7 +49,6 @@ def main(global_config, **settings):
edbob.init('{{package}}', os.path.abspath(settings['edbob.config']))
# Add static views
config.add_static_view('favicon.ico', 'static/favicon.ico')
# config.add_static_view('css', 'static/css', cache_max_age=3600)
# config.add_static_view('img', 'static/img', cache_max_age=3600)
# config.add_static_view('js', 'static/js', cache_max_age=3600)

View file

@ -23,34 +23,39 @@ class Command(commands.Command):
long_description = ''
class InitDatabaseCommand(commands.Subcommand):
class InitCommand(commands.Subcommand):
"""
Initializes the database. This is meant to be leveraged as part of setting
up the application. The database used by this command will be determined
by config, for example::
Initializes the database; called as ``{{package}} initialize``. This is
meant to be leveraged as part of setting up the application. The database
used by this command will be determined by config, for example::
.. highlight:: ini
.. highlight:: ini
[edbob.db]
sqlalchemy.url = postgresql://user:pass@localhost/{{package}}
"""
name = 'init-db'
name = 'initialize'
description = "Initialize the database"
def run(self, args):
from edbob.db import engine
from edbob.db.util import install_core_schema
from edbob.db.exceptions import CoreSchemaAlreadyInstalled
from edbob.db.extensions import activate_extension
# Install core schema to database.
try:
install_core_schema(engine)
except CoreSchemaAlreadyInstalled, err:
print err
print '%s:' % err
print ' %s' % engine.url
return
# Activate any extensions you like here...
# activate_extension('shrubbery')
# Okay, on to bootstrapping...
from edbob.db import Session
from edbob.db.classes import Role, User
@ -68,7 +73,8 @@ class InitDatabaseCommand(commands.Subcommand):
session.commit()
session.close()
print "Initialized database %s" % engine.url
print "Initialized database:"
print ' %s' % engine.url
def main(*args):

View file

@ -8,4 +8,6 @@ from sqlalchemy.orm import scoped_session, sessionmaker
from zope.sqlalchemy import ZopeTransactionExtension
DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
__all__ = ['Session']
Session = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))

View file

@ -0,0 +1,21 @@
#!/usr/bin/env python
"""
``{{package}}.subscribers`` -- Pyramid Event Subscribers
"""
import {{package}}
def before_render(event):
"""
Adds goodies to the global template renderer context.
"""
renderer_globals = event
renderer_globals['{{package}}'] = {{package}}
def includeme(config):
config.add_subscriber('{{package}}.subscribers:before_render',
'pyramid.events.BeforeRender')

View file

@ -1,3 +1,7 @@
<%inherit file="edbob/base.mako" />
<%def name="global_title()">{{project}}</%def>
<%def name="footer()">
{{project}} v${{{package}}.__version__} powered by
${h.link_to("edbob", 'http://edbob.org/', target='_blank')} v${edbob.__version__}
</%def>
${parent.body()}

View file

@ -1,11 +1,11 @@
<%inherit file="base.mako" />
<h1>Welcome to {{project}} !</h1>
<h1>Welcome to {{project}}</h1>
<p>You must choose, but choose wisely:</p>
<br />
<ul style="line-height: 200%;">
<li>links should...</li>
<li>...go here</li>
<li>some...</li>
<li>...links</li>
</ul>

View file

@ -1,3 +1,4 @@
0.1a1
-----

View file

@ -8,10 +8,15 @@ Welcome to the {{project}} project.
Getting Started
---------------
- cd <directory containing this file>
{{project}} should install and run without issue on Linux and Windows::
- $venv/bin/python setup.py develop
.. highlight:: sh
- $venv/bin/populate_{{package}} development.ini
- $venv/bin/pserve --reload development.ini
$ virtualenv {{package}}
$ cd <{{package}}-src-dir>
$ python setup.py develop
$ cd <virtual-env-dir>
$ {{package}} make-app <app-dir>
$ cd <app-dir>
$ {{package}} -c development.ini initialize
$ pserve --reload development.ini

View file

@ -76,6 +76,8 @@ setup(
'Framework :: Pylons',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: WSGI :: Application',
],
@ -92,7 +94,7 @@ setup(
{{package}} = {{package}}.commands:main
[{{package}}.commands]
init-db = {{package}}.commands:InitDatabaseCommand
initialize = {{package}}.commands:InitCommand
[paste.app_factory]
main = {{package}}:main

View file

@ -95,6 +95,12 @@ ul.sub-menu li {
margin-right: 15px;
}
#footer {
clear: both;
margin-top: 40px;
text-align: center;
}
#body {
padding-top: 15px;
}

View file

@ -1,6 +1,9 @@
<%def name="global_title()">edbob</%def>
<%def name="title()"></%def>
<%def name="head_tags()"></%def>
<%def name="footer()">
powered by ${h.link_to('edbob', 'http://edbob.org', target='_blank')} v${edbob.__version__}
</%def>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html style="direction: ltr;" xmlns="http://www.w3.org/1999/xhtml" lang="en-us">
<head>
@ -53,8 +56,8 @@
${self.body()}
</div><!-- body -->
<div id="footer" style="clear: both; margin-top: 40px; text-align: center;">
powered by ${h.link_to('edbob', 'http://edbob.org', target='_blank')} v${edbob.__version__}
<div id="footer">
${self.footer()}
</div>
</div><!-- main -->