Re: How to set queryset on the second step of a form wizard?

2008-08-22 Thread rr

http://dpaste.com/73317/

I have dpasted it on the link above

Cheers
Roy

On Aug 21, 2:30 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> On Aug 21, 11:56 am, rr <[EMAIL PROTECTED]> wrote:
>
> > The url is herehttp://dpaste.com/72961/
>
> I don't see anything glaringly wrong. You mentioned that it "complains
> about 'ChannelTypeForm' object has no attribute 'cleaned_data'"...can
> you dpaste that error trace as well?
--~--~-~--~~~---~--~~
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: How to set queryset on the second step of a form wizard?

2008-08-21 Thread Rajesh Dhawan



On Aug 21, 11:56 am, rr <[EMAIL PROTECTED]> wrote:
> The url is herehttp://dpaste.com/72961/

I don't see anything glaringly wrong. You mentioned that it "complains
about 'ChannelTypeForm' object has no attribute 'cleaned_data'"...can
you dpaste that error trace as well?

--~--~-~--~~~---~--~~
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: How to set queryset on the second step of a form wizard?

2008-08-21 Thread rr

The url is here
http://dpaste.com/72961/

-r

On Aug 21, 9:39 am, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> On Aug 21, 2:06 am, rr <[EMAIL PROTECTED]> wrote:
>
> > sorry for being annoying
>
> > It doesn't work, complains about
> > 'ChannelTypeForm' object has no attribute 'cleaned_data'
> > when submit on thesecondstep(step1)http://dpaste.com/72840/
>
> Can you also dpaste your URLs.py that shows whichformisstep0 andstep1?
--~--~-~--~~~---~--~~
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: How to set queryset on the second step of a form wizard?

2008-08-21 Thread [EMAIL PROTECTED]

Override the process_step method do that when step one is being
processed, it creates the queryset to be used by step 2 then.

if(step==1):
if(form.is_valid()):
self.step2_queryset=Book.objects.filter(**form.cleaned_data)
elif(step==0):
self.step2_queryset=None

Then, override the get_form method to grab the self.step2_queryset
variable and use it in the form. Thus you don't have to worry about
cleaning forms more than once.
--~--~-~--~~~---~--~~
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: How to set queryset on the second step of a form wizard?

2008-08-21 Thread Rajesh Dhawan



On Aug 21, 2:06 am, rr <[EMAIL PROTECTED]> wrote:
> sorry for being annoying
>
> It doesn't work, complains about
> 'ChannelTypeForm' object has no attribute 'cleaned_data'
> when submit on the second step(step1)http://dpaste.com/72840/

Can you also dpaste your URLs.py that shows which form is step 0 and
step 1?


--~--~-~--~~~---~--~~
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: How to set queryset on the second step of a form wizard?

2008-08-21 Thread rr

sorry for being annoying

It doesn't work, complains about
'ChannelTypeForm' object has no attribute 'cleaned_data'
when submit on the second step(step1)
http://dpaste.com/72840/

-r

On Aug 21, 1:51 am, rr <[EMAIL PROTECTED]> wrote:
> Don't worry.Formworks now. Thanks a lot.
>
> But would be great if you can explain it a bit on how your code works
> and the sequence of how process_steps and get_form works as I see it
> seems called a few time between steps
>
> Thanks =)
> -r
>
> On Aug 21, 1:42 am, rr <[EMAIL PROTECTED]> wrote:
>
> > It works well. Thanks a lot.
>
> > But now another problem. It seems "def done " is not working. It loops
> > back to the step1 and def done is never called
>
> > And do you mind explain how your code works? I did a "printstep"
> > before returnformin the def get_from, it prints 0, 1, 0. It seems it
> > has been called 3 times when submit in thesecondstep
>
> > What is the sequence of the call of process_step and get_form? the
> > docs didn't explain much about this
>
> > Thanks in Advance!!
> > -r
>
> > On Aug 20, 4:59 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
>
> > > On Aug 20, 12:57 pm, rr <[EMAIL PROTECTED]> wrote:
>
> > > > Thanks Rajesh
>
> > > > But...it doesn't work
> > > > It complains about form0 doesn't have cleaned_data. I guess
>
> > > > form0 = super(MyFormWizard, self).get_form(0, data=data)
>
> > > > only gives you aformwith no data?!
>
> > > I just dpasted something that will help you capture the channelType
> > > fromstep0 and then use it when thestep1formis being created.
>
> > >http://dpaste.com/hold/72763/
>
> > > If that doesn't work, please dpaste your MyFormWizard code.
>
> > > -Rajesh D
--~--~-~--~~~---~--~~
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: How to set queryset on the second step of a form wizard?

2008-08-20 Thread rr

Don't worry. Form works now. Thanks a lot.

But would be great if you can explain it a bit on how your code works
and the sequence of how process_steps and get_form works as I see it
seems called a few time between steps

Thanks =)
-r

On Aug 21, 1:42 am, rr <[EMAIL PROTECTED]> wrote:
> It works well. Thanks a lot.
>
> But now another problem. It seems "def done " is not working. It loops
> back to the step1 and def done is never called
>
> And do you mind explain how your code works? I did a "printstep"
> before returnformin the def get_from, it prints 0, 1, 0. It seems it
> has been called 3 times when submit in thesecondstep
>
> What is the sequence of the call of process_step and get_form? the
> docs didn't explain much about this
>
> Thanks in Advance!!
> -r
>
> On Aug 20, 4:59 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
>
> > On Aug 20, 12:57 pm, rr <[EMAIL PROTECTED]> wrote:
>
> > > Thanks Rajesh
>
> > > But...it doesn't work
> > > It complains about form0 doesn't have cleaned_data. I guess
>
> > > form0 = super(MyFormWizard, self).get_form(0, data=data)
>
> > > only gives you aformwith no data?!
>
> > I just dpasted something that will help you capture the channelType
> > fromstep0 and then use it when thestep1formis being created.
>
> >http://dpaste.com/hold/72763/
>
> > If that doesn't work, please dpaste your MyFormWizard code.
>
> > -Rajesh D
--~--~-~--~~~---~--~~
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: How to set queryset on the second step of a form wizard?

2008-08-20 Thread rr

It works well. Thanks a lot.

But now another problem. It seems "def done " is not working. It loops
back to the step1 and def done is never called

And do you mind explain how your code works? I did a "print step"
before return form in the def get_from, it prints 0, 1, 0. It seems it
has been called 3 times when submit in the second step

What is the sequence of the call of process_step and get_form? the
docs didn't explain much about this

Thanks in Advance!!
-r

On Aug 20, 4:59 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> On Aug 20, 12:57 pm, rr <[EMAIL PROTECTED]> wrote:
>
> > Thanks Rajesh
>
> > But...it doesn't work
> > It complains about form0 doesn't have cleaned_data. I guess
>
> > form0 = super(MyFormWizard, self).get_form(0, data=data)
>
> > only gives you aformwith no data?!
>
> I just dpasted something that will help you capture the channelType
> fromstep0 and then use it when thestep1formis being created.
>
> http://dpaste.com/hold/72763/
>
> If that doesn't work, please dpaste your MyFormWizard code.
>
> -Rajesh D
--~--~-~--~~~---~--~~
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: How to set queryset on the second step of a form wizard?

2008-08-20 Thread Rajesh Dhawan



On Aug 20, 12:57 pm, rr <[EMAIL PROTECTED]> wrote:
> Thanks Rajesh
>
> But...it doesn't work
> It complains about form0 doesn't have cleaned_data. I guess
>
> form0 = super(MyFormWizard, self).get_form(0, data=data)
>
> only gives you a form with no data?!

I just dpasted something that will help you capture the channelType
from step 0 and then use it when the step 1 form is being created.

http://dpaste.com/hold/72763/

