Hello,
I am trying to find a way to mix a bit of the traversal resource building
and the pylons controllers functions that have mapped parameters. I am also
using sqlachemy as orm (so no ZODB).
Basically, I'm looking for a way to avoid as much as possible the manual
extraction of parameters from the request object (especially
request.matchdict).
>From the sqla wiki tutorial I have:
def edit_page(request):
name = request.matchdict['pagename']
page = DBSession.query(Page).filter_by(name=name).one()
...
body = request.params['body']
I would like to use a view class and modify the latter function to have
sort of:
@view_config(...) # necessary to add context mapping?
class PageView(object):
def __init__( self, request, ... ):
self.request = request
self.context = ...
self.page = ... # instance of Page, but self.page is self.context ?
.... # index method
# the association between url http://../page/**/edit to edit_post is
missing
@view_config(request_method='POST', renderer='template/edit.html')
def edit_post(self, body):
self.page.body = body
return {'page': self.page}
# the association between url http://../page/**/delete should be
automatic
@view_config()
def delete( self ):
DBSession.delete(self.page)
... # redirect to another page...
So the url will be: http://.../page/42/edit. And the other views for
instance, http://.../page/42/delete, http://.../page/42/merge_with_page/76,
http://.../page/42/do_some_stuff and so on...
Well that's it for the handler/controller code, but all the code relative
to:
- the creation of the context
- the view mapping (url chunks to function params)
- the configuration of the association between url and the views
are missing, and that's why I'm here :)
I've read the two wiki tutorials, looked at pyramid_handlers, akhet,
pyramid_metatg, the View Mapper hook, and saw also the "View Callables as a
Class and Dependency Injection" on the list. I have perhaps to many
separate information, like pyr_handlers/pyr_metatg don't work with
traversal; traversal "should be" used with zodb, url dispatch "should be"
used with sqla; the view mapper example uses add_handler and url dispatch,
so no traversal possible. I understand the traversal mechanism, but I'm not
comfortable with the resource/context creation (the tutorial uses ZODB, I'm
using sqla)...
I also have to handle the add_page typed views, where the page has not been
created in the DB.
I'm obviously seeing that for each call to the view functions, an instance
of Page is going to be created which will be perhaps not always necessary...
And cherry on the cake, with automatic routing as the delete view example.
So, am I missing something? Is is too complicated? Or not following the
pyramid philosophy? Do I really have to use traversal?
( I come from a turbogears2 background, so my mind may be a bit
unconsciously biased. )
Thanks a lot, cheers.
pipoun
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/pylons-discuss/-/F75c9fgZbPYJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.