Re: [web2py] Reponse.flash clobbers session.flash

2011-07-09 Thread Jonathan Lundell
On Jul 9, 2011, at 2:01 PM, Jim Karsten wrote:
> Ah, I see. Ok, i'll give that some thought.

Also, ask: what are you really trying to do? In particular, in the case where 
you've got incoming session.flash text, and you're also setting your own new 
text into response.flash, what do you want to happen on the screen?



Re: [web2py] Reponse.flash clobbers session.flash

2011-07-09 Thread Jim Karsten
Ah, I see. Ok, i'll give that some thought.


Re: [web2py] Reponse.flash clobbers session.flash

2011-07-09 Thread Jonathan Lundell
On Jul 9, 2011, at 1:50 PM, Jim Karsten wrote:
> "You could check whether there's something in response.flash and not clobber 
> it, if you liked." Do this in a models file, for example?

No, it's done before the models. When the request comes in, the core logic does:

response.flash = session.flash  # normally None
session.flash = None

Something like this:

def controller1():
form = SQLFORM.factory(Field('myfield'))
if form.accepts(request.vars,session):  
response.flash = 'Record updated'   
elif form.errors:   
response.flash = 'Form contains errors' 
elif not response flash:
   
response.flash = 'Please fill in the form'  
return dict(form=form)  

def controller2():  
session.flash = 'Message from session flash.'   
redirect(URL('controller1'))

Re: [web2py] Reponse.flash clobbers session.flash

2011-07-09 Thread Jim Karsten
"You could check whether there's something in response.flash and not clobber 
it, if you liked." Do this in a models file, for example? 

Re: [web2py] Reponse.flash clobbers session.flash

2011-07-09 Thread Jonathan Lundell
On Jul 9, 2011, at 11:52 AM, Jim Karsten wrote:
> Yeah, I'm aware of that. However, what if I want that message when 
> controller1 is called on its own, not as a redirect from controller2. In the 
> example I provided the message isn't very useful, but in some case the
> message can be.

When would it be useful? If you need user instructions, why not just put them 
somewhere on the page, and not commandeer flash for the purpose?

(Before the controller is called, session.flash is copied to response.flash and 
session.flash is set to None. You could check whether there's something in 
response.flash and not clobber it, if you liked.)

Re: [web2py] Reponse.flash clobbers session.flash

2011-07-09 Thread Jim Karsten
Yeah, I'm aware of that. However, what if I want that message when 
controller1 is called on its own, not as a redirect from controller2. In the 
example I provided the message isn't very useful, but in some case the
message can be.


Re: [web2py] Reponse.flash clobbers session.flash

2011-07-09 Thread Jonathan Lundell
On Jul 9, 2011, at 10:46 AM, Jim Karsten wrote:
> When controller2 is called it redirects to controller1. The session.flash 
> message is lost. Any suggestions for how to prevent the response.flash from 
> clobbering the session.flash?
> 
> def controller1():
> form = SQLFORM.factory(Field('myfield'))  
>   
> if form.accepts(request.vars,session):
>   
> response.flash = 'Record updated' 
>   
> elif form.errors: 
>   
> response.flash = 'Form contains errors'   
>   
> else: 
>   
> response.flash = 'Please fill in the form'
>   
> return dict(form=form)
>   
>   
>   
> def controller2():
>   
> session.flash = 'Message from session flash.' 
>   
> redirect(URL('controller1'))

Try removing the else: clause in controller1. 

[web2py] Reponse.flash clobbers session.flash

2011-07-09 Thread Jim Karsten
When controller2 is called it redirects to controller1. The session.flash 
message is lost. Any suggestions for how to prevent the response.flash from 
clobbering the session.flash?

def controller1():
form = 
SQLFORM.factory(Field('myfield'))
if 
form.accepts(request.vars,session):  
response.flash = 'Record 
updated'   
elif 
form.errors:   
response.flash = 'Form contains 
errors' 

else:   
response.flash = 'Please fill in the 
form'  
return 
dict(form=form)  


def 
controller2():  
session.flash = 'Message from session 
flash.'   
redirect(URL('controller1'))