I will definitely upgrade in the upcoming months... but for now I"m 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.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.id>0).select().first() >>>>>> >>>>>> {f: row[f] for f in db.table.fields} prints out the list fine and its >>>>>> exactly how I"d 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.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+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: > - 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 a topic in the > Google Groups "web2py-users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/web2py/U2ajc9LzVCk/unsubscribe. > To unsubscribe from this group and all its topics, 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.