From f9e73ea5a9d5a4210e3a346aa2f9483d70d22ab9 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Tue, 30 Jun 2009 19:57:56 +0000 Subject: 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. --- CHANGES.txt | 4 + .../alchemy/+package+/configure.zcml | 7 +- .../paster_templates/alchemy/+package+/models.py | 11 ++- .../alchemy/+package+/templates/model.pt | 103 +++++++++++++++++++++ .../alchemy/+package+/templates/mytemplate.pt | 103 --------------------- .../alchemy/+package+/templates/root.pt | 101 ++++++++++++++++++++ .../alchemy/+package+/views.py_tmpl | 12 ++- 7 files changed, 233 insertions(+), 108 deletions(-) create mode 100644 repoze/bfg/paster_templates/alchemy/+package+/templates/model.pt delete mode 100644 repoze/bfg/paster_templates/alchemy/+package+/templates/mytemplate.pt create mode 100644 repoze/bfg/paster_templates/alchemy/+package+/templates/root.pt 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 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 @@ + + 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/model.pt b/repoze/bfg/paster_templates/alchemy/+package+/templates/model.pt new file mode 100644 index 000000000..0342ba69a --- /dev/null +++ b/repoze/bfg/paster_templates/alchemy/+package+/templates/model.pt @@ -0,0 +1,103 @@ + + + + +${project} Application + + + + + + + + + +
+ +
+ +
+
+

Welcome to ${project}, an + application generated by the repoze.bfg web + application framework.

+

+ Id: ${item.id}
+ Name: ${item.name}
+ Value: ${item.value}

+
+
+ + + + +
 
+
+
+ + + + + + diff --git a/repoze/bfg/paster_templates/alchemy/+package+/templates/mytemplate.pt b/repoze/bfg/paster_templates/alchemy/+package+/templates/mytemplate.pt deleted file mode 100644 index 302dff9fe..000000000 --- a/repoze/bfg/paster_templates/alchemy/+package+/templates/mytemplate.pt +++ /dev/null @@ -1,103 +0,0 @@ - - - - -${project} Application - - - - - - - - - -
- -
- -
-
-

Welcome to ${project}, an - application generated by the repoze.bfg web - application framework.

-

The item from the database is:

- id: ${item.id}
- name: ${item.name}
- value: ${item.value}
-
-
- - - - -
 
-
-
- - - - - - 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 @@ + + + + +${project} Application + + + + + + + + + +
+ +
+ +
+
+

Welcome to ${project}, an + application generated by the repoze.bfg web + application framework.

+

+ ${item.name}

+
+
+ + + + +
 
+
+
+ + + + + + 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}}') -- cgit v1.2.3