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
view-callable class - request arg receives context object
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
 
Simon Yarde  
View profile  
 More options Oct 31 2012, 12:02 pm
From: Simon Yarde <simonya...@me.com>
Date: Wed, 31 Oct 2012 16:02:19 +0000
Local: Wed, Oct 31 2012 12:02 pm
Subject: view-callable class - request arg receives context object

Docs say you should expect to handle a request argument in a view-callable class.

http://pyramid.readthedocs.org/en/latest/narr/views.html#defining-a-v...

But I found I was getting a context object for the request arg.

Does this mean context and request are being passed (in that order) as positional args, rather can keywords?

I know I can just reverse the order so context is first - just asking if there is anything wrong with below code that would cause this, or this is view-callables are called this way for any reason?

class SomeView():
    """
    """
    def __init__(self,
                 request, # called positionally?
                 context, # ..
                 *args,
                 **kwargs
                 ):
        print('"request" is {0}'.format(request.__class__))
        print('"context" is {0}'.format(context.__class__))

"request" is <class 'pyramid.traversal.DefaultRootFactory'>
"context" is <class 'pyramid.util.Request'>


 
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.
Michael Merickel  
View profile  
 More options Oct 31 2012, 12:07 pm
From: Michael Merickel <mmeri...@gmail.com>
Date: Wed, 31 Oct 2012 11:06:54 -0500
Local: Wed, Oct 31 2012 12:06 pm
Subject: Re: view-callable class - request arg receives context object
They are called positionally via introspection and not by name. The
calling convention is here:

http://pyramid.readthedocs.org/en/latest/narr/views.html#alternate-vi...


 
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.
Simon  
View profile  
 More options Oct 31 2012, 1:07 pm
From: Simon <simonya...@me.com>
Date: Wed, 31 Oct 2012 10:07:24 -0700 (PDT)
Local: Wed, Oct 31 2012 1:07 pm
Subject: Re: view-callable class - request arg receives context object

Thanks Michael

Is the example below given
in #defining-a-view-callable-as-a-class incorrect?

I.e. ``request`` is a context-object because it is the first-position arg.

from pyramid.response import Response

class MyView(object):
    def __init__(self, request):
        self.request = request

    def __call__(self):
        return Response('hello')


 
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.
Michael Merickel  
View profile  
 More options Oct 31 2012, 1:12 pm
From: Michael Merickel <mmeri...@gmail.com>
Date: Wed, 31 Oct 2012 12:12:09 -0500
Local: Wed, Oct 31 2012 1:12 pm
Subject: Re: view-callable class - request arg receives context object
No, it's correct. As I said it uses introspection to see what args are
there. If your function takes 1 arg, it will be the request. If it
takes 2 or more args the first two will be context and request in that
order. You need to be aware of this if you try to do (request, *args)
because the first arg will be context and args[0] will be request.


 
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.
Simon Yarde  
View profile  
 More options Oct 31 2012, 1:39 pm
From: Simon Yarde <simonya...@me.com>
Date: Wed, 31 Oct 2012 17:26:34 +0000
Local: Wed, Oct 31 2012 1:26 pm
Subject: Re: view-callable class - request arg receives context object
Understood - thanks for clarifying. Best, S

On 31 Oct 2012, at 17:12, Michael Merickel wrote:


 
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 »