[web2py] Re: create an update page (similar to profile page in default application)

2014-07-03 Thread Shubham Jain
Ok, I got it. Yes,there is only one record for one pro_id.
The 2nd one works, but now a new problem arises. I am getting the record 
that I want to edit, but on submitting it, a new blank form is 
generated(which is undesired). When I submit this form with dummy values, 
this form is getting inserted into the db but the changes/update I made on 
the record are not replicated to the db.


On Wednesday, July 2, 2014 7:31:29 PM UTC+5:30, Massimo Di Pierro wrote:

 The problem is that here:

 testform = 
 SQLFORM(db.products,db(db.products.product_id==request.post_vars.pid).select(),
  fields=['product_id','price','pro_type','tags','category','description']))

 the result of a select is a Rows and not a Row. Do you know there is a 
 single matching record? In this case:

 testform = 
 SQLFORM(db.products,db(db.products.product_id==request.post_vars.pid).select().first(),
  fields=['product_id','price','pro_type','tags','category','description']))

 or

 testform = SQLFORM(db.products, 
 db.products(product_id=request.post_vars.pid), 
 fields=['product_id','price','pro_type','tags','category','description']))

 Mind that the pid of the product you want to edit should not be a POST 
 parameter but a GET parameter. According to REST it is used to identify the 
 resource you want to edit therefore it belongs to the URL not to the posted 
 data.

 Massimo



 On Wednesday, 2 July 2014 06:05:31 UTC-5, Shubham Jain wrote:

 I want to create an update page just like profile page in default 
 application. Actually I am passing the primary key of a table by a button 
 click to the product_update page. In the controller of the update page I 
 tried these 2 codes.

 def product_edit():
 db.products.product_id.writable=FALSE   # to make product_id 
 non editable
 db.products.product_id.readable=TRUE
 testform = 
 SQLFORM(db.products,db(db.products.product_id==request.post_vars.pid).select(),
  fields=['product_id','price','pro_type','tags','category','description']))
 return dict(form=testform)

   
  
 --OR-

 dform = 
 SQLFORM(db.products,record=db(db.products.product_id==request.post_vars.pid).select(),
  
 fields=['product_id','price','pro_type','tags','category','description'])
 return dict(form=dform)

   pid - name of the input which has the product_id.
 But these don't work.

 Error Generated: TypeError: list indices must be integers, not str



-- 
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: create an update page (similar to profile page in default application)

2014-07-03 Thread Shubham Jain
And I didn't understand why should I pass the 'pro_id' by GET and not by 
POST. This is the view from where I am passing the parameter (using POST)

{{for row in rows:}}
tr
  td{{=x}}{{x=x+1}}/td
td{{=row.product_id}}/td
!-- EDIT --
tdform action={{=URL('pro_edit')}} method=post
input name=pid value={{=row.product_id}} type=hidden
input type=submit value=Edit
/form/td
   tr {{pass}}

 Please tell me if I am wrong somewhere.

Mind that the pid of the product you want to edit should not be a POST 
 parameter but a GET parameter. According to REST it is used to identify the 
 resource you want to edit therefore it belongs to the URL not to the posted 
 data.

 Massimo



 On Wednesday, 2 July 2014 06:05:31 UTC-5, Shubham Jain wrote:

 I want to create an update page just like profile page in default 
 application. Actually I am passing the primary key of a table by a button 
 click to the product_update page. In the controller of the update page I 
 tried these 2 codes.

 def product_edit():
 db.products.product_id.writable=FALSE   # to make product_id 
 non editable
 db.products.product_id.readable=TRUE
 testform = 
 SQLFORM(db.products,db(db.products.product_id==request.post_vars.pid).select(),
  fields=['product_id','price','pro_type','tags','category','description']))
 return dict(form=testform)

   
  
 --OR-

 dform = 
 SQLFORM(db.products,record=db(db.products.product_id==request.post_vars.pid).select(),
  
 fields=['product_id','price','pro_type','tags','category','description'])
 return dict(form=dform)

   pid - name of the input which has the product_id.
 But these don't work.

 Error Generated: TypeError: list indices must be integers, not str



