On 19 Okt, 21:18, Łukasz Rekucki <[email protected]> wrote:
> On 19 October 2010 19:06, Valentin Golev <[email protected]> wrote:> Hello,
> > I was going to write something like LoginRequiredMixin, but I have no
> > idea how to do this. I need to run my code before .dispatch(), but I
> > also have to call the old dispatch, but since Mixin aren't inherited
> > from View, I can't just override method and use super().
>
> This is option #4. You can just do:
>
> class LoginRequiredMixin(object):
>
>     def dispatch(self, *args, **kwargs):
>         bound_dispatch = super(LoginRequired, self).dispatch
>         return login_required(bound_dispatch)(*args, **kwargs)

This solution looks cleanest, and is easiest to implement. However
there is
a problem if two or more similar mixins are used: The order of the
calls are
dependant on the order the view inherits the mixins. If you make a
misstake
in the inheritance-order, your mixin might not be called at all, which
might
not always be whats intended.

I am personally working on option #3, with a simple linked list of
callables
that calls each other until the original "get", "post", etc. is
called.

--
Joachim Pileborg

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
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