Iterating through the views of a resource

53 views
Skip to first unread message

Theron Luhn

unread,
Feb 23, 2017, 12:45:11 AM2/23/17
to pylons-discuss
I'm looking in to getting something like https://github.com/SurveyMonkey/pyramid_autodoc working for my project.  Unfortunately, it appears to only work for URL dispatch and I'm using URL traversal.  I'm trying to figure out how I might adapt it to work with my project.

One thing I can't figure out is how to extract the view callables from Pyramid (since I need them for the docstrings).  Is there someway I can get a list of the view callables and the associated resource?  Or perhaps given a resource, iterate through all associated view callables?

Mikko Ohtamaa

unread,
Feb 23, 2017, 3:13:45 AM2/23/17
to pylons-...@googlegroups.com
Hey Theron,


One thing I can't figure out is how to extract the view callables from Pyramid (since I need them for the docstrings).  Is there someway I can get a list of the view callables and the associated resource?  Or perhaps given a resource, iterate through all associated view callables?

I am not sure if this helps, but I recursively traverse all site resources and views for a sitemap:

https://github.com/websauna/websauna/blob/master/websauna/system/core/sitemap.py#L316

It's easy to get views for a given resource context object. You can probably query all views for any context object directly from the underlying Zope component registry.
 

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/916cf024-e60e-4463-9d91-a791701c9c0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Theron Luhn

unread,
Mar 7, 2017, 2:00:14 AM3/7/17
to pylons-...@googlegroups.com
Thanks!  That pushed me in the right direction, I think I have it figured out now.

— Theron



You received this message because you are subscribed to a topic in the Google Groups "pylons-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pylons-discuss/PokpluvF688/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pylons-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/CAK8RCUtWcORQm2BJoa-bB4ZNXkousezutM4xFLY7Yoq6hZyCdw%40mail.gmail.com.

Mikko Ohtamaa

unread,
Mar 7, 2017, 4:27:02 PM3/7/17
to pylons-...@googlegroups.com
Hi Theron,

Can you share your art when you figure out it? E.g. a link to Gist on Github. I feel this would be beneficial to record it down in cookbook for everbody.

Best regards,
Mikko

On 7 March 2017 at 09:00, Theron Luhn <the...@luhn.com> wrote:
Thanks!  That pushed me in the right direction, I think I have it figured out now.

— Theron



On Feb 23, 2017, at 12:13 AM, Mikko Ohtamaa <mi...@redinnovation.com> wrote:

Hey Theron,


One thing I can't figure out is how to extract the view callables from Pyramid (since I need them for the docstrings).  Is there someway I can get a list of the view callables and the associated resource?  Or perhaps given a resource, iterate through all associated view callables?

I am not sure if this helps, but I recursively traverse all site resources and views for a sitemap:

https://github.com/websauna/websauna/blob/master/websauna/system/core/sitemap.py#L316

It's easy to get views for a given resource context object. You can probably query all views for any context object directly from the underlying Zope component registry.
 

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "pylons-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pylons-discuss/PokpluvF688/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pylons-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to pylons-discuss@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Theron Luhn

unread,
Apr 11, 2017, 8:27:25 PM4/11/17
to pylons-...@googlegroups.com
For sure.  I started digging around config.introspector and found that config.introspector.get_category('views’) gives me a list of dictionaries describing all the views, including the callable and the context like I wanted.

I was also able to hack together something to construct URLs from that:  https://gist.github.com/luhn/f56873c758ae07e59d7b50db197d1751

— Theron



To unsubscribe from this group and all its topics, send an email to pylons-discus...@googlegroups.com.

To post to this group, send email to pylons-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages