diff options
| author | Chris McDonough <chrism@plope.com> | 2010-12-18 15:53:49 -0500 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2010-12-18 15:53:49 -0500 |
| commit | 738a2b5f3eb44da7036a31005144e5252827ac38 (patch) | |
| tree | 80e10d2ae215b2e0e1f248354b6c9a5e11406cd5 /docs/tutorials | |
| parent | aa6c4267b330a5665dcb7c98d75fe21f8eeececb (diff) | |
| parent | 70119302324e5bf5627344f90c62ef31b6e43005 (diff) | |
| download | pyramid-738a2b5f3eb44da7036a31005144e5252827ac38.tar.gz pyramid-738a2b5f3eb44da7036a31005144e5252827ac38.tar.bz2 pyramid-738a2b5f3eb44da7036a31005144e5252827ac38.zip | |
Merge branch 'model2resource'
Conflicts:
docs/narr/views.rst
Diffstat (limited to 'docs/tutorials')
| -rw-r--r-- | docs/tutorials/catalog/index.rst | 4 | ||||
| -rw-r--r-- | docs/tutorials/wiki/basiclayout.rst | 14 | ||||
| -rw-r--r-- | docs/tutorials/wiki/definingmodels.rst | 22 | ||||
| -rw-r--r-- | docs/tutorials/wiki/definingviews.rst | 18 | ||||
| -rw-r--r-- | docs/tutorials/wiki/src/authorization/tutorial/login.py | 6 | ||||
| -rw-r--r-- | docs/tutorials/wiki/src/authorization/tutorial/tests.py | 25 | ||||
| -rw-r--r-- | docs/tutorials/wiki/src/authorization/tutorial/views.py | 16 | ||||
| -rw-r--r-- | docs/tutorials/wiki/src/viewdecorators/tutorial/tests.py | 25 | ||||
| -rw-r--r-- | docs/tutorials/wiki/src/viewdecorators/tutorial/views.py | 16 | ||||
| -rw-r--r-- | docs/tutorials/wiki/src/views/tutorial/tests.py | 24 | ||||
| -rw-r--r-- | docs/tutorials/wiki/src/views/tutorial/views.py | 16 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/definingmodels.rst | 12 |
12 files changed, 103 insertions, 95 deletions
diff --git a/docs/tutorials/catalog/index.rst b/docs/tutorials/catalog/index.rst index 43b078edc..e4e5bd720 100644 --- a/docs/tutorials/catalog/index.rst +++ b/docs/tutorials/catalog/index.rst @@ -88,11 +88,11 @@ want the application to be based on :term:`traversal`. Python 2.5.4 (r254:67916, Sep 4 2009, 02:12:16) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help" for more information. "root" is the Pyramid app root object. - >>> from pyramid.traversal import model_path + >>> from pyramid.traversal import resource_path >>> from myapp.models import Document >>> root['name'] = Document('title') >>> doc = root['name'] - >>> docid = root.catalog.document_map.add(model_path(doc)) + >>> docid = root.catalog.document_map.add(resource_path(doc)) >>> root.catalog.index_doc(docid, doc) >>> import transaction >>> transaction.commit() diff --git a/docs/tutorials/wiki/basiclayout.rst b/docs/tutorials/wiki/basiclayout.rst index 3dbf10bd8..c7c722f70 100644 --- a/docs/tutorials/wiki/basiclayout.rst +++ b/docs/tutorials/wiki/basiclayout.rst @@ -98,11 +98,15 @@ following: Content Models with ``models.py`` --------------------------------- -:app:`Pyramid` often uses the word :term:`model` when talking about -content resources arranged in the hierarchical *object graph* -consulted by :term:`traversal`. The ``models.py`` file is where the -``pyramid_zodb`` Paster template put the classes that implement our -model objects. +:app:`Pyramid` uses the word :term:`resource` to describe objects arranged +hierarchically in a :term:`resource tree`. This tree is consulted by +:term:`traversal` to map URLs to code. In this application, the resource +tree represents the site structure, but it *also* represents the +:term:`domain model` of the application, because eeach resource is a node +stored persistently in a :term:`ZODB` database. The ``models.py`` file is +where the ``pyramid_zodb`` Paster template put the classes that implement our +resource objects, each of which happens also to be a domain model +object. Here is the source for ``models.py``: diff --git a/docs/tutorials/wiki/definingmodels.rst b/docs/tutorials/wiki/definingmodels.rst index 097485047..f317d31dd 100644 --- a/docs/tutorials/wiki/definingmodels.rst +++ b/docs/tutorials/wiki/definingmodels.rst @@ -1,15 +1,17 @@ -=============== -Defining Models -=============== +========================= +Defining the Domain Model +========================= The first change we'll make to our bone-stock ``paster`` -generated -application will be to define a number of :term:`model` constructors. -For this application, which will be a Wiki, we will need two kinds of -model constructors: a "Wiki" model constructor, and a "Page" model -constructor. Both our Page and Wiki constructors will be class -objects. A single instance of the "Wiki" class will serve as a -container for "Page" objects, which will be instances of the "Page" -class. +application will be to define a number of :term:`resource` constructors. +Remember that, because we're using :term:`ZODB` to represent our +:term:`resource tree`, each of these resource constructors represents a +:term:`domain model` object, so we'll call these constructors "model +constructors". For this application, which will be a Wiki, we will need two +kinds of model constructors: a "Wiki" model constructor, and a "Page" model +constructor. Both our Page and Wiki constructors will be class objects. A +single instance of the "Wiki" class will serve as a container for "Page" +objects, which will be instances of the "Page" class. The source code for this tutorial stage can be browsed via `http://github.com/Pylons/pyramid/tree/master/docs/tutorials/wiki/src/models/ diff --git a/docs/tutorials/wiki/definingviews.rst b/docs/tutorials/wiki/definingviews.rst index 97314fb77..5250cb5e5 100644 --- a/docs/tutorials/wiki/definingviews.rst +++ b/docs/tutorials/wiki/definingviews.rst @@ -51,15 +51,15 @@ wiki itself (it will answer on the root URL), another named The ``view_wiki`` view function ------------------------------- -The ``view_wiki`` function will be configured to respond as the -default view of a ``Wiki`` model object. It always redirects to the -``Page`` object named "FrontPage". It returns an instance of the -:class:`pyramid.httpexceptions.HTTPFound` class (instances of which -implement the WebOb :term:`response` interface), and the -:func:`pyramid.url.model_url` API. :func:`pyramid.url.model_url` -constructs a URL to the ``FrontPage`` page -(e.g. ``http://localhost:6543/FrontPage``), and uses it as the -"location" of the HTTPFound response, forming an HTTP redirect. +The ``view_wiki`` function will be configured to respond as the default view +of a ``Wiki`` model object. It always redirects to the ``Page`` object named +"FrontPage". It returns an instance of the +:class:`pyramid.httpexceptions.HTTPFound` class (instances of which implement +the WebOb :term:`response` interface), and the +:func:`pyramid.url.resource_url` API. :func:`pyramid.url.resource_url` +constructs a URL to the ``FrontPage`` page resource +(e.g. ``http://localhost:6543/FrontPage``), and uses it as the "location" of +the HTTPFound response, forming an HTTP redirect. The ``view_page`` view function ------------------------------- diff --git a/docs/tutorials/wiki/src/authorization/tutorial/login.py b/docs/tutorials/wiki/src/authorization/tutorial/login.py index 60e69fddf..a1194feb0 100644 --- a/docs/tutorials/wiki/src/authorization/tutorial/login.py +++ b/docs/tutorials/wiki/src/authorization/tutorial/login.py @@ -1,7 +1,7 @@ from pyramid.httpexceptions import HTTPFound from pyramid.view import view_config -from pyramid.url import model_url +from pyramid.url import resource_url from pyramid.security import remember from pyramid.security import forget @@ -11,7 +11,7 @@ from tutorial.security import USERS @view_config(context=Wiki, name='login', renderer='templates/login.pt') def login(request): - login_url = model_url(request.context, request, 'login') + login_url = resource_url(request.context, request, 'login') referrer = request.url if referrer == login_url: referrer = '/' # never use the login form itself as came_from @@ -39,6 +39,6 @@ def login(request): @view_config(context=Wiki, name='logout') def logout(request): headers = forget(request) - return HTTPFound(location = model_url(request.context, request), + return HTTPFound(location = resource_url(request.context, request), headers = headers) diff --git a/docs/tutorials/wiki/src/authorization/tutorial/tests.py b/docs/tutorials/wiki/src/authorization/tutorial/tests.py index d082fb84d..aaf753816 100644 --- a/docs/tutorials/wiki/src/authorization/tutorial/tests.py +++ b/docs/tutorials/wiki/src/authorization/tutorial/tests.py @@ -43,7 +43,7 @@ class AppmakerTests(unittest.TestCase): class ViewWikiTests(unittest.TestCase): def test_it(self): from tutorial.views import view_wiki - context = testing.DummyModel() + context = testing.DummyResource() request = testing.DummyRequest() response = view_wiki(context, request) self.assertEqual(response.location, 'http://example.com/FrontPage') @@ -54,9 +54,9 @@ class ViewPageTests(unittest.TestCase): return view_page(context, request) def test_it(self): - wiki = testing.DummyModel() - wiki['IDoExist'] = testing.DummyModel() - context = testing.DummyModel(data='Hello CruelWorld IDoExist') + wiki = testing.DummyResource() + wiki['IDoExist'] = testing.DummyResource() + context = testing.DummyResource(data='Hello CruelWorld IDoExist') context.__parent__ = wiki context.__name__ = 'thepage' request = testing.DummyRequest() @@ -80,17 +80,18 @@ class AddPageTests(unittest.TestCase): return add_page(context, request) def test_it_notsubmitted(self): - from pyramid.url import model_url - context = testing.DummyModel() + from pyramid.url import resource_url + context = testing.DummyResource() request = testing.DummyRequest() request.subpath = ['AnotherPage'] info = self._callFUT(context, request) self.assertEqual(info['page'].data,'') self.assertEqual(info['save_url'], - model_url(context, request, 'add_page', 'AnotherPage')) + resource_url( + context, request, 'add_page', 'AnotherPage')) def test_it_submitted(self): - context = testing.DummyModel() + context = testing.DummyResource() request = testing.DummyRequest({'form.submitted':True, 'body':'Hello yo!'}) request.subpath = ['AnotherPage'] @@ -106,16 +107,16 @@ class EditPageTests(unittest.TestCase): return edit_page(context, request) def test_it_notsubmitted(self): - from pyramid.url import model_url - context = testing.DummyModel() + from pyramid.url import resource_url + context = testing.DummyResource() request = testing.DummyRequest() info = self._callFUT(context, request) self.assertEqual(info['page'], context) self.assertEqual(info['save_url'], - model_url(context, request, 'edit_page')) + resource_url(context, request, 'edit_page')) def test_it_submitted(self): - context = testing.DummyModel() + context = testing.DummyResource() request = testing.DummyRequest({'form.submitted':True, 'body':'Hello yo!'}) response = self._callFUT(context, request) diff --git a/docs/tutorials/wiki/src/authorization/tutorial/views.py b/docs/tutorials/wiki/src/authorization/tutorial/views.py index 48e4e2b43..3143ab552 100644 --- a/docs/tutorials/wiki/src/authorization/tutorial/views.py +++ b/docs/tutorials/wiki/src/authorization/tutorial/views.py @@ -2,7 +2,7 @@ from docutils.core import publish_parts import re from pyramid.httpexceptions import HTTPFound -from pyramid.url import model_url +from pyramid.url import resource_url from pyramid.security import authenticated_userid @@ -16,7 +16,7 @@ wikiwords = re.compile(r"\b([A-Z]\w+[A-Z]+\w+)") @view_config(context=Wiki, permission='view') def view_wiki(context, request): - return HTTPFound(location = model_url(context, request, 'FrontPage')) + return HTTPFound(location = resource_url(context, request, 'FrontPage')) @view_config(context=Page, renderer='templates/view.pt', permission='view') def view_page(context, request): @@ -26,7 +26,7 @@ def view_page(context, request): word = match.group(1) if word in wiki: page = wiki[word] - view_url = model_url(page, request) + view_url = resource_url(page, request) return '<a href="%s">%s</a>' % (view_url, word) else: add_url = request.application_url + '/add_page/' + word @@ -34,7 +34,7 @@ def view_page(context, request): content = publish_parts(context.data, writer_name='html')['html_body'] content = wikiwords.sub(check, content) - edit_url = model_url(context, request, 'edit_page') + edit_url = resource_url(context, request, 'edit_page') logged_in = authenticated_userid(request) @@ -51,8 +51,8 @@ def add_page(context, request): page.__name__ = name page.__parent__ = context context[name] = page - return HTTPFound(location = model_url(page, request)) - save_url = model_url(context, request, 'add_page', name) + return HTTPFound(location = resource_url(page, request)) + save_url = resource_url(context, request, 'add_page', name) page = Page('') page.__name__ = name page.__parent__ = context @@ -66,11 +66,11 @@ def add_page(context, request): def edit_page(context, request): if 'form.submitted' in request.params: context.data = request.params['body'] - return HTTPFound(location = model_url(context, request)) + return HTTPFound(location = resource_url(context, request)) logged_in = authenticated_userid(request) return dict(page = context, - save_url = model_url(context, request, 'edit_page'), + save_url = resource_url(context, request, 'edit_page'), logged_in = logged_in) diff --git a/docs/tutorials/wiki/src/viewdecorators/tutorial/tests.py b/docs/tutorials/wiki/src/viewdecorators/tutorial/tests.py index d082fb84d..aaf753816 100644 --- a/docs/tutorials/wiki/src/viewdecorators/tutorial/tests.py +++ b/docs/tutorials/wiki/src/viewdecorators/tutorial/tests.py @@ -43,7 +43,7 @@ class AppmakerTests(unittest.TestCase): class ViewWikiTests(unittest.TestCase): def test_it(self): from tutorial.views import view_wiki - context = testing.DummyModel() + context = testing.DummyResource() request = testing.DummyRequest() response = view_wiki(context, request) self.assertEqual(response.location, 'http://example.com/FrontPage') @@ -54,9 +54,9 @@ class ViewPageTests(unittest.TestCase): return view_page(context, request) def test_it(self): - wiki = testing.DummyModel() - wiki['IDoExist'] = testing.DummyModel() - context = testing.DummyModel(data='Hello CruelWorld IDoExist') + wiki = testing.DummyResource() + wiki['IDoExist'] = testing.DummyResource() + context = testing.DummyResource(data='Hello CruelWorld IDoExist') context.__parent__ = wiki context.__name__ = 'thepage' request = testing.DummyRequest() @@ -80,17 +80,18 @@ class AddPageTests(unittest.TestCase): return add_page(context, request) def test_it_notsubmitted(self): - from pyramid.url import model_url - context = testing.DummyModel() + from pyramid.url import resource_url + context = testing.DummyResource() request = testing.DummyRequest() request.subpath = ['AnotherPage'] info = self._callFUT(context, request) self.assertEqual(info['page'].data,'') self.assertEqual(info['save_url'], - model_url(context, request, 'add_page', 'AnotherPage')) + resource_url( + context, request, 'add_page', 'AnotherPage')) def test_it_submitted(self): - context = testing.DummyModel() + context = testing.DummyResource() request = testing.DummyRequest({'form.submitted':True, 'body':'Hello yo!'}) request.subpath = ['AnotherPage'] @@ -106,16 +107,16 @@ class EditPageTests(unittest.TestCase): return edit_page(context, request) def test_it_notsubmitted(self): - from pyramid.url import model_url - context = testing.DummyModel() + from pyramid.url import resource_url + context = testing.DummyResource() request = testing.DummyRequest() info = self._callFUT(context, request) self.assertEqual(info['page'], context) self.assertEqual(info['save_url'], - model_url(context, request, 'edit_page')) + resource_url(context, request, 'edit_page')) def test_it_submitted(self): - context = testing.DummyModel() + context = testing.DummyResource() request = testing.DummyRequest({'form.submitted':True, 'body':'Hello yo!'}) response = self._callFUT(context, request) diff --git a/docs/tutorials/wiki/src/viewdecorators/tutorial/views.py b/docs/tutorials/wiki/src/viewdecorators/tutorial/views.py index 168965db2..c8ac46edf 100644 --- a/docs/tutorials/wiki/src/viewdecorators/tutorial/views.py +++ b/docs/tutorials/wiki/src/viewdecorators/tutorial/views.py @@ -2,7 +2,7 @@ from docutils.core import publish_parts import re from pyramid.httpexceptions import HTTPFound -from pyramid.url import model_url +from pyramid.url import resource_url from pyramid.view import view_config from tutorial.models import Page @@ -13,7 +13,7 @@ wikiwords = re.compile(r"\b([A-Z]\w+[A-Z]+\w+)") @view_config(context=Wiki) def view_wiki(context, request): - return HTTPFound(location = model_url(context, request, 'FrontPage')) + return HTTPFound(location = resource_url(context, request, 'FrontPage')) @view_config(context=Page, renderer='templates/view.pt') def view_page(context, request): @@ -23,7 +23,7 @@ def view_page(context, request): word = match.group(1) if word in wiki: page = wiki[word] - view_url = model_url(page, request) + view_url = resource_url(page, request) return '<a href="%s">%s</a>' % (view_url, word) else: add_url = request.application_url + '/add_page/' + word @@ -31,7 +31,7 @@ def view_page(context, request): content = publish_parts(context.data, writer_name='html')['html_body'] content = wikiwords.sub(check, content) - edit_url = model_url(context, request, 'edit_page') + edit_url = resource_url(context, request, 'edit_page') return dict(page = context, content = content, edit_url = edit_url) @view_config(context=Wiki, name='add_page', renderer='templates/edit.pt') @@ -43,8 +43,8 @@ def add_page(context, request): page.__name__ = name page.__parent__ = context context[name] = page - return HTTPFound(location = model_url(page, request)) - save_url = model_url(context, request, 'add_page', name) + return HTTPFound(location = resource_url(page, request)) + save_url = resource_url(context, request, 'add_page', name) page = Page('') page.__name__ = name page.__parent__ = context @@ -54,9 +54,9 @@ def add_page(context, request): def edit_page(context, request): if 'form.submitted' in request.params: context.data = request.params['body'] - return HTTPFound(location = model_url(context, request)) + return HTTPFound(location = resource_url(context, request)) return dict(page = context, - save_url = model_url(context, request, 'edit_page')) + save_url = resource_url(context, request, 'edit_page')) diff --git a/docs/tutorials/wiki/src/views/tutorial/tests.py b/docs/tutorials/wiki/src/views/tutorial/tests.py index c5aafcac5..28e424884 100644 --- a/docs/tutorials/wiki/src/views/tutorial/tests.py +++ b/docs/tutorials/wiki/src/views/tutorial/tests.py @@ -43,7 +43,7 @@ class AppmakerTests(unittest.TestCase): class ViewWikiTests(unittest.TestCase): def test_it(self): from tutorial.views import view_wiki - context = testing.DummyModel() + context = testing.DummyResource() request = testing.DummyRequest() response = view_wiki(context, request) self.assertEqual(response.location, 'http://example.com/FrontPage') @@ -54,9 +54,9 @@ class ViewPageTests(unittest.TestCase): return view_page(context, request) def test_it(self): - wiki = testing.DummyModel() - wiki['IDoExist'] = testing.DummyModel() - context = testing.DummyModel(data='Hello CruelWorld IDoExist') + wiki = testing.DummyResource() + wiki['IDoExist'] = testing.DummyResource() + context = testing.DummyResource(data='Hello CruelWorld IDoExist') context.__parent__ = wiki context.__name__ = 'thepage' request = testing.DummyRequest() @@ -80,18 +80,18 @@ class AddPageTests(unittest.TestCase): return add_page(context, request) def test_it_notsubmitted(self): - from pyramid.url import model_url - context = testing.DummyModel() + from pyramid.url import resource_url + context = testing.DummyResource() request = testing.DummyRequest() request.subpath = ['AnotherPage'] info = self._callFUT(context, request) self.assertEqual(info['page'].data,'') self.assertEqual( info['save_url'], - model_url(context, request, 'add_page', 'AnotherPage')) + resource_url(context, request, 'add_page', 'AnotherPage')) def test_it_submitted(self): - context = testing.DummyModel() + context = testing.DummyResource() request = testing.DummyRequest({'form.submitted':True, 'body':'Hello yo!'}) request.subpath = ['AnotherPage'] @@ -107,16 +107,16 @@ class EditPageTests(unittest.TestCase): return edit_page(context, request) def test_it_notsubmitted(self): - from pyramid.url import model_url - context = testing.DummyModel() + from pyramid.url import resource_url + context = testing.DummyResource() request = testing.DummyRequest() info = self._callFUT(context, request) self.assertEqual(info['page'], context) self.assertEqual(info['save_url'], - model_url(context, request, 'edit_page')) + resource_url(context, request, 'edit_page')) def test_it_submitted(self): - context = testing.DummyModel() + context = testing.DummyResource() request = testing.DummyRequest({'form.submitted':True, 'body':'Hello yo!'}) response = self._callFUT(context, request) diff --git a/docs/tutorials/wiki/src/views/tutorial/views.py b/docs/tutorials/wiki/src/views/tutorial/views.py index acc1bbb57..8437fdc51 100644 --- a/docs/tutorials/wiki/src/views/tutorial/views.py +++ b/docs/tutorials/wiki/src/views/tutorial/views.py @@ -2,7 +2,7 @@ from docutils.core import publish_parts import re from pyramid.httpexceptions import HTTPFound -from pyramid.url import model_url +from pyramid.url import resource_url from tutorial.models import Page @@ -10,7 +10,7 @@ from tutorial.models import Page wikiwords = re.compile(r"\b([A-Z]\w+[A-Z]+\w+)") def view_wiki(context, request): - return HTTPFound(location = model_url(context, request, 'FrontPage')) + return HTTPFound(location = resource_url(context, request, 'FrontPage')) def view_page(context, request): wiki = context.__parent__ @@ -19,7 +19,7 @@ def view_page(context, request): word = match.group(1) if word in wiki: page = wiki[word] - view_url = model_url(page, request) + view_url = resource_url(page, request) return '<a href="%s">%s</a>' % (view_url, word) else: add_url = request.application_url + '/add_page/' + word @@ -27,7 +27,7 @@ def view_page(context, request): content = publish_parts(context.data, writer_name='html')['html_body'] content = wikiwords.sub(check, content) - edit_url = model_url(context, request, 'edit_page') + edit_url = resource_url(context, request, 'edit_page') return dict(page = context, content = content, edit_url = edit_url) def add_page(context, request): @@ -38,8 +38,8 @@ def add_page(context, request): page.__name__ = name page.__parent__ = context context[name] = page - return HTTPFound(location = model_url(page, request)) - save_url = model_url(context, request, 'add_page', name) + return HTTPFound(location = resource_url(page, request)) + save_url = resource_url(context, request, 'add_page', name) page = Page('') page.__name__ = name page.__parent__ = context @@ -48,9 +48,9 @@ def add_page(context, request): def edit_page(context, request): if 'form.submitted' in request.params: context.data = request.params['body'] - return HTTPFound(location = model_url(context, request)) + return HTTPFound(location = resource_url(context, request)) return dict(page = context, - save_url = model_url(context, request, 'edit_page')) + save_url = resource_url(context, request, 'edit_page')) diff --git a/docs/tutorials/wiki2/definingmodels.rst b/docs/tutorials/wiki2/definingmodels.rst index b710e1396..09e1f26c3 100644 --- a/docs/tutorials/wiki2/definingmodels.rst +++ b/docs/tutorials/wiki2/definingmodels.rst @@ -1,10 +1,10 @@ -=============== -Defining Models -=============== +========================= +Defining the Domain Model +========================= -The first change we'll make to our stock paster-generated application -will be to define a :term:`model` constructor representing a wiki -page. We'll do this inside our ``models.py`` file. +The first change we'll make to our stock paster-generated application will be +to define a :term:`domain model` constructor representing a wiki page. We'll +do this inside our ``models.py`` file. The source code for this tutorial stage can be browsed at `http://github.com/Pylons/pyramid/tree/master/docs/tutorials/wiki2/src/models/ |
