[web2py] Re: Two forms

2017-09-23 Thread 黄祥
yes, you are right, my bad, my old code have a race condition because of 
assigned with max id
*e.g.*
*have a race condition (don't use it if transaction is high)*
id_max = db.order.id.max()
maxID = db(db.order).select(id_max).first()[id_max]
order_id = int(maxID) + 1 if maxID else 1
db.item.order_id.default = order_id

*doesn't have a race condition (best practice)*
order_id_1 = db.order.insert(name = 'order1')
db.item.insert(name = 'item1', order_id = order_id_1)

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/d/optout.


[web2py] Re: Two forms

2017-09-22 Thread T.R.Rajkumar
The order table id will be returned by the insert statement. There will be 
no race. We can use the returned id in items table.

-- 
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: Two forms

2017-09-22 Thread 黄祥
face this before, usually created the form with web2py components 1 for 
items (up first), save the value of items on the sessions then another 
component for order table (below to submit all the data (data in sessions 
input to items and order data)

during the form.process() or form.validate() first i insert the order 
table, then create a query to get the order table id, then assign it into 
items table. as a suggestion from people in here, this will create a race 
condition (which id will assign to items table when there is another person 
that input the order), good to use when your order table input that dont 
have high traffic or high transaction

another way
option 1:
dont use the reference data type between order and items, just use the 
order field that unique, e.g. 'order_no' then assign it when generate the 
form, use the generated 'order_no' to items field table

option 2:
why not combine the table (order and items) into 1 table, do the looping 
during the insert for both of it

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/d/optout.


Re: [web2py] Re: two forms submitted into the same cotroller

2014-09-10 Thread Andrey Khmelevskiy
Thank Cliff and Massimo for your help.
I have finally make in very similar fission:
I have 2 divs,
controller1 with static form with id=1 that inserted in div1,
another controller2 that triggers by w2p_component (ajax) and generates
form with id=2 and inserted to div2 but all input fields of this form has
HTML 5 attribute "_form=1",
Plus I have button with the same "_form=1"

So when I submit/click the button -both forms submitted vars get to the
controller1 and inserted to the same record of my db table.

It works well for me.

This approach did not work when I insert my forms from controller1 via LOAD
helper

Regards
 On Sep 3, 2014 1:08 AM, "Cliff Kachinske"  wrote:

> Here is what I do.
>
> Your page should have one form only.
>
> Make 2 divs. Top div has your fixed fields including the one that triggers
> the variable content.
>
> Use jquery to catch the change event for the field. When the field changes
> send an Ajax request to the server.
>
> Let the server build the variable form and return it to the server to
> populate the second div.
>
> I build the individual form elements rather than using FORM or SQLFORM.
> That way I avoid form within a form problems.
>
> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/jNsHXtD0VqI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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: two forms submitted into the same cotroller

2014-09-02 Thread Cliff Kachinske
Here is what I do.

Your page should have one form only. 

Make 2 divs. Top div has your fixed fields including the one that triggers the 
variable content. 

Use jquery to catch the change event for the field. When the field changes send 
an Ajax request to the server. 

Let the server build the variable form and return it to the server to populate 
the second div.

I build the individual form elements rather than using FORM or SQLFORM. That 
way I avoid form within a form problems.

-- 
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: two forms submitted into the same cotroller

2014-08-31 Thread Massimo Di Pierro
This helps but I still have some questions... where is ? what is 
? is this used the output of two generated SQLFORM? or the actual 
source view?

On Sunday, 31 August 2014 14:45:02 UTC-5, Andrey K wrote:
>
> Thanks Massimo.   
> Here is my reformatted question(hope it will be more understandable): 
>  I want to present two input sets of information coming from server 
> into two sections of the same view (div1 and div2). First input set is 
> generated based on user choice control, that presented at the same view(div 
> 0), the second is user based. 
>  How to 
> 1)organize data fetching/adding INPUT sets to the view  so   
> 2)all user input can be submitted back to the server from these two input 
> data sets into one data table record, icluding  user selection choice. 
>
> Here is how it looks in the result view and DB recorde: 
>
> View: 
>
>  
>
>  SELECT(t1,t2,t3) 
>
>  
>
>  
>
>  
>
>  
>
> INPUT(_name=’file’, _value=’’, default = 0) 
>
> INPUT(_name=’parameter’, _value= , default=100) 
>
>  
>
>  
>
>  
>
>  
>
>  
>
> INPUT(_name=purpose, _value=’processing’) 
>
>  
>
>  
>
>  
>
> Db.table row result: 
>
> User_choice, file, parameter, purpose 
>
> t1   , 0 ,100, ‘processing’ 
>
>
> Thank you in advance. 
> Please let me know if you need more details. 
>
>

