Massimo, This is kind of complicated. It's part of a generalized application that uses a database to to define which tables can be accessed through CRUD. The database contains the table name, some search criteria and decorators. The controllers look more like web2py source than a "normal" controller. Here are the three main routines with a quick explanation:
""""managetable() is called with a tablename, assures an action, selects a response view, calls setsubmit() to write the requested crud call and returns the dictionary value built in thefields(). """" def managetable(): if request.args: tablename = request.args[0] id = request.args[1] if request.args[1] == "0": session.action="create" response.view = "%s/%s.html" % (request.controller, tablename) form = eval(setsubmit(tablename)) return thefields(form) if session.signon[session.searchfield]: managetable = eval (session.signon[session.searchfield]+"(managetable)") """setsubmit() returns the crud command based on the session variable. """ def setsubmit(table): if request.vars.submit1: session.action = "create" if request.vars.submit2: session.action = "update" if request.vars.submit3: session.action = "read" if request.vars.submit4: session.action = "delete" cmd = "crud."+session.action+"(db."+table if session.action in ['read','update','delete']: cmd += ",id)" else: cmd += ")" return cmd """ thefields() takes the components[0], extracts the fieldnames and builds the crud dictionary to return.""" def thefields(curform): mycomponents = curform.components[0] mydict = dict(form=curform) for mycount in range(len(mycomponents)): mylabel = str(mycomponents[mycount][0]) mylabel = mylabel[mylabel.find('="')+2:mylabel.find('" ')] mydict[mylabel]=mycomponents[mycount][1] return mydict =================== Here is an abbreviated Model: db.define_table('menu', db.Field('linkname','string',default='link_name'), db.Field('linkactive','string',default='False'), db.Field('linkcontroller','string',default='index'), db.Field('tablefield','string',default='tablename.fieldname'), db.Field('linkcondition','string',length=64,default='True'), db.Field ('tabledecorator','string',length=64,default='auth.requires_login()'), db.Field('tablematch','string',length=64,default='id')) db.define_table('town', db.Field('townname','string'), db.Field('towncode','string')) ## db.define_table('location', db.Field('poleno','string'), db.Field('town_id',db.town)) ## db.town.townname.requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB (db,'town.townname')] db.town.towncode.requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB (db,'town.towncode')] db.location.poleno.requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB (db,'location.poleno')] db.location.town_id.requires=IS_IN_DB(db,db.town.id ,'%(townname)s') =================== Here is a portion of a custom view using the generated fields: {{extend 'layout.html'}} <h1>location {{if session.action == "update":}} Update {{elif session.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 session.action in ["update","create"]:}} {{=location_poleno}} {{else:}} <td>{{=form.custom.inpval.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 session.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> ............. See the forth line from the bottom. (Caps for emphasis, not yelling). Two lines above that, {{=location_town_id}} produces a dropdown <select> field that works perfectly in crud, including errors. For reference, this all started in thread: http://groups.google.com/group/web2py/browse_thread/thread/5ff39195cb22d810/46792d84246385dd?q=crud+validation&lnk=ol& I'm including this reference just in case it help to have the background. I'd be glad to send you the entire application if that helps. Just let me know. Much thanks! On Jun 9, 6:47 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > Gary, > I need more explanation. One example or screenshot would help. > > Massimo > > On Jun 9, 4:31 pm, Gary <gary.k.ma...@gmail.com> wrote: > > > Hans, > > > The model is kind of long, but SQLFORM (I don't know how to only show > > fields using SQLFORMS), as well as the Custom Update CRUD, works > > fine. It's only the Read CRUD that is giving me a problem. In other > > words, the input tag works fine but the field display is showing the > > 'id' value rather than the 'lookup' value. > > > Is this helpful or do you need more? > > > Thanks. > > > On Jun 9, 3:51 pm, Hans Donner <hans.don...@pobox.com> wrote: > > > > Gary, > > > how dows your model look like? > > > And how does it show when you are just using SQLFORM? > > > > On Tue, Jun 9, 2009 at 9:40 PM, Gary<gary.k.ma...@gmail.com> wrote: > > > > > Thank you Fran and Massimo for the info. > > > > > I downloaded the trunk using: > > > > > bzr branch lp:~mdipierro/web2py/devel web2py-devel > > > > > and installed the application. The error message went away, but > > > > {{=form.custom.widget.town_id}} still displayed '1' vs. the 'lookup' > > > > value. It also didn't display a checkbox where indicated. > > > > > Appreciate the help. > > > > > On Jun 9, 2:24 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > >> By trunk we mean "not officially released yet" and "not guaranteed to > > > >> work". > > > > >> Massimo > > > > >> On Jun 9, 12:41 pm, Gary <gary.k.ma...@gmail.com> wrote: > > > > >> > I tried {{=form.custom.widget.town_id}} in 1.63.5 and got an error > > > >> > "AttributeError: 'NoneType' object has no attribute 'town_id'". > > > >> > Using {{=form.custom.inpval.town_id}} returns a '1', the value of the > > > >> > id in the 'Location' file pointing to the 'Town' file. > > > > >> > For clarification, does 'new trunk' mean something other than the > > > >> > current release? > > > > >> > Thanks. > > > > >> > On Jun 9, 12:38 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > >> > > with the new trunk you can do > > > > >> > > {{=form.custom.widget.fieldname}} > > > > >> > > On Jun 9, 11:06 am, Gary <gary.k.ma...@gmail.com> wrote: > > > > >> > > > I'm using crud to interact with a custom view. > > > >> > > > form.custom.inpval.fieldname and form.custom.dspval.fieldname > > > >> > > > display > > > >> > > > the proper value for most field types, but not files, select > > > >> > > > boxes and > > > >> > > > checkboxes. The download easily fixes the file display, but > > > >> > > > I've been > > > >> > > > unable to find a similar solution to displaying the 'lookup' > > > >> > > > value of > > > >> > > > the select rather than the 'id' of the target? Ditto for the > > > >> > > > checkbox > > > >> > > > rather that 'True/False'. > > > > >> > > > Thanks in advance for any help. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---