diff options
| author | Tres Seaver <tseaver@palladion.com> | 2009-06-30 19:57:56 +0000 |
|---|---|---|
| committer | Tres Seaver <tseaver@palladion.com> | 2009-06-30 19:57:56 +0000 |
| commit | f9e73ea5a9d5a4210e3a346aa2f9483d70d22ab9 (patch) | |
| tree | 83d10e61df15996bb836a0bc8f73ba5dbf36559b | |
| parent | 3f7e15999ee9f9b02271ccb54d0525946be4b259 (diff) | |
| download | pyramid-f9e73ea5a9d5a4210e3a346aa2f9483d70d22ab9.tar.gz pyramid-f9e73ea5a9d5a4210e3a346aa2f9483d70d22ab9.tar.bz2 pyramid-f9e73ea5a9d5a4210e3a346aa2f9483d70d22ab9.zip | |
Updated the ``bfg_alchemy`` paster template to include two views:
- The view on the root shows a list of links to records.
- The view on a record shows the details for that object.
| -rw-r--r-- | CHANGES.txt | 4 | ||||
| -rw-r--r-- | repoze/bfg/paster_templates/alchemy/+package+/configure.zcml | 7 | ||||
| -rwxr-xr-x | repoze/bfg/paster_templates/alchemy/+package+/models.py | 11 | ||||
| -rw-r--r-- | repoze/bfg/paster_templates/alchemy/+package+/templates/model.pt (renamed from repoze/bfg/paster_templates/alchemy/+package+/templates/mytemplate.pt) | 8 | ||||
| -rw-r--r-- | repoze/bfg/paster_templates/alchemy/+package+/templates/root.pt | 101 | ||||
| -rw-r--r-- | repoze/bfg/paster_templates/alchemy/+package+/views.py_tmpl | 12 |
6 files changed, 134 insertions, 9 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 7ff778ec4..d8a72991b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,10 @@ Next release ============ +- Updated the ``bfg_alchemy`` paster template to include two views: + the view on the root shows a list of links to records; the view on + a record shows the details for that object. + - Register a ``repoze.bfg.resource.OverrideProvider`` as a pkg_resources provider only for modules which are known to have overrides, instead of globally, when a <resource> directive is used diff --git a/repoze/bfg/paster_templates/alchemy/+package+/configure.zcml b/repoze/bfg/paster_templates/alchemy/+package+/configure.zcml index cb2c6c999..2ce917de8 100644 --- a/repoze/bfg/paster_templates/alchemy/+package+/configure.zcml +++ b/repoze/bfg/paster_templates/alchemy/+package+/configure.zcml @@ -5,7 +5,7 @@ <view for=".models.MyApp" - view=".views.my_view" + view=".views.view_root" /> <view @@ -14,6 +14,11 @@ name="static" /> + <view + for=".models.MyModel" + view=".views.view_model" + /> + <subscriber for="repoze.bfg.interfaces.INewRequest" handler=".run.handle_teardown" /> diff --git a/repoze/bfg/paster_templates/alchemy/+package+/models.py b/repoze/bfg/paster_templates/alchemy/+package+/models.py index 41c1d37e2..ee57dc5e7 100755 --- a/repoze/bfg/paster_templates/alchemy/+package+/models.py +++ b/repoze/bfg/paster_templates/alchemy/+package+/models.py @@ -40,7 +40,11 @@ class MyApp(object): def __getitem__(self, key): session= DBSession() - query = session.query(MyModel).filter_by(name=key) + try: + key = int(key) + except (ValueError, TypeError): + raise KeyError(key) + query = session.query(MyModel).filter_by(id=key) try: item = query.one() item.__parent__ = self @@ -56,6 +60,11 @@ class MyApp(object): item = default return item + def __iter__(self): + session= DBSession() + query = session.query(MyModel) + return iter(query) + root = MyApp() def default_get_root(environ): diff --git a/repoze/bfg/paster_templates/alchemy/+package+/templates/mytemplate.pt b/repoze/bfg/paster_templates/alchemy/+package+/templates/model.pt index 302dff9fe..0342ba69a 100644 --- a/repoze/bfg/paster_templates/alchemy/+package+/templates/mytemplate.pt +++ b/repoze/bfg/paster_templates/alchemy/+package+/templates/model.pt @@ -28,10 +28,10 @@ application generated by the <a href="http://bfg.repoze.org">repoze.bfg</a> web application framework.</h1> - <p>The item from the database is:</p> - <b>id:</b> ${item.id}<br/> - <b>name:</b> ${item.name}<br/> - <b>value:</b> ${item.value}<br/> + <p> + <b>Id:</b> ${item.id}<br /> + <b>Name:</b> ${item.name}<br /> + <b>Value:</b> ${item.value}</p> </div> </div> <!-- end content --> diff --git a/repoze/bfg/paster_templates/alchemy/+package+/templates/root.pt b/repoze/bfg/paster_templates/alchemy/+package+/templates/root.pt new file mode 100644 index 000000000..94354b50e --- /dev/null +++ b/repoze/bfg/paster_templates/alchemy/+package+/templates/root.pt @@ -0,0 +1,101 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:tal="http://xml.zope.org/namespaces/tal"> +<head> +<meta http-equiv="content-type" content="text/html; charset=utf-8" /> +<title>${project} Application</title> +<meta name="keywords" content="python web application" /> +<meta name="description" content="repoze.bfg web application" /> +<link href="${request.application_url}/static/default.css" rel="stylesheet" type="text/css" /> +</head> +<body> +<!-- start header --> +<div id="logo"> + <h2><code>${project}</code>, a <code>repoze.bfg</code> application</h2> +</div> +<div id="header"> + <div id="menu"> + </div> +</div> +<!-- end header --> +<div id="wrapper"> + <!-- start page --> + <div id="page"> + <!-- start content --> + <div id="content"> + <div class="post"> + <h1 class="title">Welcome to <code>${project}</code>, an + application generated by the <a + href="http://bfg.repoze.org">repoze.bfg</a> web + application framework.</h1> + <p tal:repeat="item items"> + <a href="${item.id}">${item.name}</a></p> + </div> + </div> + <!-- end content --> + <!-- start sidebar --> + <div id="sidebar"> + <ul> + <li id="search"> + <h2>Search<br/> <code>repoze.bfg</code> Documentation</h2> + <form method="get" + action="http://bfg.repoze.org/searchresults"> + <fieldset> + <input type="text" id="q" name="text" value="" /> + <input type="submit" id="x" value="Search" /> + </fieldset> + </form> + </li> + <li> + <h2><code>repoze.bfg</code> links</h2> + <ul> + <li><a + href="http://docs.repoze.org/bfg/#narrative-documentation">Narrative + Documentation</a> + </li> + <li> + <a + href="http://docs.repoze.org/bfg/#api-documentation">API + Documentation</a> + </li> + <li> + <a + href="http://docs.repoze.org/bfg/#tutorials">Tutorials</a> + </li> + <li> + <a + href="http://docs.repoze.org/bfg/#change-history">Change + History</a> + </li> + <li> + <a + href="http://docs.repoze.org/bfg/#sample-applications">Sample + Applications</a> + </li> + <li> + <a + href="http://docs.repoze.org/bfg/#support-and-development">Support + and Development</a> + </li> + <li> + <a + href="irc://irc.freenode.net#repoze">IRC Channel</a> + </li> + </ul> + </li> + </ul> + </div> + <!-- end sidebar --> + <div style="clear: both;"> </div> + </div> +</div> +<!-- end page --> +<!-- start footer --> +<div id="footer"> + <p id="legal">( c ) 2008. All Rights Reserved. Template design + by <a href="http://www.freecsstemplates.org/">Free CSS + Templates</a>.</p> +</div> +<!-- end footer --> +</body> +</html> diff --git a/repoze/bfg/paster_templates/alchemy/+package+/views.py_tmpl b/repoze/bfg/paster_templates/alchemy/+package+/views.py_tmpl index 832f64ec5..f34868ad1 100644 --- a/repoze/bfg/paster_templates/alchemy/+package+/views.py_tmpl +++ b/repoze/bfg/paster_templates/alchemy/+package+/views.py_tmpl @@ -3,8 +3,14 @@ from repoze.bfg.view import static static_view = static('templates/static') -def my_view(context, request): - return render_template_to_response('templates/mytemplate.pt', +def view_root(context, request): + return render_template_to_response('templates/root.pt', request = request, - item = context[u'test name'], + items = list(context), + project = '{{project}}') + +def view_model(context, request): + return render_template_to_response('templates/model.pt', + request = request, + item = context, project = '{{project}}') |
