27 sep 2008 kl. 11.58 skrev Steve Holden:

>
> Knut Nesheim wrote:
>> Hi!
>>
>> We're trying to build a multi-page form using FormWizard. We need to
>> authorize the user first. In other views we use the user_passes_test
>> decorator, however the documented way of using FormWizard is to
>> include it directly in the urlconf:
>>
>> (r'^contact/$', ContactWizard([ContactForm1, ContactForm2])),
>>
>> How can we use decorators with this?
>>
> You can't. But remember, a decorator is only a shorthand for the
> application of a function to another function. So you *should* be able
> to use the following (though I haven't tested it):
>
> (r'^contact/$', login_required(ContactWizard)([ContactForm1,  
> ContactForm2]))

I couldn't get that to work, but the following did:

        (r'^contact/$', login_required(ContactFormWizard([ContactFormPartOne,  
ContactFormPartTwo])))

But it complained it couldn't find the __name__ attribute, so I added  
the following to my FormWizard subclass:

        def __name__(self):
                """When using decorators, Django tries to get the name of the 
function
                and since we're a class, we'll fail. So add this method to  
compensate."""
                return 'OrderFormWizard'

I have no idea how if this will create problems for us in the future,  
but it does actually work.


>
>> We've tried
>>
>> (r'^contact/$', @login_required(ContactWizard([ContactForm1,
>> ContactForm2]))),
>>
>> But it only gives
>>
>> Exception Type: TypeError at /order/add/ Exception Value: 'type'
>> object is unsubscriptable
>>
>> Any help is appreciated.
> I am absolutely amazed that you don't get a syntax error on that  
> statement.

Oh, sorry. I pasted and edited inline.

Thanks for your input!

Regards
-- 
Knut Nesheim









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

Reply via email to