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
accessing config variable in views
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
 
Anil  
View profile  
 More options Sep 2 2012, 10:05 am
From: Anil <an...@me.com>
Date: Sun, 2 Sep 2012 07:05:22 -0700 (PDT)
Local: Sun, Sep 2 2012 10:05 am
Subject: accessing config variable in views

In my

def main(global_config, **settings)

I have the config = Configuration(...) variable.

How would I access this config variable from my views? Some people have
suggested using request.registry.settings, but I don't see it in that
dictionary in my 1.3.3 version.

Background:

I am using pyramid_ldap, and there is a config.ldap_set_login_query() that
I would like to dynamically set (the ldap search base) depending on the
type of request:

http://docs.pylonsproject.org/projects/pyramid_ldap/en/latest/

Also, if I wanted to do something before each and every request, what is
the best way? What about just after the request is sent handled? Pylons
used to have a __before__ and __after__, I don't think those are working
here.

Thanks


 
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.
Jonathan Vanasco  
View profile  
 More options Sep 2 2012, 1:31 pm
From: Jonathan Vanasco <jonat...@findmeon.com>
Date: Sun, 2 Sep 2012 10:31:47 -0700 (PDT)
Local: Sun, Sep 2 2012 1:31 pm
Subject: Re: accessing config variable in views

> How would I access this config variable from my views? Some people have
> suggested using request.registry.settings, but I don't see it in that
> dictionary in my 1.3.3 version.

request.registry.settings is the place to find app configuration
settings.

I just looked at the pyramid ldap docs, and the 'config' variable
there is a Configurator() instance.  I could be wrong, but I don't
think that is the pyramid config registry.  it might save things into
it, but I believe it is another instance.

the pyramid ldap docs also note a few things:

- there's a pretty decent API, and the only thing you should really
need to access in your views is 'get_ldap_connector()'.

- you could probably explore the object returned by
get_ldap_connector() to find the variables you want, but the package
seems to be designed for a single setup :  'All three of these methods
should be called once (and, ideally, only once) during the startup
phase of your Pyramid application'

> Also, if I wanted to do something before each and every request, what is
> the best way? What about just after the request is sent handled? Pylons
> used to have a __before__ and __after__, I don't think those are working
> here.

in most cases, you want to create an event subscriber :

    http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/api/even...

another alternative is to use a class-based approach to writing
views.  this is the most pylons-esque approach, where you can use a
single base class that has an init function.

    http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/vie...

your code could look like this:

class _BaseView(object):
    def __init__(self,request):
        self.request = request
        # do your shared stuff here

class LoginView(_BaseView):
    def login_print(self):
        pass
    def login_submit(self):
        pass

class AccountView(_BaseView):
    def account_home(self):
        pass
    def account_password_change(self):
        pass


 
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 »