-- 
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: create an update page (similar to profile page in default application)

2014-07-03 Thread Massimo Di Pierro
I am not sure about what you are doing. Why do you have one form per row 
that does not submit any data other than a hidden field with id? What is 
the purpose of that submission?






On Thursday, 3 July 2014 05:03:19 UTC-5, Shubham Jain wrote:

 And I didn't understand why should I pass the 'pro_id' by GET and not by 
 POST. This is the view from where I am passing the parameter (using POST)

 {{for row in rows:}}
 tr
   td{{=x}}{{x=x+1}}/td
 td{{=row.product_id}}/td
 !-- EDIT --
 tdform action={{=URL('pro_edit')}} method=post
 input name=pid value={{=row.product_id}} type=hidden
 input type=submit value=Edit
 /form/td
tr {{pass}}

  Please tell me if I am wrong somewhere.

 Mind that the pid of the product you want to edit should not be a POST 
 parameter but a GET parameter. According to REST it is used to identify the 
 resource you want to edit therefore it belongs to the URL not to the posted 
 data.

 Massimo



 On Wednesday, 2 July 2014 06:05:31 UTC-5, Shubham Jain wrote:

 I want to create an update page just like profile page in default 
 application. Actually I am passing the primary key of a table by a button 
 click to the product_update page. In the controller of the update page I 
 tried these 2 codes.

 def product_edit():
 db.products.product_id.writable=FALSE   # to make product_id 
 non editable
 db.products.product_id.readable=TRUE
 testform = 
 SQLFORM(db.products,db(db.products.product_id==request.post_vars.pid).select(),
  fields=['product_id','price','pro_type','tags','category','description']))
 return dict(form=testform)

   
  
 --OR-

 dform = 
 SQLFORM(db.products,record=db(db.products.product_id==request.post_vars.pid).select(),
  
 fields=['product_id','price','pro_type','tags','category','description'])
 return dict(form=dform)

   pid - name of the input which has the product_id.
 But these don't work.

 Error Generated: TypeError: list indices must be integers, not str



-- 
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: create an update page (similar to profile page in default application)

2014-07-02 Thread Massimo Di Pierro
The problem is that here:

testform = 
SQLFORM(db.products,db(db.products.product_id==request.post_vars.pid).select(), 
fields=['product_id','price','pro_type','tags','category','description']))

the result of a select is a Rows and not a Row. Do you know there is a 
single matching record? In this case:

testform = 
SQLFORM(db.products,db(db.products.product_id==request.post_vars.pid).select().first(),
 fields=['product_id','price','pro_type','tags','category','description']))

or

testform = SQLFORM(db.products, 
db.products(product_id=request.post_vars.pid), 
fields=['product_id','price','pro_type','tags','category','description']))

Mind that the pid of the product you want to edit should not be a POST 
parameter but a GET parameter. According to REST it is used to identify the 
resource you want to edit therefore it belongs to the URL not to the posted 
data.

Massimo



On Wednesday, 2 July 2014 06:05:31 UTC-5, Shubham Jain wrote:

 I want to create an update page just like profile page in default 
 application. Actually I am passing the primary key of a table by a button 
 click to the product_update page. In the controller of the update page I 
 tried these 2 codes.

 def product_edit():
 db.products.product_id.writable=FALSE   # to make product_id 
 non editable
 db.products.product_id.readable=TRUE
 testform = 
 SQLFORM(db.products,db(db.products.product_id==request.post_vars.pid).select(),
  fields=['product_id','price','pro_type','tags','category','description']))
 return dict(form=testform)

   
  
 --OR-

 dform = 
 SQLFORM(db.products,record=db(db.products.product_id==request.post_vars.pid).select(),
  
 fields=['product_id','price','pro_type','tags','category','description'])
 return dict(form=dform)

   pid - name of the input which has the product_id.
 But these don't work.

 Error Generated: TypeError: list indices must be integers, not str



-- 
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.