-- 
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: two forms submitted into the same cotroller

2014-08-31 Thread Andrey K
Thanks Massimo.  
Here is my reformatted question(hope it will be more understandable): 
 I want to present two input sets of information coming from server into 
two sections of the same view (div1 and div2). First input set is generated 
based on user choice control, that presented at the same view(div 0), the 
second is user based. 
 How to
1)organize data fetching/adding INPUT sets to the view  so  
2)all user input can be submitted back to the server from these two input data 
sets into one data table record, icluding  user selection choice.

Here is how it looks in the result view and DB recorde:

View:



 SELECT(t1,t2,t3)









INPUT(_name=’file’, _value=’’, default = 0)

INPUT(_name=’parameter’, _value= , default=100)











INPUT(_name=purpose, _value=’processing’)







Db.table row result:

User_choice, file, parameter, purpose

t1   , 0 ,100, ‘processing’


Thank you in advance.
Please let me know if you need more details.

-- 
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: two forms submitted into the same cotroller

2014-08-30 Thread Massimo Di Pierro
I believe your problem is the XY 
problem. http://mywiki.wooledge.org/XyProblem
Y = "submitting to forms to the same controller".
Do no ask about Y. What it your original problem X for which you think Y is 
a good solution?

On Saturday, 30 August 2014 15:24:16 UTC-5, Andrey K wrote:
>
> Hi Massimo,
> Here is my dilemma:
> I have one view with 3 tabs (DIVS), where I would like to have one tab for 
> user tool selection and two forms in 2 separated tabs(DIVs) : 1)static form 
> and 2)dynamic form(generated based on user selection in first tab). Also I 
> would like to submit all information from both forms into only one 
> controller as two separated peaces of data, where I can nicely parse it and 
> store in one record of the db.table, so it would be nice to have only one 
> button to trigger it.
> I have tried many ways but it did not work exactly the way I need it: 
> either I can't present two forms in separated view divs or I can't submit 
> both to only one controller. The last approach I had that did it almost the 
> thing was to use HTML5 _form attribute for all form elements and button and 
> related form _id attribute. But I have trouble submitting data back to the 
> controller that generate my dynamic form, added to DIV via 
> web2py_ajax_component.  
> Please help me out. What would be the way to make it in w2p?
>  

-- 
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: two forms submitted into the same cotroller

2014-08-30 Thread Andrey K
Hi Massimo,
Here is my dilemma:
I have one view with 3 tabs (DIVS), where I would like to have one tab for user 
tool selection and two forms in 2 separated tabs(DIVs) : 1)static form and 
2)dynamic form(generated based on user selection in first tab). Also I would 
like to submit all information from both forms into only one controller as two 
separated peaces of data, where I can nicely parse it and store in one record 
of the db.table, so it would be nice to have only one button to trigger it.
I have tried many ways but it did not work exactly the way I need it: either I 
can't present two forms in separated view divs or I can't submit both to only 
one controller. The last approach I had that did it almost the thing was to use 
HTML5 _form attribute for all form elements and button and related form _id 
attribute. But I have trouble submitting data back to the controller that 
generate my dynamic form, added to DIV via web2py_ajax_component.  
Please help me out. What would be the way to make it in w2p?
 

-- 
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: two forms submitted into the same cotroller

2014-08-29 Thread Massimo Di Pierro
Something is wrong here. Can you explain at higher level what are you 
trying to achieve?

On Friday, 29 August 2014 16:10:59 UTC-5, Andrey K wrote:
>
> Dear list,
>
> I have two related questions:
>
> 1. Basically I have one view (C) which contains two forms A and B. The 
> dynamic form A is created by controller A and added by web2py_component 
> (Ajax call). The static  form B is created by controller B and added via 
> helper LOAD. I want to submit both forms into controller A of form A. How 
> to do it ?
>
> 2. Also I want to know how I can have one controller that will dynamically 
> create 
>  two forms via web2py_component (Ajax call) and place both of them into the 
> two separate div's of the same view. I want then that the data of both 
> forms are submitted simultaneously into the same controller and processed 
> there?
>
> I managed to generate two forms in one controller but I cannot separate 
> them into different div's on the same view.
>
> I would be happy if you could advise me on this,
> Andrey
>

-- 
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: Two forms, one page

2012-03-21 Thread Cliff
> Another approach, the one that I use, is to hide the various forms
> behind accordion folds.

Or on different tabs.

