Re: Form and insertion.

64 views
Skip to first unread message
Message has been deleted

Dave S

unread,
Jun 10, 2019, 5:23:33 PM6/10/19
to web...@googlegroups.com


On Monday, June 10, 2019 at 1:04:41 PM UTC-7, Quang Lam wrote:
i have this table as follows:
db.define_table([elided])
 
to writable = false to prevent user inputting the data in this field because it will call another script to get the the data for mode attribute

i will have the form to ask the user to input info into these fields except mode field because i will call another script to get the data of the mode from the other table and input the mode data along with the input data from user. my question is where should i call the script to get the mode data? ( is it the in the form.process().accepted block. ?). how can i insert the mode data at the same time when the user click submit to insert the inputs into the table ?

Please help, Thanks

黄祥

unread,
Jun 10, 2019, 5:52:05 PM6/10/19
to web2py-users
another way around perhaps can use onvalidation to insert the mode data at the same time when the user click submit 
ref:

best regards,
stifan
Message has been deleted

Dave S

unread,
Jun 10, 2019, 6:35:27 PM6/10/19
to web...@googlegroups.com


On Monday, June 10, 2019 at 3:15:11 PM UTC-7, Quang Lam wrote:
Hi Dave, could you please elaborate more since the book doesn't explain my situation well. 
Thanks 

Hmmm, does that "other script" run server-side or client-side?  I forgot about that question.

/dps


 

Quang Lam

unread,
Jun 10, 2019, 6:38:09 PM6/10/19
to web2py-users
Hi, but the things is i set the mode field to writable false, do you think i am still able to access the mode by form.vars.mode?

Dave S

unread,
Jun 10, 2019, 6:54:33 PM6/10/19
to web2py-users


On Monday, June 10, 2019 at 3:38:09 PM UTC-7, Quang Lam wrote:
Hi, but the things is i set the mode field to writable false, do you think i am still able to access the mode by form.vars.mode?

If "the other script" runs server-side, it doesn't matter (but you won't be able to update the field in the record until you make it temporarily writable).

But your question suggests you are running the script client-side.  IIRC (caveat: I'm not Anthony), the field won't even be part of the form when you use the built-in helpers ( FORM, SQLFORM, etc)., and the accept process won't do anything with it.  If may not show up as a form.vars value at all, but it may be in the request.post.vars ... I'm not going to check that at the moment.

If you make the field readable = False and writable = True, the field won't be displayed by the form, but there will be a place in form.vars for it, and the accept process will validate it.

/dps


Quang Lam

unread,
Jun 10, 2019, 6:56:08 PM6/10/19
to web2py-users
Hi Dave, the script is run from modules folder. i planned to use the function 'onvalidation' in the form.process ().accepted but i am wondering if i can access the mode field by using form.vars.mode since i set the mode field to writable false in the table to prevent the user input for the mode field. 

Thanks 

On Monday, June 10, 2019 at 3:35:27 PM UTC-7, Dave S wrote:


On Monday, June 10, 2019 at 3:15:11 PM UTC-7, Quang Lam wrote:
Hi Dave, could you please elaborate more since the book doesn't explain my situation well. 
Thanks 

Hmmm, does that "other script" run server-side or client-side?  I forgot about that question.

/dps


 

On Monday, June 10, 2019 at 2:23:33 PM UTC-7, Dave S wrote:


On Monday, June 10, 2019 at 1:04:41 PM UTC-7, Quang Lam wrote:
i have this table as follows:
db.define_table( 'Pass', Field('FlightID',  'reference Flight',  label=T('Flight'),   requires=IS_NOT_EMPTY()),
                             Field('AnalystID', 'reference Analyst', label=T('Analyst'),  requires=IS_NOT_EMPTY()),
                             Field('TypeID',    'reference Type',    label=T('Type'),     requires=IS_NOT_EMPTY()),
                             Field('Name',                           label=T('Pass Name'),requires=IS_NOT_EMPTY()),
                             Field('Configuration',                  label=T('Configuration')),
                             Field('PostedToCustomer',               label=T('Posted To Customer'), type='boolean'),
                             Field('PassNote',                       label=T('Pass Note'),          type='text'),
                             Field('AnalysisNote',                   label=T('Analysis Note'),      type='text'),
 Field('Mode',                           label=T('Mode'),   writable=False,            type='text'))      // field mode is set to writable = false to prevent user inputting the data in this field because it will call another script to get the the data for mode attribute

i will have the form to ask the user to input info into these fields except mode field because i will call another script to get the data of the mode from the other table and input the mode data along with the input data from user. my question is where should i call the script to get the mode data? ( is it the in the form.process().accepted block. ?). how can i insert the mode data at the same time when the user click submit to insert the inputs into the table ?

Please help, Thanks

Quang Lam

unread,
Jun 10, 2019, 7:11:25 PM6/10/19
to web2py-users
Hi Dave, if i set the mode field to readable false and writable true, how i can display the mode field in the view page. i know we can make it temporarily readable true but i dont know how.
Please help. 

Dave S

unread,
Jun 10, 2019, 7:42:52 PM6/10/19
to web2py-users


On Monday, June 10, 2019 at 4:11:25 PM UTC-7, Quang Lam wrote:
Hi Dave, if i set the mode field to readable false and writable true, how i can display the mode field in the view page. i know we can make it temporarily readable true but i dont know how.
Please help. 


I'm going to wait to answer until I  can access a system that isn't at the same site I am right now.

/dps


Dave S

unread,
Jun 11, 2019, 12:21:06 PM6/11/19
to web2py-users


On Monday, June 10, 2019 at 4:42:52 PM UTC-7, Dave S wrote:


On Monday, June 10, 2019 at 4:11:25 PM UTC-7, Quang Lam wrote:
Hi Dave, if i set the mode field to readable false and writable true, how i can display the mode field in the view page. i know we can make it temporarily readable true but i dont know how.
Please help. 


I'm going to wait to answer until I  can access a system that isn't at the same site I am right now.


Here's what I tried:

I took an existing form, and in the controller that displays and processes it, I set db.mytble.PostDate.default=datetime.date(2001,07,14) and db.mytble.PostDate.writable = false.  (It isn't set that way in the define_table()).   The form displays the current date, but as a string and not as an input box.  I submit the form, and in the accept branch I do:

if form.process().accepted:
   
print form.vars
   
set form.vars.PostDate to request.now.date()
   thisrow
- db(mytable.id == form.vars.id).select().first()
   thisrow
.update_record(PostDate = form.vars.PostDate)

After submitting, I look at the console and see that form.vars does not include form.vars.PostDate.  I use appadmin to check the database, and I find that the current date is recorded in the database.in the new row.

And in case there is a difference in the enforcement of writable, I did do a quick check of setting writable = False in the define_table(Field()).  No difference that I could see.

Caveat:  I did this with 2.14.6; it's a site only visible on my localhost, so I've been slow to update.  I do have 2.18.x installed on the same machine, but I haven't moved my apps over yet.

/dps



Reply all
Reply to author
Forward
0 new messages