[web2py] Re: New record creates on Select?

2014-01-25 Thread Anthony
SQLFORM is designed for inserting records into the database, so this is not 
a bug. By default, SQLFORM.process() does an insert. To avoid that, you 
could do SQLFORM.process(..., dbio=False), or just do SQLFORM.validate() 
instead (.validate doesn't do an insert by default).

Anthony

On Saturday, January 25, 2014 5:57:58 PM UTC-5, Luciano Laporta Podazza 
wrote:

 Hello,

 I created a form(SQLFORM) to perform a search(without using crud.search) 
 and for some reason, every time I do a search, a new record is created with 
 default values. I really don't know if I'm doing something wrong or is it a 
 bug.
 Tested with Web2py 2.8.2 on Mac OS X 10.9.1 and MySQL 5. All data created 
 from scratch.

 Here is the *db.py*:

 from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
 auth = Auth(db)
 crud, service, plugins = Crud(db), Service(), PluginManager()




 auth.settings.extra_fields['auth_user']= [ 
 Field('facebook_id', 'string'),
 Field('calle', 'string'),
 Field('numero', 'integer'),
 Field('ciudad', 'string'),
 Field('provincia', 'string'),
 Field('pais', 'string'),
 Field('telefono', 'string'),
 Field('celular', 'string'),
 Field('first_time', 'boolean', default=1),
 Field('asociacion', 'boolean', default=1),
 Field('nombre_asociacion', 'string'),
 Field('email_asociacion', 'string'),
 Field('telefono_asociacion', 'string'),
 ]




 ## create all tables needed by auth if not custom tables
 auth.define_tables(username=False, signature=False)

 db.define_table('especies',
 Field('nombre_especie', 'string', requires=IS_IN_SET(['Canino',
 'Felino'], zero=None)),
 Field('nombre_raza', 'string'),
 )

 db.define_table('mascotas',
 Field('mascotas_id', db.auth_user),
 Field('foto_mascota', 'upload'),
 Field('nombre', 'string'),
 Field('especie', 'string', requires=IS_IN_SET(['Canino','Felino'],zero
 =None)),
 Field('raza_canino', db.especies, label=Raza),
 Field('raza_felino', db.especies, label=Raza),
 Field('color', 'string'),
 Field('nacimiento', 'date'),
 Field('genero', 'string', requires=IS_IN_SET(['Macho','Hembra'] , zero
 =None)),
 Field('cruza', 'boolean', default=0),
 Field('adopcion', 'boolean', default=0),
 Field('pedigree', 'boolean', default=0),
 )
 db.mascotas.raza_canino.requires = IS_EMPTY_OR(IS_IN_DB(db(db.especies.
 nombre_especie=='Canino'), db.especies.id,'%(nombre_raza)s', zero='Elegir 
 raza'))
 db.mascotas.raza_felino.requires = IS_EMPTY_OR(IS_IN_DB(db(db.especies.
 nombre_especie=='Felino'), db.especies.id,'%(nombre_raza)s', zero='Elegir 
 raza'))


 Table *especies *is where I add some pet species(cats or dogs) and their 
 races.

 Here is the search on *controller.py*:

 def search():
 search = SQLFORM(db.mascotas,
 fields=[
 'especie',
 'raza_canino',
 'raza_felino',
 'genero'])
 if search.process().accepted:
 query = db((db.auth_user.id==db.mascotas.mascotas_id)
 (db.mascotas.especie==search.vars.especie)
 ((db.mascotas.raza_canino==search.vars.raza_canino)|
 (db.mascotas.raza_felino==search.vars.raza_felino))
 (db.mascotas.genero==search.vars.genero)).select(db.mascotas.
 nombre,
 db.mascotas.nacimiento,
 db.auth_user.id,db.mascotas.id)
 return dict(query=query,search=search)
 elif search.errors:
 response.flash = 'form has errors' 
 else:
 response.flash = 'please fill out the form'
 query=''
 return dict(search=search,query=query)

 Thanks for you help.


-- 
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/groups/opt_out.


[web2py] Re: New record creates on Select?

2014-01-25 Thread Luciano Laporta Podazza
Oh guys, I'm terribly ashamed, sorry for such a lame post from me.

Thanks for your time and consideration. As always, you rock guys :)

Cheers!

On Saturday, January 25, 2014 8:35:33 PM UTC-3, Anthony wrote:

 SQLFORM is designed for inserting records into the database, so this is 
 not a bug. By default, SQLFORM.process() does an insert. To avoid that, you 
 could do SQLFORM.process(..., dbio=False), or just do SQLFORM.validate() 
 instead (.validate doesn't do an insert by default).

 Anthony

 On Saturday, January 25, 2014 5:57:58 PM UTC-5, Luciano Laporta Podazza 
 wrote:

 Hello,

 I created a form(SQLFORM) to perform a search(without using crud.search) 
 and for some reason, every time I do a search, a new record is created with 
 default values. I really don't know if I'm doing something wrong or is it a 
 bug.
 Tested with Web2py 2.8.2 on Mac OS X 10.9.1 and MySQL 5. All data created 
 from scratch.

 Here is the *db.py*:

 from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
 auth = Auth(db)
 crud, service, plugins = Crud(db), Service(), PluginManager()




 auth.settings.extra_fields['auth_user']= [ 
 Field('facebook_id', 'string'),
 Field('calle', 'string'),
 Field('numero', 'integer'),
 Field('ciudad', 'string'),
 Field('provincia', 'string'),
 Field('pais', 'string'),
 Field('telefono', 'string'),
 Field('celular', 'string'),
 Field('first_time', 'boolean', default=1),
 Field('asociacion', 'boolean', default=1),
 Field('nombre_asociacion', 'string'),
 Field('email_asociacion', 'string'),
 Field('telefono_asociacion', 'string'),
 ]




 ## create all tables needed by auth if not custom tables
 auth.define_tables(username=False, signature=False)

 db.define_table('especies',
 Field('nombre_especie', 'string', requires=IS_IN_SET(['Canino',
 'Felino'], zero=None)),
 Field('nombre_raza', 'string'),
 )

 db.define_table('mascotas',
 Field('mascotas_id', db.auth_user),
 Field('foto_mascota', 'upload'),
 Field('nombre', 'string'),
 Field('especie', 'string', requires=IS_IN_SET(['Canino','Felino'],zero
 =None)),
 Field('raza_canino', db.especies, label=Raza),
 Field('raza_felino', db.especies, label=Raza),
 Field('color', 'string'),
 Field('nacimiento', 'date'),
 Field('genero', 'string', requires=IS_IN_SET(['Macho','Hembra'] ,zero
 =None)),
 Field('cruza', 'boolean', default=0),
 Field('adopcion', 'boolean', default=0),
 Field('pedigree', 'boolean', default=0),
 )
 db.mascotas.raza_canino.requires = IS_EMPTY_OR(IS_IN_DB(db(db.especies.
 nombre_especie=='Canino'), db.especies.id,'%(nombre_raza)s', zero='Elegir 
 raza'))
 db.mascotas.raza_felino.requires = IS_EMPTY_OR(IS_IN_DB(db(db.especies.
 nombre_especie=='Felino'), db.especies.id,'%(nombre_raza)s', zero='Elegir 
 raza'))


 Table *especies *is where I add some pet species(cats or dogs) and their 
 races.

 Here is the search on *controller.py*:

 def search():
 search = SQLFORM(db.mascotas,
 fields=[
 'especie',
 'raza_canino',
 'raza_felino',
 'genero'])
 if search.process().accepted:
 query = db((db.auth_user.id==db.mascotas.mascotas_id)
 (db.mascotas.especie==search.vars.especie)
 ((db.mascotas.raza_canino==search.vars.raza_canino)|
 (db.mascotas.raza_felino==search.vars.raza_felino))
 (db.mascotas.genero==search.vars.genero)).select(db.mascotas.
 nombre,
 db.mascotas.nacimiento,
 db.auth_user.id,db.mascotas.id)
 return dict(query=query,search=search)
 elif search.errors:
 response.flash = 'form has errors' 
 else:
 response.flash = 'please fill out the form'
 query=''
 return dict(search=search,query=query)

 Thanks for you help.



-- 
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/groups/opt_out.