Massimo, Thank you so much for your feedback. Most of the changes you suggested certainly made the code simpler and easier to read, but I have a couple of issues that I don't understand.
1) It appears that the line: getattr(crud,session.action)(db[tablename],record) executes the crud call, but I don't understand how getattr() does that. Could you provide a brief explanation? 2) If I directly return the dictionary that results from setsubmit (tablename), what would the format of the return be and what should the variables in the form be named? I tried a couple of combinations (widgets, inpval, dspval) , but they all failed (widget) carried extra data (impval) or failed to display an <input> on update. 3) In thefields(), the value of curform is: <form action="" enctype="multipart/form-data" method="post"><table><tr id="location_poleno__row"><td><label for="location_poleno" id="location_poleno__label">Poleno: </label></td><td>EBW 1234</ td><td></td></tr><tr id="location_town_id__row"><td><label for="location_town_id" id="location_town_id__label">Town Id: </label></ td><td>1</td><td></td></tr> ..... and curform.record is: <SQLStorage {'electricprovider': None, 'update_record': <function <lambda> at 0x9ff80d4>, 'npolesize': None, 'notifydate': datetime.datetime(2009, 3, 27, 8, 9, 43), 'id': 2, 'specialprotection': None, 'city': 'East Brunswick', 'data1': None, 'zipcode': '08816', 'cableprovider': None, 'state': 'NJ', 'town_id': 1, .... Please notice that in both places, the value of town_id is 1 and not the value in the related table. When I set mydict = dict(form=curform) is was able to fix a syntax error 'mydict does not exist' but I'm not sure that's the right thing to do. However, the real problem is an error message that says curform.custom.widget is not iterable. Even if it fixes it, I'm still not sure what the variables in the form should be named. It seems that the original code that was generated using components[0] accomplished everything except providing the current values of 'lookup' fields in display mode. When used for add or update, they worked as expected - including error messages. I assume that the custom fields are meant to provide the same functionality, but I must be using them incorrectly. You help is greatly appreciated. On Jun 9, 11:34 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > Allow me simplify it, else I do not understand it: > > def managetable(): > (tablename, id) = (request.args(0), request.args(1)) # can be > None > response.view = "%s/%s.html" % (request.controller, > tablename) > return thefields(setsubmit(tablename)) > # why not return dict(form=setsubmit(tablename)) ? > > # this I do not understand > # if session.signon[session.searchfield]: managetable = eval > # (session.signon[session.searchfield]+"(managetable)") > > def setsubmit(tablename,record=None): > if request.vars.submit1: command="create" > elif request.vars.submit2: command="read" > elif request.vars.submit3: command="update" > elif request.vars.submit4: command="delete" > return getattr(crud,command)(db[tablename],record) > > def thefields(curform): > mydict(form=curform) > for fieldname in curform.record: > if fieldname in curform.custom.widget: > mydict[fieldname] = curform.custom.widget[fieldname] > return mydict > > {{extend 'layout.html'}} > {{action = request.args(0)}} > <h1>location > {{if action == "update":}} Update > {{elif action == "create":}} Add > {{pass}} > </h1> > <form action="" enctype="multipart/form-data" method="post"> > <table> > <tr id="location_poleno__row"> > <td><label for="location_poleno" id="location_poleno__label">Poleno: > </label></td> > {{if action in ["update","create"]:}} > {{=" *** location_poleno"}} > {{else:}} > <td>{{=form.custom.widget.poleno}}</td> > {{pass}} > <td></td> > </tr> > <tr id="location_town_id__row">> <td><label for="location_town_id" > id="location_town_id__label">Town > > Id: </label></td> > {{if action in ["update","create"]:}} > {{=" *** location_town_id"}} > {{else:}} > <!-- THIS IS THE LINE THAT SHOULD RETURN A SELECTED FIELD FROM A > SELECT TAG --> > <td>{{=form.custom.widget.town_id}}</td> > {{pass}} > <td></td> > </tr> > > Does this work as expected? I do not underatnd it well enough to > debug. sorry. > > Massimo --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---