Using custom forms is the simplest way to access the fields. http://web2py.com/AlterEgo/default/show/205
-Thadeus On Tue, Oct 27, 2009 at 11:33 AM, znafets <znaf...@googlemail.com> wrote: > > Yeah, but this does not work. > The call form.accept will throw an exception KeyError: ('no_table',) > > File "/usr/lib/python2.5/threading.py", line 462, in __bootstrap > self.__bootstrap_inner() > File "/usr/lib/python2.5/threading.py", line 486, in __bootstrap_inner > self.run() > File "/usr/local/src/PYTHON/web2py/gluon/wsgiserver.py", line 1377, in > run > conn.communicate() > File "/usr/local/src/PYTHON/web2py/gluon/wsgiserver.py", line 1261, in > communicate > req.respond() > File "/usr/local/src/PYTHON/web2py/gluon/wsgiserver.py", line 673, in > respond > self._respond() > File "/usr/local/src/PYTHON/web2py/gluon/wsgiserver.py", line 679, in > _respond > response = self.wsgi_app(env, self.start_response) > File "/usr/local/src/PYTHON/web2py/gluon/main.py", line 546, in > app_with_logging > ret[0] = wsgiapp(environ, responder2) > File "/usr/local/src/PYTHON/web2py/gluon/contrib/wsgihooks.py", line > 48, in __call__ > result = self.__application(environ, start_response) > File "/usr/local/src/PYTHON/web2py/gluon/main.py", line 389, in > wsgibase > serve_controller(request, response, session) > File "/usr/local/src/PYTHON/web2py/gluon/main.py", line 160, in > serve_controller > page = run_controller_in(request.controller, request.function, > environment) > File "/usr/local/src/PYTHON/web2py/gluon/compileapp.py", line 307, in > run_controller_in > restricted(code, environment, filename) > File "/usr/local/src/PYTHON/web2py/gluon/restricted.py", line 178, in > restricted > exec ccode in environment > File "/usr/local/src/PYTHON/web2py/applications/BootBox/controllers/ > users.py", line 256, in <module> > File "/usr/local/src/PYTHON/web2py/gluon/globals.py", line 102, in > <lambda> > self._caller = lambda f: f() > File "/usr/local/src/PYTHON/web2py/applications/BootBox/controllers/ > users.py", line 52, in edit_user > if form.accepts(request.vars, session): > File "/usr/local/src/PYTHON/web2py/gluon/sqlhtml.py", line 746, in > accepts > onvalidation, > File "/usr/local/src/PYTHON/web2py/gluon/html.py", line 1245, in > accepts > status = self._traverse(status) > File "/usr/local/src/PYTHON/web2py/gluon/html.py", line 451, in > _traverse > newstatus = c._traverse(status) and newstatus > File "/usr/local/src/PYTHON/web2py/gluon/html.py", line 451, in > _traverse > newstatus = c._traverse(status) and newstatus > File "/usr/local/src/PYTHON/web2py/gluon/html.py", line 451, in > _traverse > newstatus = c._traverse(status) and newstatus > File "/usr/local/src/PYTHON/web2py/gluon/html.py", line 451, in > _traverse > newstatus = c._traverse(status) and newstatus > File "/usr/local/src/PYTHON/web2py/gluon/html.py", line 458, in > _traverse > newstatus = self._validate() > File "/usr/local/src/PYTHON/web2py/gluon/html.py", line 1054, in > _validate > (value, errors) = validator(value) > File "/usr/local/src/PYTHON/web2py/gluon/validators.py", line 380, in > __call__ > rows = self.dbset(field == value).select(limitby=(0, 1)) > File "/usr/local/src/PYTHON/web2py/gluon/sql.py", line 2239, in select > query = self._select(*fields, **attributes) > File "/usr/local/src/PYTHON/web2py/gluon/sql.py", line 2146, in > _select > fields = [self._db[table].ALL for table in self._tables] > File "/usr/local/src/PYTHON/web2py/gluon/sql.py", line 531, in > __getitem__ > return dict.__getitem__(self, str(key)) > > And what I also can't wrap my head around is how to access the data > provided for the fields now in the view. > Do I have to go through the hassle Thadeus pointed out or is there > another way to access the fields putting them on the view. > > ciao > Stefan > > On 27 Okt., 17:14, mdipierro <mdipie...@cs.depaul.edu> wrote: > > I think I understand BUT, if you have a table user and a table address > > referencing a user, it means a user can have more than one address. > > But I think you expect the form to work as if the system knows that > > one person can have only one address. This is why you have to be > > explicit: > > user = db((db.user.id == req_user_id) & > > (db.addr.user == req_user_id)).select()[0] > > > > db.user.id.default = user.user.id > > db.user.name.default = user.user.name > > db.user.email.default = user.user.email > > db.addr.city.default = user.addr.city > > > > form = SQLFORM.factory(db.user.name, > > db.user.rname,db.addr.city) > > > > if form.accepts(request.vars, session): > > > > # change the user data > > if change_user_data(user): > > user.user.update_record(name=form.vars.name) # <---- > > user.addr.update_record(city=form.vars.city) # <---- > > response.flash = 'form accepted' > > else: > > response.flash = 'form not accepted' > > redirect(URL(r=request,f='index')) > > > > On Oct 27, 7:11 am, znafets <znaf...@googlemail.com> wrote: > > > > > Massimo, > > > > > is this sufficient to understand the problem, or should I describe > > > further ? > > > > > ciao > > > Stefan > > > > > On 26 Okt., 19:57, znafets <znaf...@googlemail.com> wrote: > > > > > > Massimo, > > > > > > I am sorry, I will try to be more explicite here: > > > > > > the model (two tables user and addr) > > > > > > db.define_table('user', > > > > Field('name', length=12, requires=IS_NOT_EMPTY()), > > > > Field('alias',length=12 ), > > > > Field('rname', length=28), > > > > Field('gender', requires=IS_IN_SET(['Male', 'Female', > > > > 'Other'])), > > > > Field('email', length=12), > > > > Field('password','password'), > > > > Field('created_on','date'), > > > > Field('console','boolean',default=False), > > > > Field('verification',default=''), > > > > Field('last_attempt_time','integer',default=0), > > > > Field('failed_attempts','integer',default=0)) > > > > > > db.user.name.requires=IS_NOT_IN_DB(db,'user.name', > > > > error_message='value already > > > > in DB') > > > > db.user.password.requires=CRYPT() > > > > db.user.email.requires=[IS_EMAIL(),IS_NOT_IN_DB(db,'user.email')] > > > > db.user.public_fields=['name', 'alias','rname', 'email','password', > > > > 'reg_date','console'] > > > > db.user.public_labels={'name':'User Name', 'alias':'User Alias', > > > > 'rname':'Real Name', 'created_on':'Member > > > > since', > > > > 'console':'Console Login'} > > > > > > VALID_USER=IS_IN_DB(db(db.user.verification==''),'user.id','%(id)s:% > > > > (name)s') > > > > > > # addr table > > > > db.define_table('addr', > > > > Field('user', db.user), > > > > Field('zip'), > > > > Field('city'), > > > > Field('street'), > > > > Field('number'), > > > > Field('country'), > > > > Field('phone_short'), > > > > Field('phone_office'), > > > > Field('phone_home'), > > > > Field('phone_mobile'), > > > > Field('fax'), > > > > Field('birth', 'date'), > > > > Field('notes','text')) > > > > > > from these two tables I get the record data in the controller > function > > > > like this: > > > > > > def edit_user(): > > > > if len(request.args): > > > > > > req_user_id = request.args[0] > > > > > > # if current user is not a member of system manager group > > > > # he cannot edit any records except his own > > > > if not is_member("Systems") and session.user_id != int > > > > (req_user_id): > > > > session.flash = 'sorry, no sufficient access rights' > > > > redirect(URL(r=request,f='index')) > > > > > > user = db((db.user.id == req_user_id) & > > > > (db.addr.user == > req_user_id)).select()[0] > > > > > > db.user.id.default = user.user.id > > > > db.user.name.default = user.user.name > > > > db.user.email.default = user.user.email > > > > db.addr.city.default = user.addr.city > > > > > > form = SQLFORM.factory(db.user.name, db.user.rname, > > > > db.addr.city) > > > > > > ### > > > > ### this call doesn't work due to no_table issue > > > > ### > > > > if form.accepts(request.vars, session): > > > > > > # change the user data > > > > if change_user_data(user): > > > > response.flash = 'form accepted' > > > > else: > > > > response.flash = 'form not accepted' > > > > redirect(URL(r=request,f='index')) > > > > > > elif form.errors: > > > > response.flash = 'form has errors' > > > > > > return dict(form=form) > > > > > > what I would like to do now is to place the fields in the view where > I > > > > think it males most sense like: > > > > name zip city > > > > rname street number > > > > etc. > > > > > > submit > > > > > > after submit the records in both tables should be updated, means when > > > > I changed the street the record in addr table gets updated, some > field > > > > from user table and this one gets updated. It's okay updating all > > > > records of both tables when submit button getts pressed. > > > > > > I do not have preferences for either SQLFORM or FORM or > > > > SQLFORM.factory. What ever is easier and less hard to read. > > > > I am also fine with doing plain old HTML manually in the view as long > > > > as I can access the field values and place the fields where ever I > > > > want them and as long as I can get that information change back to > the > > > > controller that is supposed to update my records. > > > > > > Thanks for getting into it with me. > > > > > > ciao > > > > Stefan > > > > > > On 26 Okt., 19:38, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > > > > Stephan, > > > > > > > I think I am not completely understanding what you need. can you > make > > > > > a concrete example of a model, how the model should look like (use > a > > > > > drawing or text) and what should happen when the form is submitted? > > > > > > > Massimo > > > > > > > On Oct 26, 1:33 pm, znafets <znaf...@googlemail.com> wrote: > > > > > > > > @weheh: I saw that but couldn't take too much from it > > > > > > @Thadeus: Woooa, that looks like for a second generation BF > compiler - > > > > > > I am blinded :) , thank you anyway > > > > > > @Massimo: I knew you would like that highly sophisticated stuff > but > > > > > > please don't ask me if it helps to solve my problem, or better > put: is > > > > > > this the only solution to that use case I described ? Then I > guess > > > > > > this is way out of my league and incomprehensible for my old > eyes. > > > > > > > > I adored web2py so far for being easy to use and elegant, but in > this > > > > > > specific case I am willing to rethink that impression in a way > that it > > > > > > may be easy as long as one stays on well flattened roads leading > to > > > > > > standard views with minimum customization. Once you are passed > that it > > > > > > seems to get really hairy. > > > > > > > > to recap: > > > > > > getting data from two tables displayed in a view with fields that > are > > > > > > supposed to appear where I want them, pre-filled with the data > that is > > > > > > already in the db is this the only way to do it in web2py ? > > > > > > seriously ? No easier, better, smoother way ? > > > > > > > > ciao > > > > > > Stefan > > > > > > > > On 26 Okt., 18:00, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > > > > > > An aesthetic issue. Consider you can replace: > > > > > > > > > {{ > > > > > > > def req(): > > > > > > > return XML('''<span class="required">*</span>''') > > > > > > > > > }} > > > > > > > > > with > > > > > > > > > {{req=SPAN("*",_class="required")}} > > > > > > > > > and call it with {{=req}} or > > > > > > > > > {{def req():}}<span class="required">*</span>{{return}} > > > > > > > > > and call it with {{req()}} (no equal) > > > > > > > > > Massimo > > > > > > > > > On Oct 26, 11:51 am, Thadeus Burgess <thade...@thadeusb.com> > wrote: > > > > > > > > > > This is usually what I end up doing for custom form. It > allows for fully > > > > > > > > customizable XHTML/CSS 3 forms. > > > > > > > > > > {{ > > > > > > > > def req(): > > > > > > > > return XML('''<span class="required">*</span>''')}} > > > > > > > > > > {{pass}} > > > > > > > > > > {{def labels(field, required):}} > > > > > > > > <label for="{{=field}}" > id="{{=field}}__label" > > > > > > > > class="title">{{=form.custom.label[field]}}{{if > > > > > > > > required:}}{{=req()}}{{pass}}</label> > > > > > > > > <label for="{{=field}}" > id="{{=field}}__comment" > > > > > > > > class="comment">{{=form.custom.comment[field]}}</label> > > > > > > > > <label for="{{=field}}" > id="{{=field}}__error" > > > > > > > > class="error">{{if > > > > > > > > > form.errors.has_key(field):}}{{=form.errors[field]}}{{pass}}</label> > > > > > > > > {{pass}} > > > > > > > > > > {{def li(field, required=True):}} > > > > > > > > <li {{if > form.errors.has_key(field):}}class="err"{{pass}}> > > > > > > > > <div class="labels"> > > > > > > > > {{labels(field, required)}} > > > > > > > > </div> > > > > > > > > {{=form.custom.widget[field]}} > > > > > > > > </li> > > > > > > > > {{pass}} > > > > > > > > > > {{=form.custom.begin}} > > > > > > > > > > <fieldset> > > > > > > > > <legend></legend> > > > > > > > > <ol> > > > > > > > > {{li('signup_code')}} > > > > > > > > </ol> > > > > ... > > > > Erfahren Sie mehr ยป > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" 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 -~----------~----~----~----~------~----~------~--~---