[web2py] Re: How to temporarily redirect all requests

2011-07-13 Thread Luis Goncalves
Hello Anthony, and others!

I implemented your very first suggestion, code in a model, outside of a 
function, as you (and pbreit) suggested. It worked fine! It's been very 
hectic (meetings/travel) and I haven't had a chance to reply until now.  
Thanks for your help (everybody!) !!!  Luis.


[web2py] Re: How to temporarily redirect all requests

2011-07-10 Thread Anthony
Are you saying you want to do this someplace other than in a model file? The 
model file will be the first place where you'll be able to introduce any 
application logic (prior to that it's just framework code getting executed).

On Sunday, July 10, 2011 3:48:47 PM UTC-4, Luis Goncalves wrote:

> more thoughts:
>
> could I do something like:
>
>- define a shared global variable  session.version 
> - = -1 initially, signifying no choice made
>- ? use a callback that gets executed *before *the controller that 
>responds to the request 
>   - if session.version >-1:
>let the responding controller do its thing
>   else:
>if controller allowed to run:
> let the controller run
>else:
> redirect to 'please choose version'
>   
> Is it possible to implement such a "callback"???
>
> (or is this not the right/best way to achieve the functionality I need?)
>
> thanks,
> Luis.
>


[web2py] Re: How to temporarily redirect all requests

2011-07-10 Thread pbreit
Also note that you can put anthony's code in a controller outside a function 
and it will run every time tha controller is called.


[web2py] Re: How to temporarily redirect all requests

2011-07-10 Thread Luis Goncalves
Awesome!!! Thanks!!! I will try it out!!!
Luis.


Re: [web2py] Re: How to temporarily redirect all requests

2011-07-10 Thread Jonathan Lundell
On Jul 10, 2011, at 12:48 PM, Luis Goncalves wrote:
> more thoughts:
> 
> could I do something like:
> define a shared global variable  session.version 
> = -1 initially, signifying no choice made
> ? use a callback that gets executed before the controller that responds to 
> the request
> if session.version >-1:
>  let the responding controller do its thing
> else:
>  if controller allowed to run:
>   let the controller run
>  else:
>   redirect to 'please choose version'
> Is it possible to implement such a "callback"???
> 
> (or is this not the right/best way to achieve the functionality I need?)

Anthony's idea of doing it in a model sounds good.

Or you could write a decorator, along the lines of @auth.requires_login(), that 
performed the tests you need.



[web2py] Re: How to temporarily redirect all requests

2011-07-10 Thread Luis Goncalves
more thoughts:

could I do something like:

   - define a shared global variable  session.version 
   - = -1 initially, signifying no choice made
   - ? use a callback that gets executed *before *the controller that 
   responds to the request
  - if session.version >-1:
   let the responding controller do its thing
  else:
   if controller allowed to run:
let the controller run
   else:
redirect to 'please choose version'
  
Is it possible to implement such a "callback"???

(or is this not the right/best way to achieve the functionality I need?)

thanks,
Luis.


[web2py] Re: How to temporarily redirect all requests

2011-07-10 Thread Anthony
You could do the check in a model file -- all (non-conditional) model files 
are executed on every request (before the requested controller action). 
E.g.:
 
if not (session.version_selected or 
request.function=='version_selection_page'):
redirect(URL('default','version_selection_page')
 
 
Anthony

On Sunday, July 10, 2011 3:22:44 PM UTC-4, Luis Goncalves wrote:

> Hello Everyone!
>
> Is there a simple/efficient/secure way to temporarily redirect all requests 
> to a specific page?
> (all requests except for those that define a few actions that are permitted 
> at that point in time)
>
> The context:
>
>- When user logs in, he needs to choose the version of the website to 
>use (different version access different sets of data) 
>- Until he chooses a version, clicking on any of the menu options, or 
>links, or typing in any URL should not execute normally, but rather send 
> him 
>(keep him on) a page that tells him to "please select a version" 
>- Ideally, selecting the version is done from the 'version' menubar 
>option, so these still have to work properly.
>
> An ugly way to do this is to have every single possible action 
> (URL,controller) check if the version selection has been done or not,  but 
> that seems like an inelegant, brute-force approach (and prone to errors if 
> new functionality is added whilst forgetting to include the check).
>
> Thanks!!!
>
> Luis.
>