Re: newforms + multiple sister forms submitted/processed in one user action

2007-08-11 Thread Patrick Anderson

On Sat, 11 Aug 2007 14:36:50 +, Patrick Anderson wrote:

> On Sat, 11 Aug 2007 14:34:05 +, Patrick Anderson wrote:
> 
>> On Fri, 10 Aug 2007 18:46:18 -0700, Doug B wrote:
>> 
>> 
> ---

 If I have 8 people, how should bind POST data to a form object in the
 view?
>>> 
>>> You can use the 'prefix' option when instantiating the forms.  Prefix
>>> the form with the corresponding form 'number' or other unique
>>> identifier.  On post pass it the whole post dict.  It will pull the
>>> data out according to the prefix.
>>> 
>>> 
>> That's what I thought, too. One problem I have right now is to
>> dynamically assign form element id attribute based on count of the for
>> loop in the view.
> 
> Which I solved by manipulating Widget attrs in each form.base_field
> 

Now I have the problem with validation and errors, since I'm submitting 
data in one request to multiple form objects, how can I get to the errors 
and display them properly next to each field?

Perhaps it is better and simpler to deal with each form at a time, even 
if it means to have a separate submit button for each one.

>> 
>> 
> 
> 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: newforms + multiple sister forms submitted/processed in one user action

2007-08-11 Thread Patrick Anderson

On Sat, 11 Aug 2007 14:34:05 +, Patrick Anderson wrote:

> On Fri, 10 Aug 2007 18:46:18 -0700, Doug B wrote:
> 
>>> 
---
>>>
>>> If I have 8 people, how should bind POST data to a form object in the
>>> view?
>> 
>> You can use the 'prefix' option when instantiating the forms.  Prefix
>> the form with the corresponding form 'number' or other unique
>> identifier.  On post pass it the whole post dict.  It will pull the
>> data out according to the prefix.
>> 
>> 
> That's what I thought, too. One problem I have right now is to
> dynamically assign form element id attribute based on count of the for
> loop in the view.

Which I solved by manipulating Widget attrs in each form.base_field

> 
> 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: newforms + multiple sister forms submitted/processed in one user action

2007-08-11 Thread Patrick Anderson

On Fri, 10 Aug 2007 18:46:18 -0700, Doug B wrote:

>> ---
>>
>> If I have 8 people, how should bind POST data to a form object in the
>> view?
> 
> You can use the 'prefix' option when instantiating the forms.  Prefix
> the form with the corresponding form 'number' or other unique
> identifier.  On post pass it the whole post dict.  It will pull the data
> out according to the prefix.
> 

That's what I thought, too. One problem I have right now is to 
dynamically assign form element id attribute based on count of the for 
loop in the view.
 
> 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: newforms + multiple sister forms submitted/processed in one user action

2007-08-10 Thread Doug B

> ---
>
> If I have 8 people, how should bind POST data to a form object in the
> view?

You can use the 'prefix' option when instantiating the forms.  Prefix
the form with the corresponding form 'number' or other unique
identifier.  On post pass it the whole post dict.  It will pull the
data out according to the prefix.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: newforms + multiple sister forms submitted/processed in one user action

2007-08-10 Thread Patrick Anderson

On Fri, 10 Aug 2007 13:32:32 -0700, Collin Grady wrote:

> One method is to include a hidden input somewhere that indicates the
> number of forms present. Then you can just use a for loop from 1 to that
> number in the view to build the right number of forms again.
> 
> 
> 
This is the raw html form loop (without {{ form }}):

--


Name:


F. Name:

M. Name:

L. Name:



---

If I have 8 people, how should bind POST data to a form object in the 
view?

Well, here's my view I just started writing:

---

def index(request, template):

from forms import PersonForm

persons = []

if 'total_transfers' in request.session:
if request.session['total_transfers']:
[persons.append(x) for x in range(1, request.session
['total_transfers']+1)]

personnel_form = []

if len(persons):
if request.method == 'POST':
data = request.POST.copy()  
for i in persons.values():
f = PersonForm(data) # how should I bind data to form?
personnel_form.append(f)
...
# to-be done

return direct_to_template(request, 
template,
extra_context = {
'persons': persons,
'forms': personnel_forms,
})

-


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: newforms + multiple sister forms submitted/processed in one user action

2007-08-10 Thread Collin Grady

One method is to include a hidden input somewhere that indicates the
number of forms present. Then you can just use a for loop from 1 to
that number in the view to build the right number of forms again.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



newforms + multiple sister forms submitted/processed in one user action

2007-08-10 Thread Patrick Anderson

This is a simplified PersonForm I've created with newforms library:

class PersonForm(forms.Form):

name = forms.CharField()
first_name = forms.CharField()
middle_name = forms.CharField(required = False)
last_name = forms.CharField()

The problem I have is that I need to update the Personnel on the same 
page. How should I go about writing a template and processing the POST 
request with newforms if the number of PersonForms can vary in each 
session and the user should submit all forms in one action?


By the way, this form is not going to be tied to any existing model. I 
need to pass submitted data to another server, but that is not the issue 
here. I'm wondering how newforms library could help me with this task. 

Has anyone done this before and has any thoughts and tips?



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---