Perfect!! Thanks!

On Tue, Sep 7, 2010 at 7:26 PM, mdipierro <[email protected]> wrote:

> I apologize for the late reply:
>
>  form.vars.id = db.user_jogo.insert(**dict(form.vars))
>
> should have been:
>
>  form.vars.id =
> db.user_jogo.insert(**db.user_jogo._filter_fields(form.vars))
>
> The _filter_fields will remove from the form.vars those fields that do
> not belong there (for example hidden fields used by autocomplete).
>
>
> On Sep 1, 9:56 am, Tito Garrido <[email protected]> wrote:
> > nobody?
> >
> > On Mon, Aug 30, 2010 at 12:02 AM, Tito Garrido <[email protected]
> >wrote:
> >
> >
> >
> > > Hi Folks,
> >
> > > I'm trying to validade a form before sending it. There is a hidden
> field
> > > and an autocomplete field on the form and there is what I get:
> >
> > >     % repr(invalid_fieldnames)
> > > SyntaxError: invalid field names: ['_autocomplete_nome_aux']
> >
> > > *Function argument list: (self=<Table {'ALL': <gluon.sql.SQLALL object
> at
> > > 0x102..., 'id': <gluon.sql.Field object at 0x10245de90>}>,
> > > **fields={'_autocomplete_nome_aux': 'God Of War III', 'jogo': '2',
> 'user':
> > > 1})*
> >
> > > 1976.
> > > 1977.
> > > 1978.
> > > 1979.
> > > 1980.
> > > 1981.
> >
> > > 1982.
> > > 1983.
> > > 1984.
> > > 1985.
> >
> > >     def _insert(self, **fields):
> >
> > >         (fs, vs) = ([], [])
> > >         invalid_fieldnames = [key for key in fields if not key in
> self.fields]
> >
> > >         if invalid_fieldnames:
> > >             raise SyntaxError, 'invalid field names: %s' \
> >
> > >                 % repr(invalid_fieldnames)
> >
> > >         for fieldname in self.fields:
> >
> > >             if fieldname == 'id':
> >
> > >                 continue
> > >             field = self[fieldname]
> >
> > >    - invalid_fieldnames: ['_autocomplete_nome_aux']
> > >    - builtinrepr: <built-in function repr>
> >
> > > *This is the CONTROLLER:*
> >
> > > @auth.requires_login()
> > > def meus_jogos():
> >
> > >     form=SQLFORM <http://127.0.0.1:8000/examples/global/vars/SQLFORM
> >(db.user_jogo,fields=['jogo'],submit_button='Adicionar')
> >
> > >     row_jogos=db(db.user_jogo.user==auth.user.id).select()
> >
> > >     jogos_cadastrados=[]
> > >     for jogo in row_jogos:
> >
> > >         jogos_cadastrados.append(jogo.jogo.id)
> >
> > >     form.vars.user=auth.user.id
> >
> > >     if form.accepts(request <
> http://127.0.0.1:8000/examples/global/vars/request>.vars, session <
> http://127.0.0.1:8000/examples/global/vars/session>,dbio=False):
> >
> > >         if int(form.vars.jogo) not in jogos_cadastrados:
> >
> > >             form.vars.id = db.user_jogo.insert(**dict(form.vars))
> >
> > >             response <
> http://127.0.0.1:8000/examples/global/vars/response>.flash = 'Jogo
> Adicionado'
> >
> > >         else:
> > >             response <
> http://127.0.0.1:8000/examples/global/vars/response>.flash = 'Você já tem
> esse jogo cadastrado'
> >
> > >     elif form.errors:
> > >         response 
> > > <http://127.0.0.1:8000/examples/global/vars/response>.flash
> = 'Existem erros no formulário'
> >
> > >     return dict(row_jogos=row_jogos,form=form)
> >
> > > Am I missing something or is it a bug?
> >
> > > Regards,
> >
> > > Tito
> >
> > > --
> >
> > > Linux User #387870
> > > .........____
> > > .... _/_õ|__|
> > > ..º[ .-.___.-._| . . . .
> > > .__( o)__( o).:_______
> >
> > --
> >
> > Linux User #387870
> > .........____
> > .... _/_õ|__|
> > ..º[ .-.___.-._| . . . .
> > .__( o)__( o).:_______
>



-- 

Linux User #387870
.........____
.... _/_õ|__|
..º[ .-.___.-._| . . . .
.__( o)__( o).:_______

Reply via email to