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
Default, or fallback, view in traversal?
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
  2 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
 
Isaac Jurado  
View profile  
 More options Jul 17 2012, 9:53 am
From: Isaac Jurado <ijur...@econcept.es>
Date: Tue, 17 Jul 2012 06:53:49 -0700 (PDT)
Local: Tues, Jul 17 2012 9:53 am
Subject: Default, or fallback, view in traversal?
Hello,

I would like to know if there is a way to add a fallback view name
when
a context is found but none of the defined view names match.  For
example, from the following example application:

    # coding: utf8
    from pyramid.config import Configurator

    class Foo(dict):
        pass

    def make_root(request):
        return {'foo': Foo()}

    def foo(request):
        return request.subpath

    def bar(request):
        return {"whoami": "bar", "subpath": request.subpath}

    def start(global_config, **settings):
        config = Configurator(settings=settings)
        config.set_root_factory(make_root)
        config.add_view(foo, context=Foo, renderer="json")
        config.add_view(bar, name="bar", context=Foo, renderer="json")
        return config.make_wsgi_app()

Traversal finds /foo and /foo/bar fine.  However, would it be possible
to configure a view (with context=Foo) to be used when the view_name
is
not found?

Thanks in advance.


 
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.
Isaac Jurado  
View profile  
 More options Jul 18 2012, 8:23 am
From: Isaac Jurado <ijur...@econcept.es>
Date: Wed, 18 Jul 2012 14:23:59 +0200
Local: Wed, Jul 18 2012 8:23 am
Subject: Re: Default, or fallback, view in traversal?

On Tue, Jul 17, 2012 at 8:53 PM, askel <dummy...@mail.ru> wrote:
> Hi Isaac,

> I'm not a Pyramid expert but I'd play with mapper parameter of
> add_view or view_config for that.

Thanks, but I found what I was looking for:

    from pyramid.view import notfound_view_config

    @notfound_view_config(containment=Foo, renderer='json')
    def fallback(request):
        return {'fallback': True, 'view': request.view_name}

Considering that the traversal tree is location aware (with the
__parent__ and __name__ thing), it works as a charm.

Cheers.

--
Isaac Jurado
Internet Busines Solutions eConcept

"Everyone knows that debugging is twice as hard as writing a program in
the first place. So if you're as clever as you can be when you write it,
how will you ever debug it?"

Brian W. Kernighan


 
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 »