Chris McDonough
2010-12-18 ef3bd570ad4f4060ddd6a8ec83d53fb8d42fed40
model -> resource
2 files deleted
2 files added
5 files modified
1 files renamed
91 ■■■■■ changed files
docs/narr/MyProject/myproject/__init__.py 6 ●●●● patch | view | raw | blame | history
docs/narr/MyProject/myproject/resources.py patch | view | raw | blame | history
docs/narr/project.rst 53 ●●●● patch | view | raw | blame | history
pyramid/paster_templates/starter/+package+/__init__.py_tmpl 6 ●●●● patch | view | raw | blame | history
pyramid/paster_templates/starter/+package+/models.py 7 ●●●●● patch | view | raw | blame | history
pyramid/paster_templates/starter/+package+/resources.py 3 ●●●●● patch | view | raw | blame | history
pyramid/paster_templates/starter_zcml/+package+/__init__.py_tmpl 4 ●●●● patch | view | raw | blame | history
pyramid/paster_templates/starter_zcml/+package+/configure.zcml 2 ●●● patch | view | raw | blame | history
pyramid/paster_templates/starter_zcml/+package+/models.py 7 ●●●●● patch | view | raw | blame | history
pyramid/paster_templates/starter_zcml/+package+/resources.py 3 ●●●●● patch | view | raw | blame | history
docs/narr/MyProject/myproject/__init__.py
@@ -1,12 +1,12 @@
from pyramid.config import Configurator
from myproject.models import get_root
from myproject.resources import Root
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(root_factory=get_root, settings=settings)
    config = Configurator(root_factory=Root, settings=settings)
    config.add_view('myproject.views.my_view',
                    context='myproject.models.MyModel',
                    context='myproject.resources.Root',
                    renderer='myproject:templates/mytemplate.pt')
    config.add_static_view('static', 'myproject:static')
    return config.make_wsgi_app()
docs/narr/MyProject/myproject/resources.py
docs/narr/project.rst
@@ -468,7 +468,7 @@
  |-- development.ini
  |-- myproject
  |   |-- __init__.py
  |   |-- models.py
  |   |-- resources.py
  |   |-- static
  |   |   |-- favicon.ico
  |   |   |-- logo.png
@@ -738,7 +738,7 @@
   application, include a ``main`` function which is used as a Paste entry
   point.
#. A ``models.py`` module, which contains :term:`model` code.
#. A ``resources.py`` module, which contains :term:`resource` code.
#. A ``templates`` directory, which contains :term:`Chameleon` (or
   other types of) templates.
@@ -771,8 +771,8 @@
#. Line 1 imports the :term:`Configurator` class from
   :mod:`pyramid.config` that we use later.
#. Line 2 imports the ``get_root`` function from
   :mod:`myproject.models` that we use later.
#. Line 2 imports the ``Root`` class from :mod:`myproject.resources` that we
   use later.
#. Lines 4-12 define a function that returns a :app:`Pyramid`
   WSGI application.  This function is meant to be called
@@ -784,7 +784,7 @@
   Lines 8-10 register a "default view" (a view that has no ``name``
   attribute).  It is registered so that it will be found when the
   :term:`context` of the request is an instance of the
   :class:`myproject.models.MyModel` class.  The first argument to
   :class:`myproject.resources.Root` class.  The first argument to
   ``add_view`` points at a Python function that does all the work for this
   view, also known as a :term:`view callable`, via a :term:`dotted Python
   name`.  The view declaration also names a ``renderer``, which in this case
@@ -817,7 +817,7 @@
This bit of code was registered as the view callable within ``__init__.py``
(via ``add_view``).  ``add_view`` said that the default URL for instances
that are of the class :class:`myproject.models.MyModel` should run this
that are of the class :class:`myproject.resources.Root` should run this
:func:`myproject.views.my_view` function.
This view callable function is handed a single piece of information:
@@ -846,37 +846,32 @@
   the speed at which templates may be rendered.
