-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello Tobia,

Thanks for taking the time to propose these additions. Comments below:

On 02/17/2012 11:04 AM, Tobia Conforto wrote:
> The first is an updated version of method_decorator, made to accept
> additional arguments and pass them to the original decorator:
> 
> class MyView(View): @method_decorator(never_cache) 
> @method_decorator(login_required, login_url='/my-login') 
> @method_decorator(permission_required, 'thing.change_thing') def
> dispatch(self, request, *args, **kwargs): ...

Is this really any better than
@method_decorator(permission_required("thing.change_thing"))? The latter
seems more explicit/clearer, and allows method_decorator to stay simpler.

> The second is class_view_decorator, to apply classic view decorators
> to the newer class-based views:
> 
> @class_view_decorator(never_cache) 
> @class_view_decorator(login_required, login_url='/my-login') 
> @class_view_decorator(permission_required, 'thing.change_thing') 
> class MyView(View): ...

Unfortunately, class decorators that create and return a dynamic
subclass cause infinite recursion if super() is used in a method of the
decorated class, because the name given as the first argument to super()
will actually refer to the subclass at runtime. This problem, and
alternative options, were discussed extensively in a thread here a few
months ago.

Carl
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8+qN0ACgkQ8W4rlRKtE2fHmACfT+a+9GGAuGx11fhMnXp3PDBT
62MAn0deRbjzwfXhl8ro/ZcfS8oVQR+r
=zM3e
-----END PGP SIGNATURE-----

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

Reply via email to