summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2010-12-18 02:50:22 -0500
committerChris McDonough <chrism@plope.com>2010-12-18 02:50:22 -0500
commitef3bd570ad4f4060ddd6a8ec83d53fb8d42fed40 (patch)
tree4bc74790eeb788926400271d9717b93ce5a09f4a
parentfb6a5ce52a275f7798e82a34b5907ea118cbd2ff (diff)
downloadpyramid-ef3bd570ad4f4060ddd6a8ec83d53fb8d42fed40.tar.gz
pyramid-ef3bd570ad4f4060ddd6a8ec83d53fb8d42fed40.tar.bz2
pyramid-ef3bd570ad4f4060ddd6a8ec83d53fb8d42fed40.zip
model -> resource
-rw-r--r--docs/narr/MyProject/myproject/__init__.py6
-rw-r--r--docs/narr/MyProject/myproject/resources.py (renamed from docs/narr/MyProject/myproject/models.py)0
-rw-r--r--docs/narr/project.rst53
-rw-r--r--pyramid/paster_templates/starter/+package+/__init__.py_tmpl6
-rw-r--r--pyramid/paster_templates/starter/+package+/models.py7
-rw-r--r--pyramid/paster_templates/starter/+package+/resources.py3
-rw-r--r--pyramid/paster_templates/starter_zcml/+package+/__init__.py_tmpl4
-rw-r--r--pyramid/paster_templates/starter_zcml/+package+/configure.zcml2
-rw-r--r--pyramid/paster_templates/starter_zcml/+package+/models.py7
-rw-r--r--pyramid/paster_templates/starter_zcml/+package+/resources.py3
10 files changed, 39 insertions, 52 deletions
diff --git a/docs/narr/MyProject/myproject/__init__.py b/docs/narr/MyProject/myproject/__init__.py
index 05730a115..813028704 100644
--- a/docs/narr/MyProject/myproject/__init__.py
+++ b/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()
diff --git a/docs/narr/MyProject/myproject/models.py b/docs/narr/MyProject/myproject/resources.py
index 75dec7505..75dec7505 100644
--- a/docs/narr/MyProject/myproject/models.py
+++ b/docs/narr/MyProject/myproject/resources.py
diff --git a/docs/narr/project.rst b/docs/narr/project.rst
index 65ef3c526..27974d8df 100644
--- a/docs/narr/project.rst
+++ b/docs/narr/project.rst
@@ -468,7 +468,7 @@ structure:
|-- development.ini
|-- myproject
| |-- __init__.py
- | |-- models.py
+ | |-- resources.py
| |-- static
| | |-- favicon.ico
| | |-- logo.png
@@ -738,7 +738,7 @@ The ``myproject`` :term:`package` lives inside the ``MyProject``
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 @@ also informs Python that the directory which contains it is a *package*.
#. 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 @@ also informs Python that the directory which contains it is a *package*.
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 @@ code which accepts a :term:`request` and which returns a
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 @@ renderers, and templates relate and cooperate.
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.
-
-#. 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``.
+#. 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.
-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``
~~~~~~~~~~~~~~~~~~~~
diff --git a/pyramid/paster_templates/starter/+package+/__init__.py_tmpl b/pyramid/paster_templates/starter/+package+/__init__.py_tmpl
index 2cc9c17e0..7627e75eb 100644
--- a/pyramid/paster_templates/starter/+package+/__init__.py_tmpl
+++ b/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()
diff --git a/pyramid/paster_templates/starter/+package+/models.py b/pyramid/paster_templates/starter/+package+/models.py
deleted file mode 100644
index 75dec7505..000000000
--- a/pyramid/paster_templates/starter/+package+/models.py
+++ /dev/null
@@ -1,7 +0,0 @@
-class MyModel(object):
- pass
-
-root = MyModel()
-
-def get_root(request):
- return root
diff --git a/pyramid/paster_templates/starter/+package+/resources.py b/pyramid/paster_templates/starter/+package+/resources.py
new file mode 100644
index 000000000..3d811895c
--- /dev/null
+++ b/pyramid/paster_templates/starter/+package+/resources.py
@@ -0,0 +1,3 @@
+class Root(object):
+ def __init__(self, request):
+ self.request = request
diff --git a/pyramid/paster_templates/starter_zcml/+package+/__init__.py_tmpl b/pyramid/paster_templates/starter_zcml/+package+/__init__.py_tmpl
index 56d201f19..896aabca7 100644
--- a/pyramid/paster_templates/starter_zcml/+package+/__init__.py_tmpl
+++ b/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()
diff --git a/pyramid/paster_templates/starter_zcml/+package+/configure.zcml b/pyramid/paster_templates/starter_zcml/+package+/configure.zcml
index e5715718a..41e40866b 100644
--- a/pyramid/paster_templates/starter_zcml/+package+/configure.zcml
+++ b/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"
/>
diff --git a/pyramid/paster_templates/starter_zcml/+package+/models.py b/pyramid/paster_templates/starter_zcml/+package+/models.py
deleted file mode 100644
index 75dec7505..000000000
--- a/pyramid/paster_templates/starter_zcml/+package+/models.py
+++ /dev/null
@@ -1,7 +0,0 @@
-class MyModel(object):
- pass
-
-root = MyModel()
-
-def get_root(request):
- return root
diff --git a/pyramid/paster_templates/starter_zcml/+package+/resources.py b/pyramid/paster_templates/starter_zcml/+package+/resources.py
new file mode 100644
index 000000000..3d811895c
--- /dev/null
+++ b/pyramid/paster_templates/starter_zcml/+package+/resources.py
@@ -0,0 +1,3 @@
+class Root(object):
+ def __init__(self, request):
+ self.request = request