In either case,  update the fields on the tab or fold being closed to
avoid losing input.

You can use ajax for this.

On Mar 21, 12:16 am, weheh  wrote:
> I think you're going to have some trouble with this. Your best bet is
> to go with SQLFORM.factory. problem is, you lose your nice CRUD
> functionality. But it gives you complete control.
>
> Another approach, the one that I use, is to hide the various forms
> behind accordion folds. That way, you only have one submit button at a
> time in the view.
>
> On Mar 21, 4:49 am, Larry Wapnitsky  wrote:
>
>
>
>
>
>
>
> > I know it's possible to have multiple forms on one page, but is it possible
> > to have one submit button that submits data based on both forms?
>
> > I have a SQLFORM field that takes multiple entries.
>
> > This is followed by a CRUD form based on the DAL (MySQL).
>
> > I'd like to parse the data in the SQLFORM (multiple, individual entries)
> > and add them one by one as unique values to the DAL with the information in
> > the CRUD portion (data common to all entries).
>
> > Is this possible?
>
> > Thanks.


Re: [web2py] Re: Two forms, one page

2012-03-21 Thread Larry G. Wapnitsky
Thanks, Niphlod & pbreit.  Still learning, and asking questions is how I 
do it.  I'll work on your suggestions f


FYI, Niphlod - this is the same app as in the other thread.

On 3/20/2012 5:38 PM, Niphlod wrote:

why not using SQLFORM.factory for having one form for all the data ?

in the controller logic, then, something like

for f in form.vars.multiple_field:
  db.mysqltable.validate_and_insert(foo=form.vars.foo, 
bar=form.vars.bar, uniquefield=f)


should do the job.

With no example model supplied, this is all the help you can get ^_^


[web2py] Re: Two forms, one page

2012-03-20 Thread weheh
I think you're going to have some trouble with this. Your best bet is
to go with SQLFORM.factory. problem is, you lose your nice CRUD
functionality. But it gives you complete control.

Another approach, the one that I use, is to hide the various forms
behind accordion folds. That way, you only have one submit button at a
time in the view.


On Mar 21, 4:49 am, Larry Wapnitsky  wrote:
> I know it's possible to have multiple forms on one page, but is it possible
> to have one submit button that submits data based on both forms?
>
> I have a SQLFORM field that takes multiple entries.
>
> This is followed by a CRUD form based on the DAL (MySQL).
>
> I'd like to parse the data in the SQLFORM (multiple, individual entries)
> and add them one by one as unique values to the DAL with the information in
> the CRUD portion (data common to all entries).
>
> Is this possible?
>
> Thanks.


[web2py] Re: Two forms, one page

2012-03-20 Thread Niphlod
why not using SQLFORM.factory for having one form for all the data ?

in the controller logic, then, something like

for f in form.vars.multiple_field:
  db.mysqltable.validate_and_insert(foo=form.vars.foo, 
bar=form.vars.bar, uniquefield=f) 

should do the job.

With no example model supplied, this is all the help you can get ^_^


[web2py] Re: Two forms, one page

2012-03-20 Thread pbreit
I think you're going to run into problems in Web2py since even if you use 
Custom Forms (http://web2py.com/books/default/chapter/29/7#Custom-forms) 
you're going to have two conflicting security keys (hidden fields to 
prevent CSRF attacks).

If you're able to paint the form correctly in the view, then you're going 
to need to write most or all of the processing and db updating logic in 
your controller.

There might be a Jquery based approach which works better. Perhaps you 
could have a Javascript function post back the two forms individually to 
controllers designed to handle each. Sorry not more helpful.


[web2py] Re: Two forms on one page with custom forms

2011-05-23 Thread contatogilson...@gmail.com
I found the problem and created a slice:

http://web2pyslices.com/main/slices/take_slice/133
_
*Gilson Filho*
*Web Developer
http://gilsondev.com*



2011/5/23 contatogilson...@gmail.com 

> Hello,
>
> Tailored I'm a system that has a module that has a relationship of a table
>  with theauthentication module. Thus, the user can register a page in your
>  login and passwordand also your personal data, which are the data from
> that other table. Until then I usedSQLFORM.factory for it and everything
> went well. Only in the editing of the data I realized that the factory can
> not do that, and tried to use custom forms to enter the twoforms on the
> page.
>
> The problem is that it captures the form data to a model, but theother
> form he lost during data transmission. I was wondering how do I insert two
>  forms -the different tables are linked through a foreign key - with
> custom forms and sending it is passed all the data from two tables?
> _
> *Gilson Filho*
> *Web Developer
> http://gilsondev.com*
>
>