Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Writing a decorator that returns a Pyramid view.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
andre.l.caron  
View profile  
 More options Jul 16 2012, 9:30 am
From: "andre.l.caron" <andre.l.ca...@gmail.com>
Date: Mon, 16 Jul 2012 06:30:47 -0700 (PDT)
Local: Mon, Jul 16 2012 9:30 am
Subject: Writing a decorator that returns a Pyramid view.

Hi All!

I've encountered what I believe to be a bug in Pyramid and I hope you can
help me find a solution or workaround :-)

I have some rather redundant code in Pyramid views and I'm trying to
refactor it into a decorator.  The idea is that this decorator will return
a Pyramid view function decorated with @view_config and the redundant code
will be put into this "generated" function so that it automagically applies
in all view functions.  This works fine, but as soon as I move my decorator
to a seperate module and import it (it needs to be used from multiple
modules that define views) then I get HTTP 404 errors.

I've taken a look at the Pyramid and Venusian source code, but I'm not
familiar with some of the more advanced stuff going on in Venusian to
properly determine exactly why this doesn't work.

I've attached an SSCCE[1] (~100 lines of code,with comments) that
demonstrates this problem.  Can you please take a look at it and confirm
that this is a bug (or not)?

Note: I've tried to keep this as close to possible to how it's used in the
real application.  Keep in mind that this is legacy code and I'm not behind
all the decisions (e.g. the do-it-yourself-RPC framework ;-)

Thanks,
André Caron

[1]: http://sscce.org/

  other_module.py
< 1K Download

  pyramid-bug.py
2K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Forkel  
View profile  
 More options Jul 17 2012, 2:02 am
From: Robert Forkel <xrotw...@googlemail.com>
Date: Tue, 17 Jul 2012 08:02:38 +0200
Local: Tues, Jul 17 2012 2:02 am
Subject: Re: Writing a decorator that returns a Pyramid view.
Hi André,
i guess this is with venusian >= 1.0a6. I ran into a similar problem
with cornice, and managed to find a workaround:
https://github.com/xrotwang/cornice/commit/dbbf07fb50a100c9357eef4766...
Note the depth argument passed explicitely to venusian.attach which
controls down to which depth venusian will go down the import stack
(although i didn't fully understand this feature and the need for it
myself).
This may be not possible in your case, though, if you are not calling
venusian.attach in your own code but rely on view_config.
regards
robert


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
andre.l.caron  
View profile  
 More options Jul 17 2012, 9:07 am
From: "andre.l.caron" <andre.l.ca...@gmail.com>
Date: Tue, 17 Jul 2012 06:07:03 -0700 (PDT)
Local: Tues, Jul 17 2012 9:07 am
Subject: Re: Writing a decorator that returns a Pyramid view.

Hi Robert,

Thanks for the info, I applied a custom patch to
"pyramid.view.view_config()" to add a "depth=N" argument and setting
"view_config(..., depth=2)" inside the imported decorator fixes everything.
 I'll see if I can submit a patch to the Pyramid project.

Thanks!
André


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
andre.l.caron  
View profile  
 More options Jul 17 2012, 4:56 pm
From: "andre.l.caron" <andre.l.ca...@gmail.com>
Date: Tue, 17 Jul 2012 13:56:32 -0700 (PDT)
Local: Tues, Jul 17 2012 4:56 pm
Subject: Re: Writing a decorator that returns a Pyramid view.

I submitted a [bug and a patch][1] on the Pyramid project.

[1]:  https://github.com/Pylons/pyramid/issues/637


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
andre.l.caron  
View profile  
 More options Jul 18 2012, 8:07 am
From: "andre.l.caron" <andre.l.ca...@gmail.com>
Date: Wed, 18 Jul 2012 05:07:46 -0700 (PDT)
Local: Wed, Jul 18 2012 8:07 am
Subject: Re: Writing a decorator that returns a Pyramid view.

For posterity, the Pyramid project does not intend on fixing this limitation<https://github.com/Pylons/pyramid/pull/638#issuecomment-7050642>.
 If you encounter this problem, you will have to bypass the use of
`@view_config` and use `Configurator.add_view()` manually (or through some
other custom registration scheme).


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »