Re: [web2py] Re: Create a copy record button in SQLFORM?
Richard/Niphold, Thank you so much. It's almost done. Just getting attribute error now but I am going to try to fix that with exception handling. type 'exceptions.AttributeError' 'str' object has no attribute 'year' I have a modified_on field which is set to datetime. WHen I comment that out it transfers to the next page with no problem. Any thoughts on how I could fix? On Sunday, May 4, 2014 9:10:55 AM UTC-4, Richard wrote: Sorry for miss leading, Niphold is true... So, for f, v in request.vars.iteritmes(): db.table[f].default = v On Sat, May 3, 2014 at 8:47 AM, Niphlod nip...@gmail.com javascript:wrote: request.vars is like a dict. Surely you're hitting that issue :-P test = dict(a=1,b=2) for k,v in test: ...print k, v ... Traceback (most recent call last): File stdin, line 1, in module ValueError: need more than 1 value to unpack Add an iteritems() and you're good to go for k,v in test.iteritems(): ... print k,v ... a 1 b 2 On Friday, May 2, 2014 11:20:40 PM UTC+2, LoveWeb2py wrote: Web2py admin console has a red line at for f, v in request.vars: and then says too many values to unpack. my function is def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) Should I have extra values in the dict method? -- 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+un...@googlegroups.com javascript:. For more options, visit https://groups.google.com/d/optout. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
Also, When I click the submit button in {{=form}} it doesn't actually submit anything. It just doubles the values that are already in the fields and puts them into a list. I think I need to do something like db.insert with a new ID number for the submit button. On Monday, May 5, 2014 8:46:25 AM UTC-4, LoveWeb2py wrote: Richard/Niphold, Thank you so much. It's almost done. Just getting attribute error now but I am going to try to fix that with exception handling. type 'exceptions.AttributeError' 'str' object has no attribute 'year' I have a modified_on field which is set to datetime. WHen I comment that out it transfers to the next page with no problem. Any thoughts on how I could fix? On Sunday, May 4, 2014 9:10:55 AM UTC-4, Richard wrote: Sorry for miss leading, Niphold is true... So, for f, v in request.vars.iteritmes(): db.table[f].default = v On Sat, May 3, 2014 at 8:47 AM, Niphlod nip...@gmail.com wrote: request.vars is like a dict. Surely you're hitting that issue :-P test = dict(a=1,b=2) for k,v in test: ...print k, v ... Traceback (most recent call last): File stdin, line 1, in module ValueError: need more than 1 value to unpack Add an iteritems() and you're good to go for k,v in test.iteritems(): ... print k,v ... a 1 b 2 On Friday, May 2, 2014 11:20:40 PM UTC+2, LoveWeb2py wrote: Web2py admin console has a red line at for f, v in request.vars: and then says too many values to unpack. my function is def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) Should I have extra values in the dict method? -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
Please show code!! Richard On Mon, May 5, 2014 at 8:50 AM, LoveWeb2py atayloru...@gmail.com wrote: Also, When I click the submit button in {{=form}} it doesn't actually submit anything. It just doubles the values that are already in the fields and puts them into a list. I think I need to do something like db.insert with a new ID number for the submit button. On Monday, May 5, 2014 8:46:25 AM UTC-4, LoveWeb2py wrote: Richard/Niphold, Thank you so much. It's almost done. Just getting attribute error now but I am going to try to fix that with exception handling. type 'exceptions.AttributeError' 'str' object has no attribute 'year' I have a modified_on field which is set to datetime. WHen I comment that out it transfers to the next page with no problem. Any thoughts on how I could fix? On Sunday, May 4, 2014 9:10:55 AM UTC-4, Richard wrote: Sorry for miss leading, Niphold is true... So, for f, v in request.vars.iteritmes(): db.table[f].default = v On Sat, May 3, 2014 at 8:47 AM, Niphlod nip...@gmail.com wrote: request.vars is like a dict. Surely you're hitting that issue :-P test = dict(a=1,b=2) for k,v in test: ...print k, v ... Traceback (most recent call last): File stdin, line 1, in module ValueError: need more than 1 value to unpack Add an iteritems() and you're good to go for k,v in test.iteritems(): ... print k,v ... a 1 b 2 On Friday, May 2, 2014 11:20:40 PM UTC+2, LoveWeb2py wrote: Web2py admin console has a red line at for f, v in request.vars: and then says too many values to unpack. my function is def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) Should I have extra values in the dict method? -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
Hi Richard, Here is what I have so far: Controllers: def user_list(): grid=SQLFORM.smartgrid(db.users, paginate=20, links_placement='left', _href=URL('transition_form', vars=dict((f, row[f]) for f in db.users.fields], user_signature=True) return dict(grid=grid) def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) View: user_list.html {{=form}} This properly populates the values. but it isn't submitting properly. After the form submits I would like it to return to the database and show me the user that was just added. Also, I set my database to autoincrement the ID which should solve the id problem I was thinking I could set something in my transition_form function that if form.process().accepted: redirect(URL('user_list')), but I get an error saying table object has no attribute '_formkey' does this mean I need to do some type of form validation? On Monday, May 5, 2014 9:53:38 AM UTC-4, Richard wrote: Please show code!! Richard On Mon, May 5, 2014 at 8:50 AM, LoveWeb2py atayl...@gmail.comjavascript: wrote: Also, When I click the submit button in {{=form}} it doesn't actually submit anything. It just doubles the values that are already in the fields and puts them into a list. I think I need to do something like db.insert with a new ID number for the submit button. On Monday, May 5, 2014 8:46:25 AM UTC-4, LoveWeb2py wrote: Richard/Niphold, Thank you so much. It's almost done. Just getting attribute error now but I am going to try to fix that with exception handling. type 'exceptions.AttributeError' 'str' object has no attribute 'year' I have a modified_on field which is set to datetime. WHen I comment that out it transfers to the next page with no problem. Any thoughts on how I could fix? On Sunday, May 4, 2014 9:10:55 AM UTC-4, Richard wrote: Sorry for miss leading, Niphold is true... So, for f, v in request.vars.iteritmes(): db.table[f].default = v On Sat, May 3, 2014 at 8:47 AM, Niphlod nip...@gmail.com wrote: request.vars is like a dict. Surely you're hitting that issue :-P test = dict(a=1,b=2) for k,v in test: ...print k, v ... Traceback (most recent call last): File stdin, line 1, in module ValueError: need more than 1 value to unpack Add an iteritems() and you're good to go for k,v in test.iteritems(): ... print k,v ... a 1 b 2 On Friday, May 2, 2014 11:20:40 PM UTC+2, LoveWeb2py wrote: Web2py admin console has a red line at for f, v in request.vars: and then says too many values to unpack. my function is def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) Should I have extra values in the dict method? -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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+un...@googlegroups.com javascript:. For more options, visit https://groups.google.com/d/optout. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
Sorry forgot to add .iteritems(): this is the most updated version. On Monday, May 5, 2014 10:01:46 AM UTC-4, LoveWeb2py wrote: Hi Richard, Here is what I have so far: Controllers: def user_list(): grid=SQLFORM.smartgrid(db.users, paginate=20, links_placement='left', _href=URL('transition_form', vars=dict((f, row[f]) for f in db.users.fields], user_signature=True) return dict(grid=grid) def transition_form(): for f, v in request.vars.iteritems(): db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) View: user_list.html {{=form}} This properly populates the values. but it isn't submitting properly. After the form submits I would like it to return to the database and show me the user that was just added. Also, I set my database to autoincrement the ID which should solve the id problem I was thinking I could set something in my transition_form function that if form.process().accepted: redirect(URL('user_list')), but I get an error saying table object has no attribute '_formkey' does this mean I need to do some type of form validation? On Monday, May 5, 2014 9:53:38 AM UTC-4, Richard wrote: Please show code!! Richard On Mon, May 5, 2014 at 8:50 AM, LoveWeb2py atayl...@gmail.com wrote: Also, When I click the submit button in {{=form}} it doesn't actually submit anything. It just doubles the values that are already in the fields and puts them into a list. I think I need to do something like db.insert with a new ID number for the submit button. On Monday, May 5, 2014 8:46:25 AM UTC-4, LoveWeb2py wrote: Richard/Niphold, Thank you so much. It's almost done. Just getting attribute error now but I am going to try to fix that with exception handling. type 'exceptions.AttributeError' 'str' object has no attribute 'year' I have a modified_on field which is set to datetime. WHen I comment that out it transfers to the next page with no problem. Any thoughts on how I could fix? On Sunday, May 4, 2014 9:10:55 AM UTC-4, Richard wrote: Sorry for miss leading, Niphold is true... So, for f, v in request.vars.iteritmes(): db.table[f].default = v On Sat, May 3, 2014 at 8:47 AM, Niphlod nip...@gmail.com wrote: request.vars is like a dict. Surely you're hitting that issue :-P test = dict(a=1,b=2) for k,v in test: ...print k, v ... Traceback (most recent call last): File stdin, line 1, in module ValueError: need more than 1 value to unpack Add an iteritems() and you're good to go for k,v in test.iteritems(): ... print k,v ... a 1 b 2 On Friday, May 2, 2014 11:20:40 PM UTC+2, LoveWeb2py wrote: Web2py admin console has a red line at for f, v in request.vars: and then says too many values to unpack. my function is def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) Should I have extra values in the dict method? -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
That what I thought! How do you validate your form?? Please read the book a bit more about form submission... http://web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORM def display_form(): form = SQLFORM(db.person) if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'form has errors' else: response.flash = 'please fill out the form' return dict(form=form) You need to process the form, see if it validate... You shouldn't have to insert manually your data if you don't need facy thing and form.process().accepted should handle everything for you. Richard On Mon, May 5, 2014 at 10:03 AM, LoveWeb2py atayloru...@gmail.com wrote: Sorry forgot to add .iteritems(): this is the most updated version. On Monday, May 5, 2014 10:01:46 AM UTC-4, LoveWeb2py wrote: Hi Richard, Here is what I have so far: Controllers: def user_list(): grid=SQLFORM.smartgrid(db.users, paginate=20, links_placement='left', _href=URL('transition_form', vars=dict((f, row[f]) for f in db.users.fields], user_signature=True) return dict(grid=grid) def transition_form(): for f, v in request.vars.iteritems(): db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) View: user_list.html {{=form}} This properly populates the values. but it isn't submitting properly. After the form submits I would like it to return to the database and show me the user that was just added. Also, I set my database to autoincrement the ID which should solve the id problem I was thinking I could set something in my transition_form function that if form.process().accepted: redirect(URL('user_list')), but I get an error saying table object has no attribute '_formkey' does this mean I need to do some type of form validation? On Monday, May 5, 2014 9:53:38 AM UTC-4, Richard wrote: Please show code!! Richard On Mon, May 5, 2014 at 8:50 AM, LoveWeb2py atayl...@gmail.com wrote: Also, When I click the submit button in {{=form}} it doesn't actually submit anything. It just doubles the values that are already in the fields and puts them into a list. I think I need to do something like db.insert with a new ID number for the submit button. On Monday, May 5, 2014 8:46:25 AM UTC-4, LoveWeb2py wrote: Richard/Niphold, Thank you so much. It's almost done. Just getting attribute error now but I am going to try to fix that with exception handling. type 'exceptions.AttributeError' 'str' object has no attribute 'year' I have a modified_on field which is set to datetime. WHen I comment that out it transfers to the next page with no problem. Any thoughts on how I could fix? On Sunday, May 4, 2014 9:10:55 AM UTC-4, Richard wrote: Sorry for miss leading, Niphold is true... So, for f, v in request.vars.iteritmes(): db.table[f].default = v On Sat, May 3, 2014 at 8:47 AM, Niphlod nip...@gmail.com wrote: request.vars is like a dict. Surely you're hitting that issue :-P test = dict(a=1,b=2) for k,v in test: ...print k, v ... Traceback (most recent call last): File stdin, line 1, in module ValueError: need more than 1 value to unpack Add an iteritems() and you're good to go for k,v in test.iteritems(): ... print k,v ... a 1 b 2 On Friday, May 2, 2014 11:20:40 PM UTC+2, LoveWeb2py wrote: Web2py admin console has a red line at for f, v in request.vars: and then says too many values to unpack. my function is def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) Should I have extra values in the dict method? -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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
Re: [web2py] Re: Create a copy record button in SQLFORM?
I've read that, Richard. When using this I get that error: def transition_form(): for f, v in request.vars.iteritems(): db.users[f].default = v form = SQLFORM(db.users, user_signature=True) if form.process().accepted: response.flash = 'form accepted' return dict(form=form) Still get the same error : type 'exceptions.AttributeError' 'Table' object has no attribute '_formkey' On Monday, May 5, 2014 10:34:28 AM UTC-4, Richard wrote: That what I thought! How do you validate your form?? Please read the book a bit more about form submission... http://web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORM def display_form(): form = SQLFORM(db.person) if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'form has errors' else: response.flash = 'please fill out the form' return dict(form=form) You need to process the form, see if it validate... You shouldn't have to insert manually your data if you don't need facy thing and form.process().accepted should handle everything for you. Richard On Mon, May 5, 2014 at 10:03 AM, LoveWeb2py atayl...@gmail.comjavascript: wrote: Sorry forgot to add .iteritems(): this is the most updated version. On Monday, May 5, 2014 10:01:46 AM UTC-4, LoveWeb2py wrote: Hi Richard, Here is what I have so far: Controllers: def user_list(): grid=SQLFORM.smartgrid(db.users, paginate=20, links_placement='left', _href=URL('transition_form', vars=dict((f, row[f]) for f in db.users.fields], user_signature=True) return dict(grid=grid) def transition_form(): for f, v in request.vars.iteritems(): db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) View: user_list.html {{=form}} This properly populates the values. but it isn't submitting properly. After the form submits I would like it to return to the database and show me the user that was just added. Also, I set my database to autoincrement the ID which should solve the id problem I was thinking I could set something in my transition_form function that if form.process().accepted: redirect(URL('user_list')), but I get an error saying table object has no attribute '_formkey' does this mean I need to do some type of form validation? On Monday, May 5, 2014 9:53:38 AM UTC-4, Richard wrote: Please show code!! Richard On Mon, May 5, 2014 at 8:50 AM, LoveWeb2py atayl...@gmail.com wrote: Also, When I click the submit button in {{=form}} it doesn't actually submit anything. It just doubles the values that are already in the fields and puts them into a list. I think I need to do something like db.insert with a new ID number for the submit button. On Monday, May 5, 2014 8:46:25 AM UTC-4, LoveWeb2py wrote: Richard/Niphold, Thank you so much. It's almost done. Just getting attribute error now but I am going to try to fix that with exception handling. type 'exceptions.AttributeError' 'str' object has no attribute 'year' I have a modified_on field which is set to datetime. WHen I comment that out it transfers to the next page with no problem. Any thoughts on how I could fix? On Sunday, May 4, 2014 9:10:55 AM UTC-4, Richard wrote: Sorry for miss leading, Niphold is true... So, for f, v in request.vars.iteritmes(): db.table[f].default = v On Sat, May 3, 2014 at 8:47 AM, Niphlod nip...@gmail.com wrote: request.vars is like a dict. Surely you're hitting that issue :-P test = dict(a=1,b=2) for k,v in test: ...print k, v ... Traceback (most recent call last): File stdin, line 1, in module ValueError: need more than 1 value to unpack Add an iteritems() and you're good to go for k,v in test.iteritems(): ... print k,v ... a 1 b 2 On Friday, May 2, 2014 11:20:40 PM UTC+2, LoveWeb2py wrote: Web2py admin console has a red line at for f, v in request.vars: and then says too many values to unpack. my function is def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) Should I have extra values in the dict method? -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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
Re: [web2py] Re: Create a copy record button in SQLFORM?
You miss this part in what you show me : if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'form has errors' else: response.flash = 'please fill out the form' Avoid using user_signature at the begining, and you can add this more secure thing latter on. Richard On Mon, May 5, 2014 at 10:40 AM, LoveWeb2py atayloru...@gmail.com wrote: I've read that, Richard. When using this I get that error: def transition_form(): for f, v in request.vars.iteritems(): db.users[f].default = v form = SQLFORM(db.users, user_signature=True) if form.process().accepted: response.flash = 'form accepted' return dict(form=form) Still get the same error : type 'exceptions.AttributeError' 'Table' object has no attribute '_formkey' On Monday, May 5, 2014 10:34:28 AM UTC-4, Richard wrote: That what I thought! How do you validate your form?? Please read the book a bit more about form submission... http://web2py.com/books/default/chapter/29/07/forms- and-validators#SQLFORM def display_form(): form = SQLFORM(db.person) if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'form has errors' else: response.flash = 'please fill out the form' return dict(form=form) You need to process the form, see if it validate... You shouldn't have to insert manually your data if you don't need facy thing and form.process().accepted should handle everything for you. Richard On Mon, May 5, 2014 at 10:03 AM, LoveWeb2py atayl...@gmail.com wrote: Sorry forgot to add .iteritems(): this is the most updated version. On Monday, May 5, 2014 10:01:46 AM UTC-4, LoveWeb2py wrote: Hi Richard, Here is what I have so far: Controllers: def user_list(): grid=SQLFORM.smartgrid(db.users, paginate=20, links_placement='left', _href=URL('transition_form', vars=dict((f, row[f]) for f in db.users.fields], user_signature=True) return dict(grid=grid) def transition_form(): for f, v in request.vars.iteritems(): db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) View: user_list.html {{=form}} This properly populates the values. but it isn't submitting properly. After the form submits I would like it to return to the database and show me the user that was just added. Also, I set my database to autoincrement the ID which should solve the id problem I was thinking I could set something in my transition_form function that if form.process().accepted: redirect(URL('user_list')), but I get an error saying table object has no attribute '_formkey' does this mean I need to do some type of form validation? On Monday, May 5, 2014 9:53:38 AM UTC-4, Richard wrote: Please show code!! Richard On Mon, May 5, 2014 at 8:50 AM, LoveWeb2py atayl...@gmail.com wrote: Also, When I click the submit button in {{=form}} it doesn't actually submit anything. It just doubles the values that are already in the fields and puts them into a list. I think I need to do something like db.insert with a new ID number for the submit button. On Monday, May 5, 2014 8:46:25 AM UTC-4, LoveWeb2py wrote: Richard/Niphold, Thank you so much. It's almost done. Just getting attribute error now but I am going to try to fix that with exception handling. type 'exceptions.AttributeError' 'str' object has no attribute 'year' I have a modified_on field which is set to datetime. WHen I comment that out it transfers to the next page with no problem. Any thoughts on how I could fix? On Sunday, May 4, 2014 9:10:55 AM UTC-4, Richard wrote: Sorry for miss leading, Niphold is true... So, for f, v in request.vars.iteritmes(): db.table[f].default = v On Sat, May 3, 2014 at 8:47 AM, Niphlod nip...@gmail.com wrote: request.vars is like a dict. Surely you're hitting that issue :-P test = dict(a=1,b=2) for k,v in test: ...print k, v ... Traceback (most recent call last): File stdin, line 1, in module ValueError: need more than 1 value to unpack Add an iteritems() and you're good to go for k,v in test.iteritems(): ... print k,v ... a 1 b 2 On Friday, May 2, 2014 11:20:40 PM UTC+2, LoveWeb2py wrote: Web2py admin console has a red line at for f, v in request.vars: and then says too many values to unpack. my function is def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) Should I have extra values in the dict method? -- 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
Re: [web2py] Re: Create a copy record button in SQLFORM?
Still doesn't work. Says I'm missing _formkey. Also worth noting right when I get to the form it says 'please fill out the form' as in its processing the else already before it even accepts the data... On Monday, May 5, 2014 11:13:09 AM UTC-4, Richard wrote: You miss this part in what you show me : if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'form has errors' else: response.flash = 'please fill out the form' Avoid using user_signature at the begining, and you can add this more secure thing latter on. Richard On Mon, May 5, 2014 at 10:40 AM, LoveWeb2py atayl...@gmail.comjavascript: wrote: I've read that, Richard. When using this I get that error: def transition_form(): for f, v in request.vars.iteritems(): db.users[f].default = v form = SQLFORM(db.users, user_signature=True) if form.process().accepted: response.flash = 'form accepted' return dict(form=form) Still get the same error : type 'exceptions.AttributeError' 'Table' object has no attribute '_formkey' On Monday, May 5, 2014 10:34:28 AM UTC-4, Richard wrote: That what I thought! How do you validate your form?? Please read the book a bit more about form submission... http://web2py.com/books/default/chapter/29/07/forms- and-validators#SQLFORM def display_form(): form = SQLFORM(db.person) if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'form has errors' else: response.flash = 'please fill out the form' return dict(form=form) You need to process the form, see if it validate... You shouldn't have to insert manually your data if you don't need facy thing and form.process().accepted should handle everything for you. Richard On Mon, May 5, 2014 at 10:03 AM, LoveWeb2py atayl...@gmail.com wrote: Sorry forgot to add .iteritems(): this is the most updated version. On Monday, May 5, 2014 10:01:46 AM UTC-4, LoveWeb2py wrote: Hi Richard, Here is what I have so far: Controllers: def user_list(): grid=SQLFORM.smartgrid(db.users, paginate=20, links_placement='left', _href=URL('transition_form', vars=dict((f, row[f]) for f in db.users.fields], user_signature=True) return dict(grid=grid) def transition_form(): for f, v in request.vars.iteritems(): db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) View: user_list.html {{=form}} This properly populates the values. but it isn't submitting properly. After the form submits I would like it to return to the database and show me the user that was just added. Also, I set my database to autoincrement the ID which should solve the id problem I was thinking I could set something in my transition_form function that if form.process().accepted: redirect(URL('user_list')), but I get an error saying table object has no attribute '_formkey' does this mean I need to do some type of form validation? On Monday, May 5, 2014 9:53:38 AM UTC-4, Richard wrote: Please show code!! Richard On Mon, May 5, 2014 at 8:50 AM, LoveWeb2py atayl...@gmail.comwrote: Also, When I click the submit button in {{=form}} it doesn't actually submit anything. It just doubles the values that are already in the fields and puts them into a list. I think I need to do something like db.insert with a new ID number for the submit button. On Monday, May 5, 2014 8:46:25 AM UTC-4, LoveWeb2py wrote: Richard/Niphold, Thank you so much. It's almost done. Just getting attribute error now but I am going to try to fix that with exception handling. type 'exceptions.AttributeError' 'str' object has no attribute 'year' I have a modified_on field which is set to datetime. WHen I comment that out it transfers to the next page with no problem. Any thoughts on how I could fix? On Sunday, May 4, 2014 9:10:55 AM UTC-4, Richard wrote: Sorry for miss leading, Niphold is true... So, for f, v in request.vars.iteritmes(): db.table[f].default = v On Sat, May 3, 2014 at 8:47 AM, Niphlod nip...@gmail.com wrote: request.vars is like a dict. Surely you're hitting that issue :-P test = dict(a=1,b=2) for k,v in test: ...print k, v ... Traceback (most recent call last): File stdin, line 1, in module ValueError: need more than 1 value to unpack Add an iteritems() and you're good to go for k,v in test.iteritems(): ... print k,v ... a 1 b 2 On Friday, May 2, 2014 11:20:40 PM UTC+2, LoveWeb2py wrote: Web2py admin console has a red line at for f, v in request.vars: and then says too many values to unpack. my function is def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) Should I have extra values in the dict method? --
Re: [web2py] Re: Create a copy record button in SQLFORM?
Would you please show the exact code, the one for the SQLFORM.grid funciton and the one for the SQLFORM function... Richard On Mon, May 5, 2014 at 11:33 AM, LoveWeb2py atayloru...@gmail.com wrote: Still doesn't work. Says I'm missing _formkey. Also worth noting right when I get to the form it says 'please fill out the form' as in its processing the else already before it even accepts the data... On Monday, May 5, 2014 11:13:09 AM UTC-4, Richard wrote: You miss this part in what you show me : if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'form has errors' else: response.flash = 'please fill out the form' Avoid using user_signature at the begining, and you can add this more secure thing latter on. Richard On Mon, May 5, 2014 at 10:40 AM, LoveWeb2py atayl...@gmail.com wrote: I've read that, Richard. When using this I get that error: def transition_form(): for f, v in request.vars.iteritems(): db.users[f].default = v form = SQLFORM(db.users, user_signature=True) if form.process().accepted: response.flash = 'form accepted' return dict(form=form) Still get the same error : type 'exceptions.AttributeError' 'Table' object has no attribute '_formkey' On Monday, May 5, 2014 10:34:28 AM UTC-4, Richard wrote: That what I thought! How do you validate your form?? Please read the book a bit more about form submission... http://web2py.com/books/default/chapter/29/07/forms-and- validators#SQLFORM def display_form(): form = SQLFORM(db.person) if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'form has errors' else: response.flash = 'please fill out the form' return dict(form=form) You need to process the form, see if it validate... You shouldn't have to insert manually your data if you don't need facy thing and form.process().accepted should handle everything for you. Richard On Mon, May 5, 2014 at 10:03 AM, LoveWeb2py atayl...@gmail.com wrote: Sorry forgot to add .iteritems(): this is the most updated version. On Monday, May 5, 2014 10:01:46 AM UTC-4, LoveWeb2py wrote: Hi Richard, Here is what I have so far: Controllers: def user_list(): grid=SQLFORM.smartgrid(db.users, paginate=20, links_placement='left', _href=URL('transition_form', vars=dict((f, row[f]) for f in db.users.fields], user_signature=True) return dict(grid=grid) def transition_form(): for f, v in request.vars.iteritems(): db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) View: user_list.html {{=form}} This properly populates the values. but it isn't submitting properly. After the form submits I would like it to return to the database and show me the user that was just added. Also, I set my database to autoincrement the ID which should solve the id problem I was thinking I could set something in my transition_form function that if form.process().accepted: redirect(URL('user_list')), but I get an error saying table object has no attribute '_formkey' does this mean I need to do some type of form validation? On Monday, May 5, 2014 9:53:38 AM UTC-4, Richard wrote: Please show code!! Richard On Mon, May 5, 2014 at 8:50 AM, LoveWeb2py atayl...@gmail.comwrote: Also, When I click the submit button in {{=form}} it doesn't actually submit anything. It just doubles the values that are already in the fields and puts them into a list. I think I need to do something like db.insert with a new ID number for the submit button. On Monday, May 5, 2014 8:46:25 AM UTC-4, LoveWeb2py wrote: Richard/Niphold, Thank you so much. It's almost done. Just getting attribute error now but I am going to try to fix that with exception handling. type 'exceptions.AttributeError' 'str' object has no attribute 'year' I have a modified_on field which is set to datetime. WHen I comment that out it transfers to the next page with no problem. Any thoughts on how I could fix? On Sunday, May 4, 2014 9:10:55 AM UTC-4, Richard wrote: Sorry for miss leading, Niphold is true... So, for f, v in request.vars.iteritmes(): db.table[f].default = v On Sat, May 3, 2014 at 8:47 AM, Niphlod nip...@gmail.com wrote: request.vars is like a dict. Surely you're hitting that issue :-P test = dict(a=1,b=2) for k,v in test: ...print k, v ... Traceback (most recent call last): File stdin, line 1, in module ValueError: need more than 1 value to unpack Add an iteritems() and you're good to go for k,v in test.iteritems(): ... print k,v ... a 1 b 2 On Friday, May 2, 2014 11:20:40 PM UTC+2, LoveWeb2py wrote: Web2py admin console has a red line at for f, v in request.vars: and then says too many values to unpack. my function is def transition_form(): for f, v in request.vars:
Re: [web2py] Re: Create a copy record button in SQLFORM?
Controllers: @auth.requires_login() def users_list(): grid=SQLFROM.smartgrid(db.users, paginate=20, links_placement='left', links=[dict(header='', body=lambda row: A(I(_class='icon retweet icon-retweet'), _href=URL('transition_form', vars=dict((f, row[f]) for f in db.users.fields], user_signature=True) return dict(grid=grid) @auth.requires_login() def transition_form(): for f, v in request.vars.iteritems(): db.users[f].default = v form = SQLFORM(db.users) if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'errors on page' else: response.flash = 'facepalm' return dict(form=form) It populates the transition_form properly it just doesn't insert the new record when I click submit. It just doubles the record and returns the response in the view. Also, when loading the transition_form page it automatically flashes with 'facepalm' which means its processing the form on load. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
You got 'facepalm' because it's not process the form when you get redirected... Since you don't redirect once the form get accepted and process web2py return the same function once the form validate and get process. Now maybe you should delete the request.vars once you have assign them as default value... An other issue maybe related to the fact that your vars names are the same of form.vars... I had issue with name collision in the pass deleting the request.vars after iteratio on it may help. Richard On Mon, May 5, 2014 at 11:57 AM, LoveWeb2py atayloru...@gmail.com wrote: Controllers: @auth.requires_login() def users_list(): grid=SQLFROM.smartgrid(db.users, paginate=20, links_placement='left', links=[dict(header='', body=lambda row: A(I(_class='icon retweet icon-retweet'), _href=URL('transition_form', vars=dict((f, row[f]) for f in db.users.fields], user_signature=True) return dict(grid=grid) @auth.requires_login() def transition_form(): for f, v in request.vars.iteritems(): db.users[f].default = v form = SQLFORM(db.users) if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'errors on page' else: response.flash = 'facepalm' return dict(form=form) It populates the transition_form properly it just doesn't insert the new record when I click submit. It just doubles the record and returns the response in the view. Also, when loading the transition_form page it automatically flashes with 'facepalm' which means its processing the form on load. -- 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. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
I tried adding def transition_form(): for f, v in request.vars.iteritems(): db.users[f].default = v form = SQLFORM(db.users) response.vars = '' if form.process().accepted: response.flash = 'form accepted' redirect(URL('users_list')) elif form.errors: response.flash = 'errors on page' else: response.flash = 'facepalm' return dict(form=form) but the same issue of 'Table' object has no attribute '_formkey' still exist. I checked with firebug and the _formkey is under hidden values so it is posting, but for some reason the page isn't picking it up... On Monday, May 5, 2014 12:12:29 PM UTC-4, Richard wrote: You got 'facepalm' because it's not process the form when you get redirected... Since you don't redirect once the form get accepted and process web2py return the same function once the form validate and get process. Now maybe you should delete the request.vars once you have assign them as default value... An other issue maybe related to the fact that your vars names are the same of form.vars... I had issue with name collision in the pass deleting the request.vars after iteratio on it may help. Richard On Mon, May 5, 2014 at 11:57 AM, LoveWeb2py atayl...@gmail.comjavascript: wrote: Controllers: @auth.requires_login() def users_list(): grid=SQLFROM.smartgrid(db.users, paginate=20, links_placement='left', links=[dict(header='', body=lambda row: A(I(_class='icon retweet icon-retweet'), _href=URL('transition_form', vars=dict((f, row[f]) for f in db.users.fields], user_signature=True) return dict(grid=grid) @auth.requires_login() def transition_form(): for f, v in request.vars.iteritems(): db.users[f].default = v form = SQLFORM(db.users) if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'errors on page' else: response.flash = 'facepalm' return dict(form=form) It populates the transition_form properly it just doesn't insert the new record when I click submit. It just doubles the record and returns the response in the view. Also, when loading the transition_form page it automatically flashes with 'facepalm' which means its processing the form on load. -- 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+un...@googlegroups.com javascript:. For more options, visit https://groups.google.com/d/optout. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
I created a clean function and removed the for f, v in request.vars.iteritems():db.users[f].default = v and the form works fine and properly redirects upon submit. So it has to be something with the for loop? def transition_form(): form = SQLFORM(db.users) response.vars = '' if form.process().accepted: response.flash = 'form accepted' redirect(URL('users_list')) elif form.errors: response.flash = 'errors on page' else: response.flash = 'facepalm' return dict(form=form) On Monday, May 5, 2014 12:21:29 PM UTC-4, LoveWeb2py wrote: I tried adding def transition_form(): for f, v in request.vars.iteritems(): db.users[f].default = v form = SQLFORM(db.users) response.vars = '' if form.process().accepted: response.flash = 'form accepted' redirect(URL('users_list')) elif form.errors: response.flash = 'errors on page' else: response.flash = 'facepalm' return dict(form=form) but the same issue of 'Table' object has no attribute '_formkey' still exist. I checked with firebug and the _formkey is under hidden values so it is posting, but for some reason the page isn't picking it up... On Monday, May 5, 2014 12:12:29 PM UTC-4, Richard wrote: You got 'facepalm' because it's not process the form when you get redirected... Since you don't redirect once the form get accepted and process web2py return the same function once the form validate and get process. Now maybe you should delete the request.vars once you have assign them as default value... An other issue maybe related to the fact that your vars names are the same of form.vars... I had issue with name collision in the pass deleting the request.vars after iteratio on it may help. Richard On Mon, May 5, 2014 at 11:57 AM, LoveWeb2py atayl...@gmail.com wrote: Controllers: @auth.requires_login() def users_list(): grid=SQLFROM.smartgrid(db.users, paginate=20, links_placement='left', links=[dict(header='', body=lambda row: A(I(_class='icon retweet icon-retweet'), _href=URL('transition_form', vars=dict((f, row[f]) for f in db.users.fields], user_signature=True) return dict(grid=grid) @auth.requires_login() def transition_form(): for f, v in request.vars.iteritems(): db.users[f].default = v form = SQLFORM(db.users) if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'errors on page' else: response.flash = 'facepalm' return dict(form=form) It populates the transition_form properly it just doesn't insert the new record when I click submit. It just doubles the record and returns the response in the view. Also, when loading the transition_form page it automatically flashes with 'facepalm' which means its processing the form on load. -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
I figured it out, but its not the most pythonic way of doing things. I had to specify db.users['dictKey'].default = request.vars['dictKey] for all 20 fields. Again it works, just not sure why the for loop was throwing it off. Thanks so much for your help, Richard!! On Monday, May 5, 2014 12:27:16 PM UTC-4, LoveWeb2py wrote: I created a clean function and removed the for f, v in request.vars.iteritems():db.users[f].default = v and the form works fine and properly redirects upon submit. So it has to be something with the for loop? def transition_form(): form = SQLFORM(db.users) response.vars = '' if form.process().accepted: response.flash = 'form accepted' redirect(URL('users_list')) elif form.errors: response.flash = 'errors on page' else: response.flash = 'facepalm' return dict(form=form) On Monday, May 5, 2014 12:21:29 PM UTC-4, LoveWeb2py wrote: I tried adding def transition_form(): for f, v in request.vars.iteritems(): db.users[f].default = v form = SQLFORM(db.users) response.vars = '' if form.process().accepted: response.flash = 'form accepted' redirect(URL('users_list')) elif form.errors: response.flash = 'errors on page' else: response.flash = 'facepalm' return dict(form=form) but the same issue of 'Table' object has no attribute '_formkey' still exist. I checked with firebug and the _formkey is under hidden values so it is posting, but for some reason the page isn't picking it up... On Monday, May 5, 2014 12:12:29 PM UTC-4, Richard wrote: You got 'facepalm' because it's not process the form when you get redirected... Since you don't redirect once the form get accepted and process web2py return the same function once the form validate and get process. Now maybe you should delete the request.vars once you have assign them as default value... An other issue maybe related to the fact that your vars names are the same of form.vars... I had issue with name collision in the pass deleting the request.vars after iteratio on it may help. Richard On Mon, May 5, 2014 at 11:57 AM, LoveWeb2py atayl...@gmail.com wrote: Controllers: @auth.requires_login() def users_list(): grid=SQLFROM.smartgrid(db.users, paginate=20, links_placement='left', links=[dict(header='', body=lambda row: A(I(_class='icon retweet icon-retweet'), _href=URL('transition_form', vars=dict((f, row[f]) for f in db.users.fields], user_signature=True) return dict(grid=grid) @auth.requires_login() def transition_form(): for f, v in request.vars.iteritems(): db.users[f].default = v form = SQLFORM(db.users) if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'errors on page' else: response.flash = 'facepalm' return dict(form=form) It populates the transition_form properly it just doesn't insert the new record when I click submit. It just doubles the record and returns the response in the view. Also, when loading the transition_form page it automatically flashes with 'facepalm' which means its processing the form on load. -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
do request.vars.clear() instead of response.vars = '' Richard On Mon, May 5, 2014 at 12:59 PM, LoveWeb2py atayloru...@gmail.com wrote: I figured it out, but its not the most pythonic way of doing things. I had to specify db.users['dictKey'].default = request.vars['dictKey] for all 20 fields. Again it works, just not sure why the for loop was throwing it off. Thanks so much for your help, Richard!! On Monday, May 5, 2014 12:27:16 PM UTC-4, LoveWeb2py wrote: I created a clean function and removed the for f, v in request.vars.iteritems():db.users[f].default = v and the form works fine and properly redirects upon submit. So it has to be something with the for loop? def transition_form(): form = SQLFORM(db.users) response.vars = '' if form.process().accepted: response.flash = 'form accepted' redirect(URL('users_list')) elif form.errors: response.flash = 'errors on page' else: response.flash = 'facepalm' return dict(form=form) On Monday, May 5, 2014 12:21:29 PM UTC-4, LoveWeb2py wrote: I tried adding def transition_form(): for f, v in request.vars.iteritems(): db.users[f].default = v form = SQLFORM(db.users) response.vars = '' if form.process().accepted: response.flash = 'form accepted' redirect(URL('users_list')) elif form.errors: response.flash = 'errors on page' else: response.flash = 'facepalm' return dict(form=form) but the same issue of 'Table' object has no attribute '_formkey' still exist. I checked with firebug and the _formkey is under hidden values so it is posting, but for some reason the page isn't picking it up... On Monday, May 5, 2014 12:12:29 PM UTC-4, Richard wrote: You got 'facepalm' because it's not process the form when you get redirected... Since you don't redirect once the form get accepted and process web2py return the same function once the form validate and get process. Now maybe you should delete the request.vars once you have assign them as default value... An other issue maybe related to the fact that your vars names are the same of form.vars... I had issue with name collision in the pass deleting the request.vars after iteratio on it may help. Richard On Mon, May 5, 2014 at 11:57 AM, LoveWeb2py atayl...@gmail.com wrote: Controllers: @auth.requires_login() def users_list(): grid=SQLFROM.smartgrid(db.users, paginate=20, links_placement='left', links=[dict(header='', body=lambda row: A(I(_class='icon retweet icon-retweet'), _href=URL('transition_form', vars=dict((f, row[f]) for f in db.users.fields], user_signature=True) return dict(grid=grid) @auth.requires_login() def transition_form(): for f, v in request.vars.iteritems(): db.users[f].default = v form = SQLFORM(db.users) if form.process().accepted: response.flash = 'form accepted' elif form.errors: response.flash = 'errors on page' else: response.flash = 'facepalm' return dict(form=form) It populates the transition_form properly it just doesn't insert the new record when I click submit. It just doubles the record and returns the response in the view. Also, when loading the transition_form page it automatically flashes with 'facepalm' which means its processing the form on load. -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
Sorry for miss leading, Niphold is true... So, for f, v in request.vars.iteritmes(): db.table[f].default = v On Sat, May 3, 2014 at 8:47 AM, Niphlod niph...@gmail.com wrote: request.vars is like a dict. Surely you're hitting that issue :-P test = dict(a=1,b=2) for k,v in test: ...print k, v ... Traceback (most recent call last): File stdin, line 1, in module ValueError: need more than 1 value to unpack Add an iteritems() and you're good to go for k,v in test.iteritems(): ... print k,v ... a 1 b 2 On Friday, May 2, 2014 11:20:40 PM UTC+2, LoveWeb2py wrote: Web2py admin console has a red line at for f, v in request.vars: and then says too many values to unpack. my function is def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) Should I have extra values in the dict method? -- 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. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
request.vars is like a dict. Surely you're hitting that issue :-P test = dict(a=1,b=2) for k,v in test: ...print k, v ... Traceback (most recent call last): File stdin, line 1, in module ValueError: need more than 1 value to unpack Add an iteritems() and you're good to go for k,v in test.iteritems(): ... print k,v ... a 1 b 2 On Friday, May 2, 2014 11:20:40 PM UTC+2, LoveWeb2py wrote: Web2py admin console has a red line at for f, v in request.vars: and then says too many values to unpack. my function is def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) Should I have extra values in the dict method? -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver.fr...@gmx.net wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items(): if k in db.t_disciplin.fields: if k == 'f_title': v = v + _copy recname = str(v) # Needed to redirect the page to the right record if k != 'id': vals[k] = v db.t_disziplin.insert(**vals) rec = db(db.t_disziplin.f_title == recname).select().first() rec_id = rec.id # redirect for edit the new record redirect(URL(r=request, f='konstanten/t_disciplin/edit/t_disciplin',args=str(rec_id))) Am Freitag, 2. Mai 2014 14:29:26 UTC+2 schrieb LoveWeb2py: Hello, There are many times when I just want to copy the values of one record in my sqlform and create a new record, but modify the content and save it. Is there an easy way to do this with web2py or would I have to write the code? Many thanks -- 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. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
Richard, How do I assign this to a button though? On Friday, May 2, 2014 9:30:21 AM UTC-4, Richard wrote: keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver...@gmx.net javascript:wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items(): if k in db.t_disciplin.fields: if k == 'f_title': v = v + _copy recname = str(v) # Needed to redirect the page to the right record if k != 'id': vals[k] = v db.t_disziplin.insert(**vals) rec = db(db.t_disziplin.f_title == recname).select().first() rec_id = rec.id # redirect for edit the new record redirect(URL(r=request, f='konstanten/t_disciplin/edit/t_disciplin',args=str(rec_id))) Am Freitag, 2. Mai 2014 14:29:26 UTC+2 schrieb LoveWeb2py: Hello, There are many times when I just want to copy the values of one record in my sqlform and create a new record, but modify the content and save it. Is there an easy way to do this with web2py or would I have to write the code? Many thanks -- 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+un...@googlegroups.com javascript:. For more options, visit https://groups.google.com/d/optout. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2 and assign .default= request.vars.field1 Richard On Fri, May 2, 2014 at 9:33 AM, LoveWeb2py atayloru...@gmail.com wrote: Richard, How do I assign this to a button though? On Friday, May 2, 2014 9:30:21 AM UTC-4, Richard wrote: keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver...@gmx.net wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items(): if k in db.t_disciplin.fields: if k == 'f_title': v = v + _copy recname = str(v) # Needed to redirect the page to the right record if k != 'id': vals[k] = v db.t_disziplin.insert(**vals) rec = db(db.t_disziplin.f_title == recname).select().first() rec_id = rec.id # redirect for edit the new record redirect(URL(r=request, f='konstanten/t_disciplin/ edit/t_disciplin',args=str(rec_id))) Am Freitag, 2. Mai 2014 14:29:26 UTC+2 schrieb LoveWeb2py: Hello, There are many times when I just want to copy the values of one record in my sqlform and create a new record, but modify the content and save it. Is there an easy way to do this with web2py or would I have to write the code? Many thanks -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2 and assign .default= request.vars.field1 Richard On Fri, May 2, 2014 at 9:33 AM, LoveWeb2py atayl...@gmail.comjavascript: wrote: Richard, How do I assign this to a button though? On Friday, May 2, 2014 9:30:21 AM UTC-4, Richard wrote: keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver...@gmx.net wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items(): if k in db.t_disciplin.fields: if k == 'f_title': v = v + _copy recname = str(v) # Needed to redirect the page to the right record if k != 'id': vals[k] = v db.t_disziplin.insert(**vals) rec = db(db.t_disziplin.f_title == recname).select().first() rec_id = rec.id # redirect for edit the new record redirect(URL(r=request, f='konstanten/t_disciplin/ edit/t_disciplin',args=str(rec_id))) Am Freitag, 2. Mai 2014 14:29:26 UTC+2 schrieb LoveWeb2py: Hello, There are many times when I just want to copy the values of one record in my sqlform and create a new record, but modify the content and save it. Is there an easy way to do this with web2py or would I have to write the code? Many thanks -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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+un...@googlegroups.com javascript:. For more options, visit https://groups.google.com/d/optout. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2 and assign .default= request.vars.field1 Richard On Fri, May 2, 2014 at 9:33 AM, LoveWeb2py atayl...@gmail.com wrote: Richard, How do I assign this to a button though? On Friday, May 2, 2014 9:30:21 AM UTC-4, Richard wrote: keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver...@gmx.net wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items(): if k in db.t_disciplin.fields: if k == 'f_title': v = v + _copy recname = str(v) # Needed to redirect the page to the right record if k != 'id': vals[k] = v db.t_disziplin.insert(**vals) rec = db(db.t_disziplin.f_title == recname).select().first() rec_id = rec.id # redirect for edit the new record redirect(URL(r=request, f='konstanten/t_disciplin/ edit/t_disciplin',args=str(rec_id))) Am Freitag, 2. Mai 2014 14:29:26 UTC+2 schrieb LoveWeb2py: Hello, There are many times when I just want to copy the values of one record in my sqlform and create a new record, but modify the content and save it. Is there an easy way to do this with web2py or would I have to write the code? Many thanks -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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.
Re: [web2py] Re: Create a copy record button in SQLFORM?
Yes, so you want to pas by a transitionnal form with the data preset base on the copied record values, where you can make the change you want before submit the form. So if you have a grid where you can select the record to copy with the icon you want that link to the transitionnal form, you just have to pass the value of the record to the form throught out URL vars... You can iter like that : SQLFORM.grid(..., links=[dict(header='', body=lambda row: A(I(_class='icon some_icon'), _href=URL('transitionnal_form', vars={f: row[f] for f in db.table.fields}],) This part : {f: row[f] for f in db.table.fields} Is a dict comprehension... Then in transitionnal form controller you do something like that : def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, ...) ... Richard On Fri, May 2, 2014 at 10:18 AM, LoveWeb2py atayloru...@gmail.com wrote: Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2 and assign .default= request.vars.field1 Richard On Fri, May 2, 2014 at 9:33 AM, LoveWeb2py atayl...@gmail.com wrote: Richard, How do I assign this to a button though? On Friday, May 2, 2014 9:30:21 AM UTC-4, Richard wrote: keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver...@gmx.net wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items(): if k in db.t_disciplin.fields: if k == 'f_title': v = v + _copy recname = str(v) # Needed to redirect the page to the right record if k != 'id': vals[k] = v db.t_disziplin.insert(**vals) rec = db(db.t_disziplin.f_title == recname).select().first() rec_id = rec.id # redirect for edit the new record redirect(URL(r=request, f='konstanten/t_disciplin/edit /t_disciplin',args=str(rec_id))) Am Freitag, 2. Mai 2014 14:29:26 UTC+2 schrieb LoveWeb2py: Hello, There are many times when I just want to copy the values of one record in my sqlform and create a new record, but modify the content and save it. Is there an easy way to do this with web2py or would I have to write the code? Many thanks -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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. -- Resources: -
Re: [web2py] Re: Create a copy record button in SQLFORM?
for this part: {f: row[f] for f in db.table.fields} what do I put for fields... could I just leave it as fields? On Friday, May 2, 2014 11:16:09 AM UTC-4, Richard wrote: Yes, so you want to pas by a transitionnal form with the data preset base on the copied record values, where you can make the change you want before submit the form. So if you have a grid where you can select the record to copy with the icon you want that link to the transitionnal form, you just have to pass the value of the record to the form throught out URL vars... You can iter like that : SQLFORM.grid(..., links=[dict(header='', body=lambda row: A(I(_class='icon some_icon'), _href=URL('transitionnal_form', vars={f: row[f] for f in db.table.fields}],) This part : {f: row[f] for f in db.table.fields} Is a dict comprehension... Then in transitionnal form controller you do something like that : def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, ...) ... Richard On Fri, May 2, 2014 at 10:18 AM, LoveWeb2py atayl...@gmail.comjavascript: wrote: Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2 and assign .default= request.vars.field1 Richard On Fri, May 2, 2014 at 9:33 AM, LoveWeb2py atayl...@gmail.com wrote: Richard, How do I assign this to a button though? On Friday, May 2, 2014 9:30:21 AM UTC-4, Richard wrote: keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver...@gmx.net wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items(): if k in db.t_disciplin.fields: if k == 'f_title': v = v + _copy recname = str(v) # Needed to redirect the page to the right record if k != 'id': vals[k] = v db.t_disziplin.insert(**vals) rec = db(db.t_disziplin.f_title == recname).select().first() rec_id = rec.id # redirect for edit the new record redirect(URL(r=request, f='konstanten/t_disciplin/edit /t_disciplin',args=str(rec_id))) Am Freitag, 2. Mai 2014 14:29:26 UTC+2 schrieb LoveWeb2py: Hello, There are many times when I just want to copy the values of one record in my sqlform and create a new record, but modify the content and save it. Is there an easy way to do this with web2py or would I have to write the code? Many thanks -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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
Re: [web2py] Re: Create a copy record button in SQLFORM?
I just realized I might be running into problems because I'm using 2.3. I haven't upgraded because the new web2py threw my css off. It looks like you're referencing the virtual fields? http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Old-style-virtual-fields If you think I should upgrade i'll make the change, but if I could stick with 2.3 I would prefer to do so On Friday, May 2, 2014 3:10:15 PM UTC-4, LoveWeb2py wrote: for this part: {f: row[f] for f in db.table.fields} what do I put for fields... could I just leave it as fields? On Friday, May 2, 2014 11:16:09 AM UTC-4, Richard wrote: Yes, so you want to pas by a transitionnal form with the data preset base on the copied record values, where you can make the change you want before submit the form. So if you have a grid where you can select the record to copy with the icon you want that link to the transitionnal form, you just have to pass the value of the record to the form throught out URL vars... You can iter like that : SQLFORM.grid(..., links=[dict(header='', body=lambda row: A(I(_class='icon some_icon'), _href=URL('transitionnal_form', vars={f: row[f] for f in db.table.fields}],) This part : {f: row[f] for f in db.table.fields} Is a dict comprehension... Then in transitionnal form controller you do something like that : def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, ...) ... Richard On Fri, May 2, 2014 at 10:18 AM, LoveWeb2py atayl...@gmail.com wrote: Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2 and assign .default= request.vars.field1 Richard On Fri, May 2, 2014 at 9:33 AM, LoveWeb2py atayl...@gmail.com wrote: Richard, How do I assign this to a button though? On Friday, May 2, 2014 9:30:21 AM UTC-4, Richard wrote: keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver...@gmx.net wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items(): if k in db.t_disciplin.fields: if k == 'f_title': v = v + _copy recname = str(v) # Needed to redirect the page to the right record if k != 'id': vals[k] = v db.t_disziplin.insert(**vals) rec = db(db.t_disziplin.f_title == recname).select().first() rec_id = rec.id # redirect for edit the new record redirect(URL(r=request, f='konstanten/t_disciplin/edit /t_disciplin',args=str(rec_id))) Am Freitag, 2. Mai 2014 14:29:26 UTC+2 schrieb LoveWeb2py: Hello, There are many times when I just want to copy the values of one record in my sqlform and create a new record, but modify the content and save it. Is there an easy way to do this with web2py or would I have to write the code? Many thanks -- 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+un...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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
Re: [web2py] Re: Create a copy record button in SQLFORM?
Okay quick update: I loaded a row into python to test the comprehension. row = db(db.table.id0).select().first() {f: row[f] for f in db.table.fields} prints out the list fine and its exactly how Id like to prepopulate my field on the transition form. Thank you for getting me this far. However when I try to type vars={f: row[f] for f in db.table.fields})))] I get invalid syntax and the ^ points to the for in the dict comprehension. When I use regular python it works fine. Any thoughts? On Friday, May 2, 2014 3:16:24 PM UTC-4, LoveWeb2py wrote: I just realized I might be running into problems because I'm using 2.3. I haven't upgraded because the new web2py threw my css off. It looks like you're referencing the virtual fields? http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Old-style-virtual-fields If you think I should upgrade i'll make the change, but if I could stick with 2.3 I would prefer to do so On Friday, May 2, 2014 3:10:15 PM UTC-4, LoveWeb2py wrote: for this part: {f: row[f] for f in db.table.fields} what do I put for fields... could I just leave it as fields? On Friday, May 2, 2014 11:16:09 AM UTC-4, Richard wrote: Yes, so you want to pas by a transitionnal form with the data preset base on the copied record values, where you can make the change you want before submit the form. So if you have a grid where you can select the record to copy with the icon you want that link to the transitionnal form, you just have to pass the value of the record to the form throught out URL vars... You can iter like that : SQLFORM.grid(..., links=[dict(header='', body=lambda row: A(I(_class='icon some_icon'), _href=URL('transitionnal_form', vars={f: row[f] for f in db.table.fields}],) This part : {f: row[f] for f in db.table.fields} Is a dict comprehension... Then in transitionnal form controller you do something like that : def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, ...) ... Richard On Fri, May 2, 2014 at 10:18 AM, LoveWeb2py atayl...@gmail.com wrote: Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2 and assign .default= request.vars.field1 Richard On Fri, May 2, 2014 at 9:33 AM, LoveWeb2py atayl...@gmail.comwrote: Richard, How do I assign this to a button though? On Friday, May 2, 2014 9:30:21 AM UTC-4, Richard wrote: keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver...@gmx.net wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items(): if k in db.t_disciplin.fields: if k == 'f_title': v = v + _copy recname = str(v) # Needed to redirect the page to the right record if k != 'id': vals[k] = v db.t_disziplin.insert(**vals) rec = db(db.t_disziplin.f_title == recname).select().first() rec_id = rec.id # redirect for edit the new record redirect(URL(r=request, f='konstanten/t_disciplin/edit /t_disciplin',args=str(rec_id))) Am Freitag, 2. Mai 2014 14:29:26 UTC+2 schrieb LoveWeb2py: Hello, There are many times when I just want to copy the values of one record in my sqlform and create a new record, but modify the content and save it. Is there an easy way to do this with web2py or would I have to write the code? Many thanks -- 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
Re: [web2py] Re: Create a copy record button in SQLFORM?
Okay... I think I see the issue. My web2py is running Python 2.6 and my Interpreter is 2.7. dictionary comprehension changed between those versions. I'm going to try and construct a dict comprehension for 2.6 and try it again. On Friday, May 2, 2014 3:40:53 PM UTC-4, LoveWeb2py wrote: Okay quick update: I loaded a row into python to test the comprehension. row = db(db.table.id0).select().first() {f: row[f] for f in db.table.fields} prints out the list fine and its exactly how Id like to prepopulate my field on the transition form. Thank you for getting me this far. However when I try to type vars={f: row[f] for f in db.table.fields})))] I get invalid syntax and the ^ points to the for in the dict comprehension. When I use regular python it works fine. Any thoughts? On Friday, May 2, 2014 3:16:24 PM UTC-4, LoveWeb2py wrote: I just realized I might be running into problems because I'm using 2.3. I haven't upgraded because the new web2py threw my css off. It looks like you're referencing the virtual fields? http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Old-style-virtual-fields If you think I should upgrade i'll make the change, but if I could stick with 2.3 I would prefer to do so On Friday, May 2, 2014 3:10:15 PM UTC-4, LoveWeb2py wrote: for this part: {f: row[f] for f in db.table.fields} what do I put for fields... could I just leave it as fields? On Friday, May 2, 2014 11:16:09 AM UTC-4, Richard wrote: Yes, so you want to pas by a transitionnal form with the data preset base on the copied record values, where you can make the change you want before submit the form. So if you have a grid where you can select the record to copy with the icon you want that link to the transitionnal form, you just have to pass the value of the record to the form throught out URL vars... You can iter like that : SQLFORM.grid(..., links=[dict(header='', body=lambda row: A(I(_class='icon some_icon'), _href=URL('transitionnal_form', vars={f: row[f] for f in db.table.fields}],) This part : {f: row[f] for f in db.table.fields} Is a dict comprehension... Then in transitionnal form controller you do something like that : def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, ...) ... Richard On Fri, May 2, 2014 at 10:18 AM, LoveWeb2py atayl...@gmail.com wrote: Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2 and assign .default= request.vars.field1 Richard On Fri, May 2, 2014 at 9:33 AM, LoveWeb2py atayl...@gmail.comwrote: Richard, How do I assign this to a button though? On Friday, May 2, 2014 9:30:21 AM UTC-4, Richard wrote: keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver...@gmx.net wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items(): if k in db.t_disciplin.fields: if k == 'f_title': v = v + _copy recname = str(v) # Needed to redirect the page to the right record if k != 'id': vals[k] = v db.t_disziplin.insert(**vals) rec = db(db.t_disziplin.f_title == recname).select().first() rec_id = rec.id # redirect for edit the new record redirect(URL(r=request, f='konstanten/t_disciplin/edit /t_disciplin',args=str(rec_id))) Am Freitag, 2. Mai 2014 14:29:26 UTC+2 schrieb LoveWeb2py: Hello, There are many times when I just want to copy the values of one record in my sqlform and create a new record, but modify the content and
Re: [web2py] Re: Create a copy record button in SQLFORM?
Upgrade to 2.9.5 web2py 2.3 is very old... Consider using 2.7 for python... http://stackoverflow.com/questions/1747817/python-create-a-dictionary-with-list-comprehension You can adapt Richard On Fri, May 2, 2014 at 3:44 PM, LoveWeb2py atayloru...@gmail.com wrote: Okay... I think I see the issue. My web2py is running Python 2.6 and my Interpreter is 2.7. dictionary comprehension changed between those versions. I'm going to try and construct a dict comprehension for 2.6 and try it again. On Friday, May 2, 2014 3:40:53 PM UTC-4, LoveWeb2py wrote: Okay quick update: I loaded a row into python to test the comprehension. row = db(db.table.id0).select().first() {f: row[f] for f in db.table.fields} prints out the list fine and its exactly how Id like to prepopulate my field on the transition form. Thank you for getting me this far. However when I try to type vars={f: row[f] for f in db.table.fields})))] I get invalid syntax and the ^ points to the for in the dict comprehension. When I use regular python it works fine. Any thoughts? On Friday, May 2, 2014 3:16:24 PM UTC-4, LoveWeb2py wrote: I just realized I might be running into problems because I'm using 2.3. I haven't upgraded because the new web2py threw my css off. It looks like you're referencing the virtual fields? http://web2py.com/books/default/chapter/29/06/the- database-abstraction-layer#Old-style-virtual-fields If you think I should upgrade i'll make the change, but if I could stick with 2.3 I would prefer to do so On Friday, May 2, 2014 3:10:15 PM UTC-4, LoveWeb2py wrote: for this part: {f: row[f] for f in db.table.fields} what do I put for fields... could I just leave it as fields? On Friday, May 2, 2014 11:16:09 AM UTC-4, Richard wrote: Yes, so you want to pas by a transitionnal form with the data preset base on the copied record values, where you can make the change you want before submit the form. So if you have a grid where you can select the record to copy with the icon you want that link to the transitionnal form, you just have to pass the value of the record to the form throught out URL vars... You can iter like that : SQLFORM.grid(..., links=[dict(header='', body=lambda row: A(I(_class='icon some_icon'), _href=URL('transitionnal_form', vars={f: row[f] for f in db.table.fields}],) This part : {f: row[f] for f in db.table.fields} Is a dict comprehension... Then in transitionnal form controller you do something like that : def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, ...) ... Richard On Fri, May 2, 2014 at 10:18 AM, LoveWeb2py atayl...@gmail.comwrote: Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2 and assign .default= request.vars.field1 Richard On Fri, May 2, 2014 at 9:33 AM, LoveWeb2py atayl...@gmail.comwrote: Richard, How do I assign this to a button though? On Friday, May 2, 2014 9:30:21 AM UTC-4, Richard wrote: keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver...@gmx.net wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items(): if k in db.t_disciplin.fields: if k == 'f_title': v = v + _copy recname = str(v) # Needed to redirect the page to the right record if k != 'id': vals[k] = v db.t_disziplin.insert(**vals) rec = db(db.t_disziplin.f_title == recname).select().first() rec_id = rec.id # redirect for edit the new record redirect(URL(r=request, f='konstanten/t_disciplin/edit
Re: [web2py] Re: Create a copy record button in SQLFORM?
dict((f, row[f]) for f in db.table.fields) Richard On Fri, May 2, 2014 at 3:59 PM, Richard Vézina ml.richard.vez...@gmail.comwrote: Upgrade to 2.9.5 web2py 2.3 is very old... Consider using 2.7 for python... http://stackoverflow.com/questions/1747817/python-create-a-dictionary-with-list-comprehension You can adapt Richard On Fri, May 2, 2014 at 3:44 PM, LoveWeb2py atayloru...@gmail.com wrote: Okay... I think I see the issue. My web2py is running Python 2.6 and my Interpreter is 2.7. dictionary comprehension changed between those versions. I'm going to try and construct a dict comprehension for 2.6 and try it again. On Friday, May 2, 2014 3:40:53 PM UTC-4, LoveWeb2py wrote: Okay quick update: I loaded a row into python to test the comprehension. row = db(db.table.id0).select().first() {f: row[f] for f in db.table.fields} prints out the list fine and its exactly how Id like to prepopulate my field on the transition form. Thank you for getting me this far. However when I try to type vars={f: row[f] for f in db.table.fields})))] I get invalid syntax and the ^ points to the for in the dict comprehension. When I use regular python it works fine. Any thoughts? On Friday, May 2, 2014 3:16:24 PM UTC-4, LoveWeb2py wrote: I just realized I might be running into problems because I'm using 2.3. I haven't upgraded because the new web2py threw my css off. It looks like you're referencing the virtual fields? http://web2py.com/books/default/chapter/29/06/the- database-abstraction-layer#Old-style-virtual-fields If you think I should upgrade i'll make the change, but if I could stick with 2.3 I would prefer to do so On Friday, May 2, 2014 3:10:15 PM UTC-4, LoveWeb2py wrote: for this part: {f: row[f] for f in db.table.fields} what do I put for fields... could I just leave it as fields? On Friday, May 2, 2014 11:16:09 AM UTC-4, Richard wrote: Yes, so you want to pas by a transitionnal form with the data preset base on the copied record values, where you can make the change you want before submit the form. So if you have a grid where you can select the record to copy with the icon you want that link to the transitionnal form, you just have to pass the value of the record to the form throught out URL vars... You can iter like that : SQLFORM.grid(..., links=[dict(header='', body=lambda row: A(I(_class='icon some_icon'), _href=URL('transitionnal_form', vars={f: row[f] for f in db.table.fields}],) This part : {f: row[f] for f in db.table.fields} Is a dict comprehension... Then in transitionnal form controller you do something like that : def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, ...) ... Richard On Fri, May 2, 2014 at 10:18 AM, LoveWeb2py atayl...@gmail.comwrote: Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2 and assign .default= request.vars.field1 Richard On Fri, May 2, 2014 at 9:33 AM, LoveWeb2py atayl...@gmail.comwrote: Richard, How do I assign this to a button though? On Friday, May 2, 2014 9:30:21 AM UTC-4, Richard wrote: keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver...@gmx.net wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items(): if k in db.t_disciplin.fields: if k == 'f_title': v = v + _copy recname = str(v) # Needed to redirect the page to the right record if k != 'id': vals[k] = v db.t_disziplin.insert(**vals) rec = db(db.t_disziplin.f_title ==
Re: [web2py] Re: Create a copy record button in SQLFORM?
Is there a way to force web2py to use 2.7 instead of 2.6? I thought it was using 2.7. Thank you for being so patient. On Friday, May 2, 2014 3:59:06 PM UTC-4, Richard wrote: Upgrade to 2.9.5 web2py 2.3 is very old... Consider using 2.7 for python... http://stackoverflow.com/questions/1747817/python-create-a-dictionary-with-list-comprehension You can adapt Richard On Fri, May 2, 2014 at 3:44 PM, LoveWeb2py atayl...@gmail.comjavascript: wrote: Okay... I think I see the issue. My web2py is running Python 2.6 and my Interpreter is 2.7. dictionary comprehension changed between those versions. I'm going to try and construct a dict comprehension for 2.6 and try it again. On Friday, May 2, 2014 3:40:53 PM UTC-4, LoveWeb2py wrote: Okay quick update: I loaded a row into python to test the comprehension. row = db(db.table.id0).select().first() {f: row[f] for f in db.table.fields} prints out the list fine and its exactly how Id like to prepopulate my field on the transition form. Thank you for getting me this far. However when I try to type vars={f: row[f] for f in db.table.fields})))] I get invalid syntax and the ^ points to the for in the dict comprehension. When I use regular python it works fine. Any thoughts? On Friday, May 2, 2014 3:16:24 PM UTC-4, LoveWeb2py wrote: I just realized I might be running into problems because I'm using 2.3. I haven't upgraded because the new web2py threw my css off. It looks like you're referencing the virtual fields? http://web2py.com/books/default/chapter/29/06/the- database-abstraction-layer#Old-style-virtual-fields If you think I should upgrade i'll make the change, but if I could stick with 2.3 I would prefer to do so On Friday, May 2, 2014 3:10:15 PM UTC-4, LoveWeb2py wrote: for this part: {f: row[f] for f in db.table.fields} what do I put for fields... could I just leave it as fields? On Friday, May 2, 2014 11:16:09 AM UTC-4, Richard wrote: Yes, so you want to pas by a transitionnal form with the data preset base on the copied record values, where you can make the change you want before submit the form. So if you have a grid where you can select the record to copy with the icon you want that link to the transitionnal form, you just have to pass the value of the record to the form throught out URL vars... You can iter like that : SQLFORM.grid(..., links=[dict(header='', body=lambda row: A(I(_class='icon some_icon'), _href=URL('transitionnal_form', vars={f: row[f] for f in db.table.fields}],) This part : {f: row[f] for f in db.table.fields} Is a dict comprehension... Then in transitionnal form controller you do something like that : def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, ...) ... Richard On Fri, May 2, 2014 at 10:18 AM, LoveWeb2py atayl...@gmail.comwrote: Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2 and assign .default= request.vars.field1 Richard On Fri, May 2, 2014 at 9:33 AM, LoveWeb2py atayl...@gmail.comwrote: Richard, How do I assign this to a button though? On Friday, May 2, 2014 9:30:21 AM UTC-4, Richard wrote: keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver...@gmx.net wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items(): if k in db.t_disciplin.fields: if k == 'f_title': v = v + _copy recname = str(v) # Needed to redirect the page to the right record if k != 'id': vals[k]
Re: [web2py] Re: Create a copy record button in SQLFORM?
python2.7 web2py ... On Fri, May 2, 2014 at 4:01 PM, LoveWeb2py atayloru...@gmail.com wrote: Is there a way to force web2py to use 2.7 instead of 2.6? I thought it was using 2.7. Thank you for being so patient. On Friday, May 2, 2014 3:59:06 PM UTC-4, Richard wrote: Upgrade to 2.9.5 web2py 2.3 is very old... Consider using 2.7 for python... http://stackoverflow.com/questions/1747817/python- create-a-dictionary-with-list-comprehension You can adapt Richard On Fri, May 2, 2014 at 3:44 PM, LoveWeb2py atayl...@gmail.com wrote: Okay... I think I see the issue. My web2py is running Python 2.6 and my Interpreter is 2.7. dictionary comprehension changed between those versions. I'm going to try and construct a dict comprehension for 2.6 and try it again. On Friday, May 2, 2014 3:40:53 PM UTC-4, LoveWeb2py wrote: Okay quick update: I loaded a row into python to test the comprehension. row = db(db.table.id0).select().first() {f: row[f] for f in db.table.fields} prints out the list fine and its exactly how Id like to prepopulate my field on the transition form. Thank you for getting me this far. However when I try to type vars={f: row[f] for f in db.table.fields})))] I get invalid syntax and the ^ points to the for in the dict comprehension. When I use regular python it works fine. Any thoughts? On Friday, May 2, 2014 3:16:24 PM UTC-4, LoveWeb2py wrote: I just realized I might be running into problems because I'm using 2.3. I haven't upgraded because the new web2py threw my css off. It looks like you're referencing the virtual fields? http://web2py.com/books/default/chapter/29/06/the-database- abstraction-layer#Old-style-virtual-fields If you think I should upgrade i'll make the change, but if I could stick with 2.3 I would prefer to do so On Friday, May 2, 2014 3:10:15 PM UTC-4, LoveWeb2py wrote: for this part: {f: row[f] for f in db.table.fields} what do I put for fields... could I just leave it as fields? On Friday, May 2, 2014 11:16:09 AM UTC-4, Richard wrote: Yes, so you want to pas by a transitionnal form with the data preset base on the copied record values, where you can make the change you want before submit the form. So if you have a grid where you can select the record to copy with the icon you want that link to the transitionnal form, you just have to pass the value of the record to the form throught out URL vars... You can iter like that : SQLFORM.grid(..., links=[dict(header='', body=lambda row: A(I(_class='icon some_icon'), _href=URL('transitionnal_form', vars={f: row[f] for f in db.table.fields}],) This part : {f: row[f] for f in db.table.fields} Is a dict comprehension... Then in transitionnal form controller you do something like that : def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, ...) ... Richard On Fri, May 2, 2014 at 10:18 AM, LoveWeb2py atayl...@gmail.comwrote: Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2 and assign .default= request.vars.field1 Richard On Fri, May 2, 2014 at 9:33 AM, LoveWeb2py atayl...@gmail.comwrote: Richard, How do I assign this to a button though? On Friday, May 2, 2014 9:30:21 AM UTC-4, Richard wrote: keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver...@gmx.net wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items(): if k in db.t_disciplin.fields: if k == 'f_title': v = v + _copy recname = str(v) # Needed to redirect the page to the right record
Re: [web2py] Re: Create a copy record button in SQLFORM?
Try with dict() contructor in one of my last email if you want to stay in 2.6 Richard On Fri, May 2, 2014 at 4:02 PM, Richard Vézina ml.richard.vez...@gmail.comwrote: python2.7 web2py ... On Fri, May 2, 2014 at 4:01 PM, LoveWeb2py atayloru...@gmail.com wrote: Is there a way to force web2py to use 2.7 instead of 2.6? I thought it was using 2.7. Thank you for being so patient. On Friday, May 2, 2014 3:59:06 PM UTC-4, Richard wrote: Upgrade to 2.9.5 web2py 2.3 is very old... Consider using 2.7 for python... http://stackoverflow.com/questions/1747817/python- create-a-dictionary-with-list-comprehension You can adapt Richard On Fri, May 2, 2014 at 3:44 PM, LoveWeb2py atayl...@gmail.com wrote: Okay... I think I see the issue. My web2py is running Python 2.6 and my Interpreter is 2.7. dictionary comprehension changed between those versions. I'm going to try and construct a dict comprehension for 2.6 and try it again. On Friday, May 2, 2014 3:40:53 PM UTC-4, LoveWeb2py wrote: Okay quick update: I loaded a row into python to test the comprehension. row = db(db.table.id0).select().first() {f: row[f] for f in db.table.fields} prints out the list fine and its exactly how Id like to prepopulate my field on the transition form. Thank you for getting me this far. However when I try to type vars={f: row[f] for f in db.table.fields})))] I get invalid syntax and the ^ points to the for in the dict comprehension. When I use regular python it works fine. Any thoughts? On Friday, May 2, 2014 3:16:24 PM UTC-4, LoveWeb2py wrote: I just realized I might be running into problems because I'm using 2.3. I haven't upgraded because the new web2py threw my css off. It looks like you're referencing the virtual fields? http://web2py.com/books/default/chapter/29/06/the-database- abstraction-layer#Old-style-virtual-fields If you think I should upgrade i'll make the change, but if I could stick with 2.3 I would prefer to do so On Friday, May 2, 2014 3:10:15 PM UTC-4, LoveWeb2py wrote: for this part: {f: row[f] for f in db.table.fields} what do I put for fields... could I just leave it as fields? On Friday, May 2, 2014 11:16:09 AM UTC-4, Richard wrote: Yes, so you want to pas by a transitionnal form with the data preset base on the copied record values, where you can make the change you want before submit the form. So if you have a grid where you can select the record to copy with the icon you want that link to the transitionnal form, you just have to pass the value of the record to the form throught out URL vars... You can iter like that : SQLFORM.grid(..., links=[dict(header='', body=lambda row: A(I(_class='icon some_icon'), _href=URL('transitionnal_form', vars={f: row[f] for f in db.table.fields}],) This part : {f: row[f] for f in db.table.fields} Is a dict comprehension... Then in transitionnal form controller you do something like that : def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, ...) ... Richard On Fri, May 2, 2014 at 10:18 AM, LoveWeb2py atayl...@gmail.comwrote: Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2 and assign .default= request.vars.field1 Richard On Fri, May 2, 2014 at 9:33 AM, LoveWeb2py atayl...@gmail.comwrote: Richard, How do I assign this to a button though? On Friday, May 2, 2014 9:30:21 AM UTC-4, Richard wrote: keepvalues or row = db(...).select(db.table.record).first() db.other_table.field1.default = row.field form = SQLFORM(db.table, ...) Richard On Fri, May 2, 2014 at 9:07 AM, Oli oliver...@gmx.net wrote: I hope this help. def copy_and_edit(): copy_and_edit record = db.t_disciplin(request.args[0]) vals = {} for k,v in record.items():
Re: [web2py] Re: Create a copy record button in SQLFORM?
I will definitely upgrade in the upcoming months... but for now Im stuck with 2.6. Your dict comprehension worked, but now I'm getting an error when I click bthe button saying there are too many values to unpack. I'm guessing this is because I'm using 2.6 again and its something to do with my function: def transition_form(): for f, v in rqeuest.vars: db.table[f].default = v form = SQLFORM(db.table) return dict(form=form) On Fri, May 2, 2014 at 4:03 PM, Richard Vézina ml.richard.vez...@gmail.comwrote: Try with dict() contructor in one of my last email if you want to stay in 2.6 Richard On Fri, May 2, 2014 at 4:02 PM, Richard Vézina ml.richard.vez...@gmail.com wrote: python2.7 web2py ... On Fri, May 2, 2014 at 4:01 PM, LoveWeb2py atayloru...@gmail.com wrote: Is there a way to force web2py to use 2.7 instead of 2.6? I thought it was using 2.7. Thank you for being so patient. On Friday, May 2, 2014 3:59:06 PM UTC-4, Richard wrote: Upgrade to 2.9.5 web2py 2.3 is very old... Consider using 2.7 for python... http://stackoverflow.com/questions/1747817/python- create-a-dictionary-with-list-comprehension You can adapt Richard On Fri, May 2, 2014 at 3:44 PM, LoveWeb2py atayl...@gmail.com wrote: Okay... I think I see the issue. My web2py is running Python 2.6 and my Interpreter is 2.7. dictionary comprehension changed between those versions. I'm going to try and construct a dict comprehension for 2.6 and try it again. On Friday, May 2, 2014 3:40:53 PM UTC-4, LoveWeb2py wrote: Okay quick update: I loaded a row into python to test the comprehension. row = db(db.table.id0).select().first() {f: row[f] for f in db.table.fields} prints out the list fine and its exactly how Id like to prepopulate my field on the transition form. Thank you for getting me this far. However when I try to type vars={f: row[f] for f in db.table.fields})))] I get invalid syntax and the ^ points to the for in the dict comprehension. When I use regular python it works fine. Any thoughts? On Friday, May 2, 2014 3:16:24 PM UTC-4, LoveWeb2py wrote: I just realized I might be running into problems because I'm using 2.3. I haven't upgraded because the new web2py threw my css off. It looks like you're referencing the virtual fields? http://web2py.com/books/default/chapter/29/06/the-database- abstraction-layer#Old-style-virtual-fields If you think I should upgrade i'll make the change, but if I could stick with 2.3 I would prefer to do so On Friday, May 2, 2014 3:10:15 PM UTC-4, LoveWeb2py wrote: for this part: {f: row[f] for f in db.table.fields} what do I put for fields... could I just leave it as fields? On Friday, May 2, 2014 11:16:09 AM UTC-4, Richard wrote: Yes, so you want to pas by a transitionnal form with the data preset base on the copied record values, where you can make the change you want before submit the form. So if you have a grid where you can select the record to copy with the icon you want that link to the transitionnal form, you just have to pass the value of the record to the form throught out URL vars... You can iter like that : SQLFORM.grid(..., links=[dict(header='', body=lambda row: A(I(_class='icon some_icon'), _href=URL('transitionnal_form', vars={f: row[f] for f in db.table.fields}],) This part : {f: row[f] for f in db.table.fields} Is a dict comprehension... Then in transitionnal form controller you do something like that : def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, ...) ... Richard On Fri, May 2, 2014 at 10:18 AM, LoveWeb2py atayl...@gmail.comwrote: Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2 and assign .default= request.vars.field1 Richard On Fri, May 2, 2014 at 9:33 AM, LoveWeb2py
Re: [web2py] Re: Create a copy record button in SQLFORM?
**dict(...) On Fri, May 2, 2014 at 4:10 PM, Austin Taylor atayloru...@gmail.com wrote: I will definitely upgrade in the upcoming months... but for now Im stuck with 2.6. Your dict comprehension worked, but now I'm getting an error when I click bthe button saying there are too many values to unpack. I'm guessing this is because I'm using 2.6 again and its something to do with my function: def transition_form(): for f, v in rqeuest.vars: db.table[f].default = v form = SQLFORM(db.table) return dict(form=form) On Fri, May 2, 2014 at 4:03 PM, Richard Vézina ml.richard.vez...@gmail.com wrote: Try with dict() contructor in one of my last email if you want to stay in 2.6 Richard On Fri, May 2, 2014 at 4:02 PM, Richard Vézina ml.richard.vez...@gmail.com wrote: python2.7 web2py ... On Fri, May 2, 2014 at 4:01 PM, LoveWeb2py atayloru...@gmail.comwrote: Is there a way to force web2py to use 2.7 instead of 2.6? I thought it was using 2.7. Thank you for being so patient. On Friday, May 2, 2014 3:59:06 PM UTC-4, Richard wrote: Upgrade to 2.9.5 web2py 2.3 is very old... Consider using 2.7 for python... http://stackoverflow.com/questions/1747817/python- create-a-dictionary-with-list-comprehension You can adapt Richard On Fri, May 2, 2014 at 3:44 PM, LoveWeb2py atayl...@gmail.com wrote: Okay... I think I see the issue. My web2py is running Python 2.6 and my Interpreter is 2.7. dictionary comprehension changed between those versions. I'm going to try and construct a dict comprehension for 2.6 and try it again. On Friday, May 2, 2014 3:40:53 PM UTC-4, LoveWeb2py wrote: Okay quick update: I loaded a row into python to test the comprehension. row = db(db.table.id0).select().first() {f: row[f] for f in db.table.fields} prints out the list fine and its exactly how Id like to prepopulate my field on the transition form. Thank you for getting me this far. However when I try to type vars={f: row[f] for f in db.table.fields})))] I get invalid syntax and the ^ points to the for in the dict comprehension. When I use regular python it works fine. Any thoughts? On Friday, May 2, 2014 3:16:24 PM UTC-4, LoveWeb2py wrote: I just realized I might be running into problems because I'm using 2.3. I haven't upgraded because the new web2py threw my css off. It looks like you're referencing the virtual fields? http://web2py.com/books/default/chapter/29/06/the-database- abstraction-layer#Old-style-virtual-fields If you think I should upgrade i'll make the change, but if I could stick with 2.3 I would prefer to do so On Friday, May 2, 2014 3:10:15 PM UTC-4, LoveWeb2py wrote: for this part: {f: row[f] for f in db.table.fields} what do I put for fields... could I just leave it as fields? On Friday, May 2, 2014 11:16:09 AM UTC-4, Richard wrote: Yes, so you want to pas by a transitionnal form with the data preset base on the copied record values, where you can make the change you want before submit the form. So if you have a grid where you can select the record to copy with the icon you want that link to the transitionnal form, you just have to pass the value of the record to the form throught out URL vars... You can iter like that : SQLFORM.grid(..., links=[dict(header='', body=lambda row: A(I(_class='icon some_icon'), _href=URL('transitionnal_form', vars={f: row[f] for f in db.table.fields}],) This part : {f: row[f] for f in db.table.fields} Is a dict comprehension... Then in transitionnal form controller you do something like that : def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, ...) ... Richard On Fri, May 2, 2014 at 10:18 AM, LoveWeb2py atayl...@gmail.comwrote: Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean? You can redirect (A('Link', _href=URL(controler, function, vars=dict(pass_your_record_vars_here=record_vars1, ...))) to a function that do what I wrote above... Just pass record value throught vars then request.vars.field1 request.vars.field2
Re: [web2py] Re: Create a copy record button in SQLFORM?
return **dict(form=form)? I am sorry I know my questions are noob, but I can't tell you how much I appreciate your help. I've spent two days on this problem. On Fri, May 2, 2014 at 4:11 PM, Richard Vézina ml.richard.vez...@gmail.comwrote: **dict(...) On Fri, May 2, 2014 at 4:10 PM, Austin Taylor atayloru...@gmail.comwrote: I will definitely upgrade in the upcoming months... but for now Im stuck with 2.6. Your dict comprehension worked, but now I'm getting an error when I click bthe button saying there are too many values to unpack. I'm guessing this is because I'm using 2.6 again and its something to do with my function: def transition_form(): for f, v in rqeuest.vars: db.table[f].default = v form = SQLFORM(db.table) return dict(form=form) On Fri, May 2, 2014 at 4:03 PM, Richard Vézina ml.richard.vez...@gmail.com wrote: Try with dict() contructor in one of my last email if you want to stay in 2.6 Richard On Fri, May 2, 2014 at 4:02 PM, Richard Vézina ml.richard.vez...@gmail.com wrote: python2.7 web2py ... On Fri, May 2, 2014 at 4:01 PM, LoveWeb2py atayloru...@gmail.comwrote: Is there a way to force web2py to use 2.7 instead of 2.6? I thought it was using 2.7. Thank you for being so patient. On Friday, May 2, 2014 3:59:06 PM UTC-4, Richard wrote: Upgrade to 2.9.5 web2py 2.3 is very old... Consider using 2.7 for python... http://stackoverflow.com/questions/1747817/python- create-a-dictionary-with-list-comprehension You can adapt Richard On Fri, May 2, 2014 at 3:44 PM, LoveWeb2py atayl...@gmail.comwrote: Okay... I think I see the issue. My web2py is running Python 2.6 and my Interpreter is 2.7. dictionary comprehension changed between those versions. I'm going to try and construct a dict comprehension for 2.6 and try it again. On Friday, May 2, 2014 3:40:53 PM UTC-4, LoveWeb2py wrote: Okay quick update: I loaded a row into python to test the comprehension. row = db(db.table.id0).select().first() {f: row[f] for f in db.table.fields} prints out the list fine and its exactly how Id like to prepopulate my field on the transition form. Thank you for getting me this far. However when I try to type vars={f: row[f] for f in db.table.fields})))] I get invalid syntax and the ^ points to the for in the dict comprehension. When I use regular python it works fine. Any thoughts? On Friday, May 2, 2014 3:16:24 PM UTC-4, LoveWeb2py wrote: I just realized I might be running into problems because I'm using 2.3. I haven't upgraded because the new web2py threw my css off. It looks like you're referencing the virtual fields? http://web2py.com/books/default/chapter/29/06/the-database- abstraction-layer#Old-style-virtual-fields If you think I should upgrade i'll make the change, but if I could stick with 2.3 I would prefer to do so On Friday, May 2, 2014 3:10:15 PM UTC-4, LoveWeb2py wrote: for this part: {f: row[f] for f in db.table.fields} what do I put for fields... could I just leave it as fields? On Friday, May 2, 2014 11:16:09 AM UTC-4, Richard wrote: Yes, so you want to pas by a transitionnal form with the data preset base on the copied record values, where you can make the change you want before submit the form. So if you have a grid where you can select the record to copy with the icon you want that link to the transitionnal form, you just have to pass the value of the record to the form throught out URL vars... You can iter like that : SQLFORM.grid(..., links=[dict(header='', body=lambda row: A(I(_class='icon some_icon'), _href=URL('transitionnal_form', vars={f: row[f] for f in db.table.fields}],) This part : {f: row[f] for f in db.table.fields} Is a dict comprehension... Then in transitionnal form controller you do something like that : def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, ...) ... Richard On Fri, May 2, 2014 at 10:18 AM, LoveWeb2py atayl...@gmail.comwrote: Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I just want to copy a record from the same table and insert the record as a new ID. I think the answer will be a combination of your and Oli's approach. On Friday, May 2, 2014 9:39:46 AM UTC-4, Richard wrote: What do you mean?
Re: [web2py] Re: Create a copy record button in SQLFORM?
I actually see it trying to return the values in the variables in the URL it says field1='data', field2='data2', but its hanging for some reason... On Fri, May 2, 2014 at 4:15 PM, Austin Taylor atayloru...@gmail.com wrote: return **dict(form=form)? I am sorry I know my questions are noob, but I can't tell you how much I appreciate your help. I've spent two days on this problem. On Fri, May 2, 2014 at 4:11 PM, Richard Vézina ml.richard.vez...@gmail.com wrote: **dict(...) On Fri, May 2, 2014 at 4:10 PM, Austin Taylor atayloru...@gmail.comwrote: I will definitely upgrade in the upcoming months... but for now Im stuck with 2.6. Your dict comprehension worked, but now I'm getting an error when I click bthe button saying there are too many values to unpack. I'm guessing this is because I'm using 2.6 again and its something to do with my function: def transition_form(): for f, v in rqeuest.vars: db.table[f].default = v form = SQLFORM(db.table) return dict(form=form) On Fri, May 2, 2014 at 4:03 PM, Richard Vézina ml.richard.vez...@gmail.com wrote: Try with dict() contructor in one of my last email if you want to stay in 2.6 Richard On Fri, May 2, 2014 at 4:02 PM, Richard Vézina ml.richard.vez...@gmail.com wrote: python2.7 web2py ... On Fri, May 2, 2014 at 4:01 PM, LoveWeb2py atayloru...@gmail.comwrote: Is there a way to force web2py to use 2.7 instead of 2.6? I thought it was using 2.7. Thank you for being so patient. On Friday, May 2, 2014 3:59:06 PM UTC-4, Richard wrote: Upgrade to 2.9.5 web2py 2.3 is very old... Consider using 2.7 for python... http://stackoverflow.com/questions/1747817/python- create-a-dictionary-with-list-comprehension You can adapt Richard On Fri, May 2, 2014 at 3:44 PM, LoveWeb2py atayl...@gmail.comwrote: Okay... I think I see the issue. My web2py is running Python 2.6 and my Interpreter is 2.7. dictionary comprehension changed between those versions. I'm going to try and construct a dict comprehension for 2.6 and try it again. On Friday, May 2, 2014 3:40:53 PM UTC-4, LoveWeb2py wrote: Okay quick update: I loaded a row into python to test the comprehension. row = db(db.table.id0).select().first() {f: row[f] for f in db.table.fields} prints out the list fine and its exactly how Id like to prepopulate my field on the transition form. Thank you for getting me this far. However when I try to type vars={f: row[f] for f in db.table.fields})))] I get invalid syntax and the ^ points to the for in the dict comprehension. When I use regular python it works fine. Any thoughts? On Friday, May 2, 2014 3:16:24 PM UTC-4, LoveWeb2py wrote: I just realized I might be running into problems because I'm using 2.3. I haven't upgraded because the new web2py threw my css off. It looks like you're referencing the virtual fields? http://web2py.com/books/default/chapter/29/06/the-database- abstraction-layer#Old-style-virtual-fields If you think I should upgrade i'll make the change, but if I could stick with 2.3 I would prefer to do so On Friday, May 2, 2014 3:10:15 PM UTC-4, LoveWeb2py wrote: for this part: {f: row[f] for f in db.table.fields} what do I put for fields... could I just leave it as fields? On Friday, May 2, 2014 11:16:09 AM UTC-4, Richard wrote: Yes, so you want to pas by a transitionnal form with the data preset base on the copied record values, where you can make the change you want before submit the form. So if you have a grid where you can select the record to copy with the icon you want that link to the transitionnal form, you just have to pass the value of the record to the form throught out URL vars... You can iter like that : SQLFORM.grid(..., links=[dict(header='', body=lambda row: A(I(_class='icon some_icon'), _href=URL('transitionnal_form', vars={f: row[f] for f in db.table.fields}],) This part : {f: row[f] for f in db.table.fields} Is a dict comprehension... Then in transitionnal form controller you do something like that : def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, ...) ... Richard On Fri, May 2, 2014 at 10:18 AM, LoveWeb2py atayl...@gmail.com wrote: Basically... right now I have a magnifying glass, the pencil, and a trash can for my records. I want to add a plus next to each one of my records and when I click on the plus it copies that records values into a new record and creates a new ID. I can then modify some of the values in the record or keep it the same if I choose. Does that make sense? On Friday, May 2, 2014 9:57:23 AM UTC-4, LoveWeb2py wrote: This is very helpful, Richard. I have about 20 fields so I think I would have to iterate through the fields and insert the request.vars to the database. Ahhh after looking at your code it looks like that could would write a record from one table to another. In this case I
Re: [web2py] Re: Create a copy record button in SQLFORM?
Web2py admin console has a red line at for f, v in request.vars: and then says too many values to unpack. my function is def transition_form(): for f, v in request.vars: db.table[f].default = v form = SQLFORM(db.table, user_signature=True) return dict(form=form) Should I have extra values in the dict method? -- 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.