Skip to content

Commit

Permalink
- The alchemy scaffold has been removed.
Browse files Browse the repository at this point in the history
- The ``routesalchemy`` scaffold has been renamed ``alchemy``.
  • Loading branch information
mcdonc committed Nov 13, 2011
1 parent 8595a77 commit 818f8ca
Show file tree
Hide file tree
Showing 38 changed files with 69 additions and 662 deletions.
10 changes: 10 additions & 0 deletions CHANGES.txt
Expand Up @@ -67,3 +67,13 @@ Dependencies
- Pyramid no longer depends on the Paste or PasteScript packages.


Scaffolds
---------

- Rendered scaffolds have now been changed to be more relocatable (fewer
mentions of the package name within files in the package).

- The ``alchemy`` scaffold has been removed.

- The ``routesalchemy`` scaffold has been renamed ``alchemy``.

4 changes: 3 additions & 1 deletion TODO.txt
Expand Up @@ -9,7 +9,9 @@ Must-Have

- Fix SQLA tutorial to match ZODB tutorial.

- Fix other scaffolds to match ZODB scaffold.
- Fix routesalchemy scaffold to match ZODB scaffold.

- Remove alchemy scaffold.

Nice-to-Have
------------
Expand Down
13 changes: 4 additions & 9 deletions docs/narr/project.rst
Expand Up @@ -28,7 +28,6 @@ as part of Pyramid.
single: starter scaffold
single: zodb scaffold
single: alchemy scaffold
single: routesalchemy scaffold

.. _additional_paster_scaffolds:

Expand All @@ -52,12 +51,8 @@ The included scaffolds are these:
``zodb``
URL mapping via :term:`traversal` and persistence via :term:`ZODB`.

``routesalchemy``
URL mapping via :term:`URL dispatch` and persistence via
:term:`SQLAlchemy`

``alchemy``
URL mapping via :term:`traversal` and persistence via
URL mapping via :term:`URL dispatch` and persistence via
:term:`SQLAlchemy`

.. note::
Expand Down Expand Up @@ -99,18 +94,18 @@ Or on Windows:
The above command uses the ``pcreate`` command to create a project with the
``starter`` scaffold. To use a different scaffold, such as
``routesalchemy``, you'd just change the ``-s`` argument value. For example,
``alchemy``, you'd just change the ``-s`` argument value. For example,
on UNIX:

.. code-block:: text
$ bin/pcreate -s routesalchemy MyProject
$ bin/pcreate -s alchemy MyProject
Or on Windows:

.. code-block:: text
$ Scripts\pcreate routesalchemy MyProject
$ Scripts\pcreate alchemy MyProject
Here's sample output from a run of ``pcreate`` on UNIX for a project we name
``MyProject``:
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/wiki2/basiclayout.rst
Expand Up @@ -2,7 +2,7 @@
Basic Layout
============

The starter files generated by the ``routesalchemy`` scaffold are
The starter files generated by the ``alchemy`` scaffold are
basic, but they provide a good orientation for the high-level patterns common
to most :term:`url dispatch` -based :app:`Pyramid` projects.

Expand Down Expand Up @@ -98,7 +98,7 @@ register views for the routes, mapping your patterns to code:

The first positional ``add_view`` argument ``tutorial.views.my_view`` is the
dotted name to a *function* we write (generated by the
``routesalchemy`` scaffold) that is given a ``request`` object and
``alchemy`` scaffold) that is given a ``request`` object and
which returns a response or a dictionary. This view also names a
``renderer``, which is a template which lives in the ``templates``
subdirectory of the package. When the ``tutorial.views.my_view`` view
Expand All @@ -124,7 +124,7 @@ Content Models with ``models.py``
In a SQLAlchemy-based application, a *model* object is an object
composed by querying the SQL database which backs an application.
SQLAlchemy is an "object relational mapper" (an ORM). The
``models.py`` file is where the ``routesalchemy`` scaffold
``models.py`` file is where the ``alchemy`` scaffold
put the classes that implement our models.

Let's take a look. First, we need some imports to support later code.
Expand Down
12 changes: 6 additions & 6 deletions docs/tutorials/wiki2/installation.rst
Expand Up @@ -84,7 +84,7 @@ Making a Project

Your next step is to create a project. :app:`Pyramid` supplies a
variety of scaffolds to generate sample projects. We will use the
``routesalchemy`` scaffold, which generates an application
``alchemy`` scaffold, which generates an application
that uses :term:`SQLAlchemy` and :term:`URL dispatch`.

The below instructions assume your current working directory is the
Expand All @@ -94,15 +94,15 @@ On UNIX:

.. code-block:: text
$ bin/pcreate -s routesalchemy tutorial
$ bin/pcreate -s alchemy tutorial
On Windows:

.. code-block:: text
c:\pyramidtut> Scripts\pcreate -s routesalchemy tutorial
c:\pyramidtut> Scripts\pcreate -s alchemy tutorial
.. note:: If you are using Windows, the ``routesalchemy``
.. note:: If you are using Windows, the ``alchemy``
scaffold may not deal gracefully with installation into a
location that contains spaces in the path. If you experience
startup problems, try putting both the virtualenv and the project
Expand Down Expand Up @@ -222,10 +222,10 @@ page. You can read more about the purpose of the icon at
:ref:`debug_toolbar`. It allows you to get information about your
application while you develop.

Decisions the ``routesalchemy`` Scaffold Has Made For You
Decisions the ``alchemy`` Scaffold Has Made For You
=================================================================

Creating a project using the ``routesalchemy`` scaffold makes
Creating a project using the ``alchemy`` scaffold makes
the following assumptions:

- you are willing to use :term:`SQLAlchemy` as a database access tool
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/wiki2/tests.rst
Expand Up @@ -13,9 +13,9 @@ We write a test class for the model class ``Page`` and another test class
for the ``initialize_sql`` function.

To do so, we'll retain the ``tutorial.tests.ViewTests`` class provided as a
result of the ``routesalchemy`` project generator. We'll add two
test classes: one for the ``Page`` model named ``PageModelTests``, one for the
``initialize_sql`` function named ``InitializeSqlTests``.
result of the ``alchemy`` scaffold. We'll add two test classes: one for the
``Page`` model named ``PageModelTests``, one for the ``initialize_sql``
function named ``InitializeSqlTests``.

Testing the Views
=================
Expand Down
8 changes: 2 additions & 6 deletions pyramid/scaffolds/__init__.py
Expand Up @@ -28,13 +28,9 @@ class StarterProjectTemplate(PyramidTemplate):

class ZODBProjectTemplate(PyramidTemplate):
_template_dir = 'zodb'
summary = 'Pyramid ZODB starter project'

class RoutesAlchemyProjectTemplate(PyramidTemplate):
_template_dir = 'routesalchemy'
summary = 'Pyramid SQLAlchemy project using url dispatch (no traversal)'
summary = 'Pyramid ZODB project using traversal'

class AlchemyProjectTemplate(PyramidTemplate):
_template_dir = 'alchemy'
summary = 'Pyramid SQLAlchemy project using traversal'
summary = 'Pyramid SQLAlchemy project using url dispatch'

19 changes: 9 additions & 10 deletions pyramid/scaffolds/alchemy/+package+/__init__.py_tmpl 100755 → 100644
@@ -1,19 +1,18 @@
from pyramid.config import Configurator
from sqlalchemy import engine_from_config

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

def main(global_config, **settings):
""" This function returns a WSGI application.
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
get_root = appmaker(engine)
config = Configurator(settings=settings, root_factory=get_root)
initialize_sql(engine)
config = Configurator(settings=settings)
config.add_static_view('static', '{{package}}:static', cache_max_age=3600)
config.add_view('{{package}}.views.view_root',
context='{{package}}.models.MyRoot',
renderer="templates/root.pt")
config.add_view('{{package}}.views.view_model',
context='{{package}}.models.MyModel',
renderer="templates/model.pt")
config.add_route('home', '/')
config.add_view('{{package}}.views.my_view',
route_name='home',
renderer='templates/mytemplate.pt')
return config.make_wsgi_app()

56 changes: 7 additions & 49 deletions pyramid/scaffolds/alchemy/+package+/models.py 100755 → 100644
@@ -1,15 +1,14 @@
import transaction

from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import Unicode

from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy import Integer
from sqlalchemy import Unicode
from sqlalchemy import Column
from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker

from zope.sqlalchemy import ZopeTransactionExtension

Expand All @@ -26,45 +25,9 @@ def __init__(self, name, value):
self.name = name
self.value = value

class MyRoot(object):
__name__ = None
__parent__ = None

def __getitem__(self, key):
session= DBSession()
try:
id = int(key)
except (ValueError, TypeError):
raise KeyError(key)

item = session.query(MyModel).get(id)
if item is None:
raise KeyError(key)

item.__parent__ = self
item.__name__ = key
return item

def get(self, key, default=None):
try:
item = self.__getitem__(key)
except KeyError:
item = default
return item

def __iter__(self):
session= DBSession()
query = session.query(MyModel)
return iter(query)

root = MyRoot()

def root_factory(request):
return root

def populate():
session = DBSession()
model = MyModel(name='test name', value=55)
model = MyModel(name='root', value=55)
session.add(model)
session.flush()
transaction.commit()
Expand All @@ -77,8 +40,3 @@ def initialize_sql(engine):
populate()
except IntegrityError:
transaction.abort()
return DBSession

def appmaker(engine):
initialize_sql(engine)
return root_factory
82 changes: 0 additions & 82 deletions pyramid/scaffolds/alchemy/+package+/templates/model.pt_tmpl

This file was deleted.

0 comments on commit 818f8ca

Please sign in to comment.