If that doesn't work, please dpaste your MyFormWizard code.

-Rajesh D
--~--~-~--~~~---~--~~
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: How to set queryset on the second step of a form wizard?

2008-08-20 Thread Rajesh Dhawan



On Aug 20, 12:57 pm, rr <[EMAIL PROTECTED]> wrote:
> Thanks Rajesh
>
> But...it doesn't work
> It complains about form0 doesn't have cleaned_data. I guess
>
> form0 = super(MyFormWizard, self).get_form(0, data=data)
>
> only gives you a form with no data?!

Can you dpaste what you've so far?

--~--~-~--~~~---~--~~
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: How to set queryset on the second step of a form wizard?

2008-08-20 Thread rr

Thanks Rajesh

But...it doesn't work
It complains about form0 doesn't have cleaned_data. I guess

form0 = super(MyFormWizard, self).get_form(0, data=data)

only gives you a form with no data?!



On Aug 20, 11:06 am, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> Hi,
>
> > Depending onstep1's selection, I want tosetthequerysetof one of
> > the fields (a ModelChoiceField)
>
> > e.g.
> > class StepOneForm(forms.Form):
> >    channelType =
> > forms.ModelChoiceField(queryset=ChannelType.objects.all())
> > class StepTwoForm(forms.Form):
> >    channel = forms.ModelChoiceField()
>
> > class MyFormWizard(FormWizard):
> >    def process_step(self, request,form,step):
> >         ifstep==0:
> >             self.get_form(1).channel.queryset=
> >form.cleaned_data['channelType'].channel_set.all()
>
> The process_step method is called only after theformis already
> validated. So, as you found out, that's not going to work. Also, you
> are trying tosetthequerysetonform#1 whenstepis 0. That's not
> going to persist.
>
> > But it doesn't seems working... how can a dynamic choice can be
> > achieved depending on selection of previousstep?!
>
> Try overriding the get_form method instead of process_step. Also, you
> will need to populateform#1'squerysetwhen you are instep1. So,
> the code would be something like this:
>
> def get_form(self,step, data=None):
>    form= super(MyFormWizard, self).get_form(step, data=data)
>     ifstep== 1:
>         # Getstep#0'sformandsetform#1'squerysetbased on it
>                 form0 = super(MyFormWizard, self).get_form(0, data=data)
>                form.fields['channel'].queryset=
> form0.cleaned_data['channelType'].channel_set.all()
>     returnform
>
> -Rajesh D
--~--~-~--~~~---~--~~
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: How to set queryset on the second step of a form wizard?

2008-08-20 Thread Rajesh Dhawan

Hi,

> Depending on step 1's selection, I want to set the queryset of one of
> the fields (a ModelChoiceField)
>
> e.g.
> class StepOneForm(forms.Form):
>channelType =
> forms.ModelChoiceField(queryset=ChannelType.objects.all())
> class StepTwoForm(forms.Form):
>channel = forms.ModelChoiceField()
>
> class MyFormWizard(FormWizard):
>def process_step(self, request, form, step):
> if step==0:
> self.get_form(1).channel.queryset =
> form.cleaned_data['channelType'].channel_set.all()

The process_step method is called only after the form is already
validated. So, as you found out, that's not going to work. Also, you
are trying to set the queryset on form #1 when step is 0. That's not
going to persist.

> But it doesn't seems working... how can a dynamic choice can be
> achieved depending on selection of previous step?!

Try overriding the get_form method instead of process_step. Also, you
will need to populate form #1's queryset when you are in step 1. So,
the code would be something like this:

def get_form(self, step, data=None):
form = super(MyFormWizard, self).get_form(step, data=data)
if step == 1:
# Get step #0's form and set form #1's queryset based on it
form0 = super(MyFormWizard, self).get_form(0, data=data)
form.fields['channel'].queryset =
form0.cleaned_data['channelType'].channel_set.all()
return form

-Rajesh D

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---