[web2py] Re: Document Expired/ Need to reload page on using browser back button

2014-08-31 Thread Anthony
The problem is that you are making a POST request to return the grid, which 
is fundamentally a GET action. When you use the browser back button to try 
to return to a page that was requested via POST, the browser will typically 
display a message indicating the page has expired (because responses to 
POST requests are not cacheable) and make you jump through some hoops to 
re-submit the request (this is because POST requests generally result in 
changes to resources, so it is assumed you do not want to re-submit and 
repeatedly make the same change simply by hitting the back button).

In this case, a better approach would be to make a GET request by changing 
the form method to get. However, that will put var1 and testval into 
the query string of the /default/results URL, which you may not want. As an 
alternative, you can submit the form back to the index function and then 
have the index function redirect to the results function after saving 
var1 to the session:

In index.html, change the form method to get:

form enctype=multipart/form-data method=get action='#' 

In the controller:

def index():
if request.vars:
if request.vars.testval and session.var1:
del session.var1
if request.vars.var1 and not session.var1:
   session.var1 = request.vars.var1
redirect(URL('default', 'results'))
return dict(message='Hello World')

def results():
grid = {}
if session.var1:
query = (db.Category.Name==session.var1)
grid = SQLFORM.grid(query=query)
return dict(grid=grid)

Anthony

On Saturday, August 30, 2014 1:14:25 AM UTC-4, Sarbjit wrote:

 Hi Anthony,

 I am able to reproduce this problem in a small app (tested on windows - 
 2.9.5).

 *MODEL:*

 db.define_table('Category',
 Field('Name'),
 Field('SubCategoryName'))
  
 # Insert test data 
  
 if db(db.Category.id0).count() == 0:
 db.Category.insert(Name='PC',SubCategoryName='Intel')
 db.Category.insert(Name='PC',SubCategoryName='AMD')
 db.Category.insert(Name='SmartPhone',SubCategoryName='Apple')
 db.Category.insert(Name='SmartPhone',SubCategoryName='HTC')
 db.Category.insert(Name='SmartPhone',SubCategoryName='Google')

 *CONTROLLER:*

 def index():
 response.flash = T(Welcome to web2py!)
 return dict(message=T('Hello World'))

 def results():
 if (request.vars.testval and session.var1):
 try:
 del session.var1
 except Exception : pass
 if (request.vars.var1) and (not session.var1):
session.var1 = request.vars.var1
 grid = {}
 if session.var1:
 query = (db.Category.Name==session.var1)
 grid = SQLFORM.grid(query=query)
 return dict(grid=grid)

 *VIEWS:*

 *results.html*

 {{extend 'layout.html'}}
 {{=grid}}

 *index.html*

 {{extend 'layout.html'}}
 form enctype=multipart/form-data method=post 
 action={{=URL('default','results')}} 
 select name=var1
 option value=PCPC/option
 option value=SmartPhoneSmart Phone/option
 /select
 input type=submit value='Submit'
 input type=hidden name=testval value=test /
 /form

 *Steps to reproduce the problem :-*

 1. Select any value from the drop down and hit submit button.
 2. Select any GRID row and click on View
 3. Use Browser Back button - Document will expire, you have to refresh to 
 get the results back (Tried on Chrome/Firefox)
 4. Repeat Step2
 5. Now instead of using Browser back button, use GRID embedded back button.
 6. Now repeating step 2-3 won't cause any problem (document won't expire) 
 until the new selection is made from the selection drop down.

 Please suggest something to resolve this problem. 

 Thanks
 Sarbjit


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Document Expired/ Need to reload page on using browser back button

2014-08-31 Thread Sarbjit
Thanks a lot Anthony for the solution.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Document Expired/ Need to reload page on using browser back button

2014-08-29 Thread Anthony
Can you show your code?

On Friday, August 29, 2014 12:54:48 AM UTC-4, Sarbjit wrote:

 I have an application having the layout as :-

 INDEX controller generates a view which have some drop-down and calls 
 another controller RESULTS :

 Snippet :
 form enctype=multipart/form-data method=post 
 action={{=URL('default','results')}} 

 Now the RESULTS controller creates a grid and populates the view 
 corresponding to RESULT controller.

 PROBLEM :-

 When I view/edit any entry of GRID, then on using the browser back button, 
 I get the following message :-

 Document Expired (Firefox)
 Need to conform form resubmissions (ERR_CACHE_MISS) -- Chrome

 In the RESULTS controller, I just query request.vars for variables and 
 store them in session and later on clear the session once the GRID is 
 populated.

 I don't see this problem if I use the BACK button provided by the GRID 
 itself (URL contained a signature - Is it causing it to work?)

 Can any one please suggest on how to address this problem. This is very 
 annoying problem.

 Thanks in advance
 Sarbjit



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Document Expired/ Need to reload page on using browser back button

