[web2py] Re: form fields
I'm saying thank you Anthony another time...you find every time the right way...my compliments. Tell me...in your opinion what is the best python guide/tutorial (for free or cheap money) to use? What do you suggest? Have a good day. Thank you! Il giorno giovedì 31 maggio 2018 23:32:51 UTC+2, Anthony ha scritto: > On Thursday, May 31, 2018 at 2:27:44 PM UTC-4, Andrea Fae' wrote: >> >> thanks Anthony. Could you give me simple example about second idea? It's >> noy possible to pass variables to a onvalidation funtion? i.e. onvalidation >> doesn't accept parameters...the problem is: how to make that object >> available to the onvalidation function? >> > > record = db.mytable(1) > > def my_validation(form): > [now access record, which has been defined in the parent scope] > > form =SQLFORM(...).process(onvalidation=my_validation) > > or: > > record = db.mytable(1) > > def my_validation(form, record): > ... > > form = SQLFORM(...).process(onvalidation=lambda form: my_validation( > form, record)) > > Anthony > -- 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/d/optout.
[web2py] Re: form fields
On Thursday, May 31, 2018 at 2:27:44 PM UTC-4, Andrea Fae' wrote: > > thanks Anthony. Could you give me simple example about second idea? It's > noy possible to pass variables to a onvalidation funtion? i.e. onvalidation > doesn't accept parameters...the problem is: how to make that object > available to the onvalidation function? > record = db.mytable(1) def my_validation(form): [now access record, which has been defined in the parent scope] form =SQLFORM(...).process(onvalidation=my_validation) or: record = db.mytable(1) def my_validation(form, record): ... form = SQLFORM(...).process(onvalidation=lambda form: my_validation(form , record)) Anthony -- 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/d/optout.
[web2py] Re: form fields
thanks Anthony. Could you give me simple example about second idea? It's noy possible to pass variables to a onvalidation funtion? i.e. onvalidation doesn't accept parameters... Il giorno giovedì 31 maggio 2018 00:24:29 UTC+2, Anthony ha scritto: > > SQLFORM shows the values of non-writable fields but does not put those > values into HTML form widgets, so they are not submitted with the form. A > couple of options: > >- Instead of setting writable=False, specify a custom widget for the >fields with the HTML readonly attribute set to true (e.g., widget=lambda >f, v: SQLFORM.widgets.string.widget(f, v, _readonly=True)). With this >approach, be sure to validate the non-writable values as well, as a >malicious user can still submit modified values. >- Create a separate object (e.g., a DAL Row) containing the >non-writable field values, and make that object available within the >onvalidation function (since those values are not changeable within the >form, there is no reason the values must come from the form submission). > > Anthony > > On Wednesday, May 30, 2018 at 4:28:01 PM UTC-4, Andrea Fae' wrote: >> >> Hello I have a SQLFORM but some of them I populate from other variables >> and I don't want to change. So I typed field.writable=False... >> But when I use a custom "onvalidation" function I want to have the >> content of all the form fields... >> In request.vars I see some fields but not all >> In form.vars I see part of these fields >> Both without the not writable fields. >> >> How is working? request.vars, form.vars. Why do they show different field >> values? Why I can't see the not wirtable values? I tried to read the book, >> but I didn't find the information yet. >> Thanks a lot >> > -- 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/d/optout.
[web2py] Re: form fields
SQLFORM shows the values of non-writable fields but does not put those values into HTML form widgets, so they are not submitted with the form. A couple of options: - Instead of setting writable=False, specify a custom widget for the fields with the HTML readonly attribute set to true (e.g., widget=lambda f, v: SQLFORM.widgets.string.widget(f, v, _readonly=True)). With this approach, be sure to validate the non-writable values as well, as a malicious user can still submit modified values. - Create a separate object (e.g., a DAL Row) containing the non-writable field values, and make that object available within the onvalidation function (since those values are not changeable within the form, there is no reason the values must come from the form submission). Anthony On Wednesday, May 30, 2018 at 4:28:01 PM UTC-4, Andrea Fae' wrote: > > Hello I have a SQLFORM but some of them I populate from other variables > and I don't want to change. So I typed field.writable=False... > But when I use a custom "onvalidation" function I want to have the content > of all the form fields... > In request.vars I see some fields but not all > In form.vars I see part of these fields > Both without the not writable fields. > > How is working? request.vars, form.vars. Why do they show different field > values? Why I can't see the not wirtable values? I tried to read the book, > but I didn't find the information yet. > Thanks a lot > -- 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/d/optout.
[web2py] Re: Form fields in DB showing a 0 value
Niphold, thanks for that info, but this is what I have; db.define_table( 'order_bus', Field('depart_from'), Field('arrive_to'), Field('date', 'date'), Field('time', db.depature_times), # drop-down select time options Field('no_of_passengers', db.tickets), # drop-down options to select number of positions Field('posted_on', 'datetime', readable=False, writable=False), Field('posted_by', readable=False, writable=False)) db.order_bus.depart_from.widget = SQLFORM.widgets.autocomplete(request, db. route.city, id_field=db.route.id, limitby=(0,10), min_length=2) db.order_bus.arrive_to.widget = SQLFORM.widgets.autocomplete(request, db. route.city, id_field=db.route.id, limitby=(0,10), min_length=2) I like to point out that something very strange happens; When I select the depart_from and arrive_to fields, the auto complete options appear, and then I can choose a city. When the form is submitted, the route.id for the arrive_to field that was selected on the form, appears in the depart_from column in the order_bus db table. In addition to that, the arrive_to db table table shows 0. So I am not sure as what is really going on. On Sunday, November 10, 2013 6:02:23 PM UTC-5, Niphlod wrote: after two days of bashing your head to the wall, why don't you read the docs about the autocomplete widget ? You need to pass the id_field argument http://web2py.com/books/default/chapter/29/07/forms-and-validators?search=autocomplete#Autocomplete-widget On Sunday, November 10, 2013 9:56:46 PM UTC+1, raferbop wrote: When I remove the auto complete widget, the data saves in the database is it should. -- 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: Form fields in DB showing a 0 value
When I remove the auto complete widget, the data saves in the database is it should. On Saturday, November 9, 2013 7:34:39 PM UTC-5, 黄祥 wrote: oopss, sorry didn't notice that you are using SQLFORM.widgets.autocomplete, yes, it should. basically the reference type of field is refer to primary key of the table which is 'id' field, please use it as reference base and then please use record representation (format) to show it in html form field. if you want to narrow down, please comment the autocoomplete widgets first or if you are in development or testing environment please try to remove the database first, sometime the migrations is not affected in database table. p.s. : date field name in your order_bus table is a SQL/NOSQL keyword. best regards, stifan -- 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: Form fields in DB showing a 0 value
after two days of bashing your head to the wall, why don't you read the docs about the autocomplete widget ? You need to pass the id_field argument http://web2py.com/books/default/chapter/29/07/forms-and-validators?search=autocomplete#Autocomplete-widget On Sunday, November 10, 2013 9:56:46 PM UTC+1, raferbop wrote: When I remove the auto complete widget, the data saves in the database is it should. -- 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: Form fields in DB showing a 0 value
please use format as record representation or set it on IS_IN_DB form validation. e.g. if you want to show city as a drop down menu in order_bus form : db.define_table( 'route', Field('city'), Field('country_iso'), format = '%(city)s') db.order_bus.depart_from.requires = IS_IN_DB(db, 'route.id', '%(city)s', zero = T('choose one')) db.order_bus.arrive_to.requires = IS_IN_DB(db, 'route.id', '%(city)s', zero = T('choose one')) ref: http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Record-representation http://web2py.com/books/default/chapter/29/07/forms-and-validators#Database-validators best regards, stifan -- 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: Form fields in DB showing a 0 value
Stifan,Winvalid literal for long() with base 10: 'Montego Bay' On Saturday, November 9, 2013 4:03:15 PM UTC-5, 黄祥 wrote: please use format as record representation or set it on IS_IN_DB form validation. e.g. if you want to show city as a drop down menu in order_bus form : db.define_table( 'route', Field('city'), Field('country_iso'), format = '%(city)s') db.order_bus.depart_from.requires = IS_IN_DB(db, 'route.id', '%(city)s', zero = T('choose one')) db.order_bus.arrive_to.requires = IS_IN_DB(db, 'route.id', '%(city)s', zero = T('choose one')) ref: http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Record-representation http://web2py.com/books/default/chapter/29/07/forms-and-validators#Database-validators best regards, stifan -- 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: Form fields in DB showing a 0 value
oopss, sorry didn't notice that you are using SQLFORM.widgets.autocomplete, yes, it should. basically the reference type of field is refer to primary key of the table which is 'id' field, please use it as reference base and then please use record representation (format) to show it in html form field. if you want to narrow down, please comment the autocoomplete widgets first or if you are in development or testing environment please try to remove the database first, sometime the migrations is not affected in database table. p.s. : date field name in your order_bus table is a SQL/NOSQL keyword. best regards, stifan -- 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.