Is there a terser way to get a reference to my DB than self.request.root.db?
67 views
Skip to first unread message
Zak
unread,
Aug 11, 2012, 2:03:24 AM8/11/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pylons-...@googlegroups.com
self.request.root.db is quite a bit of dot notation and I'm wondering if there is a shortcut or better way to get db.
Malthe Borch
unread,
Aug 11, 2012, 3:08:18 AM8/11/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pylons-...@googlegroups.com
You could write a base class that defined it as a `property`.
On 11 August 2012 08:03, Zak <zakd...@gmail.com> wrote:
> self.request.root.db is quite a bit of dot notation and I'm wondering if
> there is a shortcut or better way to get db.
>
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pylons-discuss
storing the db connection somewhere under the active request is the
optimal thing to do -- it makes the db generally accessible throughout
the app.
there are some ways to make it easier to get to:
- if you use a class based approach to writing views, you could have a
base class that does much of the work
- you could write a helper function
class base_class(object):
def dbSession(self):
return self.request.root.db
def getDbSession(request=None):
if not request:
request= get_current_request():
return request.root.db
kusut
unread,
Aug 12, 2012, 12:10:59 AM8/12/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pylons-...@googlegroups.com
On 12 August 2012 04:07, Jonathan Vanasco <jona...@findmeon.com> wrote:
> there are some ways to make it easier to get to:
> - if you use a class based approach to writing views, you could have a
> base class that does much of the work
> - you could write a helper function