2014-08-29 Thread Sarbjit
Hi Anthony,

Thanks for response.

It would be difficult for me to share the exact code (my company specific 
data and lot of extra code etc)

However, I am providing code snippets of the main portions that I feel are 
causing this problem  and work flow (i have changed the variable names):-

Please let me know, if you still require the exact code, then I'll try to 
reproduce it in a small app that can be shared as such.

*INDEX :*

index function from controllers returns options to be populated in select 
html column. It uses ajax callbacks to dynamically populate the select 
field.

{{extend 'layout.html'}}
form enctype=multipart/form-data method=post 
action={{=URL('default','results')}} 
select name='var1'
...
select name='var2'
...
input type=submit value='Submit'
input type=hidden name=testval value=test /
/form

Once the options are selected the results function is called :-

def results(): 
if (request.vars.testval and session.var1 and session.var2) or 
(len(request.vars) == 0):
try:
del session.var1
del session.var2
except Exception : pass
if (request.vars.var1) and (not session.var1):
   session.var1 = request.vars.var1
if request.vars.var2 and not session.var2:
   session.var2 = request.vars.var2

Then the session data is checked and a grid is created. Results view just 
displays the grid data.

Now from the grid data, when I select any row and uses browser back button, 
I get this problem.

Thanks
Sarbjit


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Document Expired/ Need to reload page on using browser back button

2014-08-29 Thread Sarbjit
More Updates :

I tried debugging it using Eclipse and I observed that whenever the 
document expires, breakpoint is not hit. (results function).

Also I observed that once I use the Back button from within the grid field, 
it starts working from the browser also but only for current selection 
(from index controller).

If I change the selection from index and comes back to results - Then i 
face the same problem again - have to use back button from grid once, then 
browser button works fine for other grid entries.

Now any pointers on where to proceed?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Document Expired/ Need to reload page on using browser back button

2014-08-29 Thread Anthony
To make this easier to debug, it would be helpful if you could attach a 
minimal app that reproduces the behavior.

On Friday, August 29, 2014 11:32:20 AM UTC-4, Sarbjit wrote:

 More Updates :

 I tried debugging it using Eclipse and I observed that whenever the 
 document expires, breakpoint is not hit. (results function).

 Also I observed that once I use the Back button from within the grid 
 field, it starts working from the browser also but only for current 
 selection (from index controller).

 If I change the selection from index and comes back to results - Then i 
 face the same problem again - have to use back button from grid once, then 
 browser button works fine for other grid entries.

 Now any pointers on where to proceed?


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Document Expired/ Need to reload page on using browser back button

2014-08-29 Thread Sarbjit
Hi Anthony,

I am able to reproduce this problem in a small app (tested on windows - 
2.9.5).

*MODEL:*

db.define_table('Category',
Field('Name'),
Field('SubCategoryName'))
 
# Insert test data 
 
if db(db.Category.id0).count() == 0:
db.Category.insert(Name='PC',SubCategoryName='Intel')
db.Category.insert(Name='PC',SubCategoryName='AMD')
db.Category.insert(Name='SmartPhone',SubCategoryName='Apple')
db.Category.insert(Name='SmartPhone',SubCategoryName='HTC')
db.Category.insert(Name='SmartPhone',SubCategoryName='Google')

*CONTROLLER:*

def index():
response.flash = T(Welcome to web2py!)
return dict(message=T('Hello World'))

def results():
if (request.vars.testval and session.var1):
try:
del session.var1
except Exception : pass
if (request.vars.var1) and (not session.var1):
   session.var1 = request.vars.var1
grid = {}
if session.var1:
query = (db.Category.Name==session.var1)
grid = SQLFORM.grid(query=query)
return dict(grid=grid)

*VIEWS:*

*results.html*

{{extend 'layout.html'}}
{{=grid}}

*index.html*

{{extend 'layout.html'}}
form enctype=multipart/form-data method=post 
action={{=URL('default','results')}} 
select name=var1
option value=PCPC/option
option value=SmartPhoneSmart Phone/option
/select
input type=submit value='Submit'
input type=hidden name=testval value=test /
/form

*Steps to reproduce the problem :-*

1. Select any value from the drop down and hit submit button.
2. Select any GRID row and click on View
3. Use Browser Back button - Document will expire, you have to refresh to 
get the results back (Tried on Chrome/Firefox)
4. Repeat Step2
5. Now instead of using Browser back button, use GRID embedded back button.
6. Now repeating step 2-3 won't cause any problem (document won't expire) 
until the new selection is made from the selection drop down.

Please suggest something to resolve this problem. 

Thanks
Sarbjit

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.