.. index::
   single: models.py
   single: resources.py
.. _modelspy_project_section:
.. _resourcespy_project_section:
``models.py``
~~~~~~~~~~~~~
``resources.py``
~~~~~~~~~~~~~~~~
The ``models.py`` module provides the :term:`model` data and behavior
for our application.  Models are objects which store application data
and provide APIs which mutate and return this data.  We write a class
named ``MyModel`` that provides the behavior.
The ``resources.py`` module provides the :term:`resource` data and behavior
for our application.  Resources are objects which exist to provide site
structure in applications which use :term:`traversal` to map URLs to code.
We write a class named ``Root`` that provides the behavior for the root
resource.
.. literalinclude:: MyProject/myproject/models.py
.. literalinclude:: MyProject/myproject/resources.py
   :language: python
   :linenos:
#. Lines 1-2 define the MyModel class.
#. Lines 1-3 define the Root class.  The Root class is a "root resource
   factory" function that will be called by the :app:`Pyramid` *Router* for
   each request when it wants to find the root of the resource tree.
#. Line 4 defines an instance of MyModel as the root.
#. Line 6 is a "root factory" function that will be called by the
   :app:`Pyramid` *Router* for each request when it wants to find
   the root of the resource tree.  Conventionally this is called
   ``get_root``.
In a "real" application, the root object would not be such a simple
object.  Instead, it would be an object that could access some
persistent data store, such as a database.  :app:`Pyramid` doesn't
make any assumption about which sort of datastore you'll want to use,
so the sample application uses an instance of
:class:`myproject.models.MyModel` to represent the root.
In a "real" application, the Root object would not be such a simple object.
Instead, it might be an object that could access some persistent data store,
such as a database.  :app:`Pyramid` doesn't make any assumption about which
sort of datastore you'll want to use, so the sample application uses an
instance of :class:`myproject.resources.Root` to represent the root.
``static``
~~~~~~~~~~~~~~~~~~~~
pyramid/paster_templates/starter/+package+/__init__.py_tmpl
@@ -1,12 +1,12 @@
from pyramid.config import Configurator
from {{package}}.models import get_root
from {{package}}.resources import Root
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(root_factory=get_root, settings=settings)
    config = Configurator(root_factory=Root, settings=settings)
    config.add_view('{{package}}.views.my_view',
                    context='{{package}}.models.MyModel',
                    context='{{package}}:resources.Root"
                    renderer='{{package}}:templates/mytemplate.pt')
    config.add_static_view('static', '{{package}}:static')
    return config.make_wsgi_app()
pyramid/paster_templates/starter/+package+/models.py
File was deleted
pyramid/paster_templates/starter/+package+/resources.py
New file
@@ -0,0 +1,3 @@
class Root(object):
    def __init__(self, request):
        self.request = request
pyramid/paster_templates/starter_zcml/+package+/__init__.py_tmpl
@@ -1,11 +1,11 @@
from pyramid.config import Configurator
from {{package}}.models import get_root
from {{package}}.models import Root
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    zcml_file = settings.get('configure_zcml', 'configure.zcml')
    config = Configurator(root_factory=get_root, settings=settings)
    config = Configurator(root_factory=Root, settings=settings)
    config.load_zcml(zcml_file)
    return config.make_wsgi_app()
pyramid/paster_templates/starter_zcml/+package+/configure.zcml
@@ -4,7 +4,7 @@
  <include package="pyramid.includes" />
  <view
     context=".models.MyModel"
     context=".resources.Root"
     view=".views.my_view"
     renderer="templates/mytemplate.pt"
     />
pyramid/paster_templates/starter_zcml/+package+/models.py
File was deleted
pyramid/paster_templates/starter_zcml/+package+/resources.py
New file
@@ -0,0 +1,3 @@
class Root(object):
    def __init__(self, request):
        self.request = request