On Wed, Dec 26, 2018 at 11:18 PM Gerhard Schmidt <[email protected]> wrote:
>
> Hi Mike,
>
> Am Mittwoch, 26. Dezember 2018 19:04:37 UTC+1 schrieb Mike Orr:
>>
>> On Wed, Dec 26, 2018 at 12:28 AM Gerhard Schmidt <[email protected]> wrote:
>> > is it possible to store additional information in the view config.
>> >
>> > Background is that i would like to add more information the the view
>> > processed later by the layout tho generate the navigation of a page
>> > automatically.
>> >
>> > I would like to store the title of a page (for the navigation link) and
>> > the navigation type.
>> >
>> > The simplest solution would be to copy any unknown keyword arguments
>> > given to view_config to the Introspectable or be able to add custom
>> > keywords to be copied via config statement like adding custom predicates
>> > to the view config.
>>
>> I don't know whether you can store additional args this way, but it
>> sounds like the wrong structure for this kind of information. A page
>> title is page specific, not view specific, and parent titles (for
>> navigation links or previous/next links) sound like resource
>> information. Is this a pure URL Dispatch application with no resource
>> tree that could hold this information? I generally put my page title
>> in a Mako template function or I set it during the view's action. If
>> you have class-based views, you could store the navigation tree in a
>> view class attribute, and then use the runtime view's name to figure
>> out the current position in the tree. You may not need a multilevel
>> tree to navigate just one level up and one level across, with a
>> well-known "Home" link above that.
>
>
> first, why didn't i get you mail via mailinglist?
>
> It's a traversal application. so views are bound to context rather than urls.
>
> Right now i have a action_config decorator that adds a view with the given
> information and store the additional information in a second Introspectable
> in the registry.
>
> Would be much more convenient to store this information directly at the view.
>
> The pagetitle in my application is quite view specific and the navigation I
> am implementing is not only the site navigation (the site navigation is quite
> trivial) but the navigation within the object which can be quite complex.
>
> Storing this information in the registry works quite well for me. And being
> able to do that directly in the view Introspectable would cut some complexity.
>
> But my use case must not be the only one. So I think the question is not if
> the view Introspectable is the right place to store a pagetitle. The question
> is, should there be a way to store more information in the View
> Introspectable and how difficult is this to be implemented.
>
> Regards
> Estartu
I had an idea about this. When you want to associate data with a
callable you can use a partial function. For instance:
# views.py
def my_view(title, request):
....
# __init__.py
import functools
title = "My Title"
view1 = functools.partial(my_view, title)
config.add_view(view1, ...)
Or you could write a wrapper for view_config that does this.
I've never needed additional view data like this because my titles are
in my templates or in my view code. (I have a Mako site template with
a 'page_title' function which I override in the individual templates.)
But if you can't specify the title in either of those places or in the
context, then I'd use a partial function like this.
Outside Pyramid I'd use a callable class:
class MyClass:
def __init__(self, title):
self.title = title
def __call__(self, request):
# Use self.title.
But that wouldn't work as a view class because Pyramid makes certain
assumptions about view classes that are incompatible with this. You
might be able to configure an instance of it:
config.add_view(MyClass("My Title"), ...)
But I haven't tried it and I don't know whether Pyramid would treat it
like a function.
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pylons-discuss/CAH9f%3Durv-EUPhwC%3DeLqtBUKq4MOcw6jBnV937fXHNZWceVXeyQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.