Pylons / pyramid_layout

Pyramid add-on for managing UI layouts.
Other
24 stars 26 forks source link

Update layout.py #16

Closed mrijken closed 11 years ago

mrijken commented 11 years ago

Make it possible to add a context parameter to the panel directive, which makes that the panel will use another context. Ie Panel('format', context=context.date) which will lookup the format panel for dates.

chrisrossi commented 11 years ago

Hi @mrijken, thanks for the pull request! Looking at your modification, though, I think for your use case you just need to choose a different name for the parameter you want to pass. The 'context' should always be the Pyramid context object found during routing and traversal. If you want a different object available to your panels, just pass it in under a different name.

mrijken commented 11 years ago

Hi Chris,

I know that it is possible to give extra parameters to the panel, but that extra parameters won't be used in the lookup. The context and the name are used for selecting the right panel. When I have a couple of panels which formats different objects, ie I will get the following panels:

I know I can make a generic 'format' template which will handle these cases, but that is less maintainable because I will need to change the central 'format' panel when I want it to handle one extra class. I just want to add an extra panel in a different package.

When I can set the context in the panel to another context than the view where the panel is used, I can call the panel on the following way:

The lookup in render_panel will get the right panel based on the name and the context. In the case of 'person' it will ie render the manager panel when the person is an instance of the manager class.

I hope that it is clear that in my eyes this small change can make panels more convenient in use.

Marc

On Wed, Jul 24, 2013 at 3:51 PM, Chris Rossi notifications@github.comwrote:

Hi @mrijken https://github.com/mrijken, thanks for the pull request! Looking at your modification, though, I think for your use case you just need to choose a different name for the parameter you want to pass. The 'context' should always be the Pyramid context object found during routing and traversal. If you want a different object available to your panels, just pass it in under a different name.

— Reply to this email directly or view it on GitHubhttps://github.com/Pylons/pyramid_layout/pull/16#issuecomment-21485886 .

chrisrossi commented 11 years ago

Hi Marc,

Thanks for the feedback. I think I understand the use case a lot better now. I do think this is a good idea, now that I understand the rationale. In its current form, I can't accept this pull request because there are no new tests and documentation isn't updated. Also, after looking at this way of using the panels, it occurs to me that we ought to also allow unnamed panels. So, yes, I like this patch, but it's not quite finished yet. I'm willing to put the work in my queue, or let you have a crack at it. It'll probably be a week or more before I can get to it.

Thanks again! Chris

mrijken commented 11 years ago

I have added tests, documentation and changed the code a bit to let the tests pass.