Woah that's whack. And if you add a super call to `A` it fails with

`AttributeError: 'super' object has no attribute 'main'`

Seems kind of precarious though, doesn't it? Also calling `B().main()` will
fail with the same error, so it's very unintuitive to whoever writes `B`
that they should add a `super` call to that method!


On Mon, Aug 26, 2013 at 7:37 PM, Ethan Soergel <notifications@github.com>wrote:

> In corehq/apps/domain/views.py:
>
> > +
> > +    def get(self, request, *args, **kwargs):
> > +        if request.couch_user.is_domain_admin(self.domain):
> > +            return HttpResponseRedirect(reverse(EditBasicProjectInfoView.name, args=[self.domain]))
> > +        return HttpResponseRedirect(reverse(EditMyProjectSettingsView.name, args=[self.domain]))
> > +
> > +
> > +class BaseAdminProjectSettingsView(BaseProjectSettingsView):
> > +    """
> > +        The base class for all project settings views that require administrative
> > +        access.
> > +    """
> > +
> > +    @method_decorator(domain_admin_required)
> > +    def dispatch(self, request, *args, **kwargs):
> > +        return super(BaseProjectSettingsView, self).dispatch(request, *args, **kwargs)
>
> You can definitely use multiple mixins for permissions, as long as super
> is called correctly. For example, this works:
>
> class A(object):
>     def main(self):
>         print "A"
>
> class B(object):
>     def main(self):
>         print "B"
>         super(B, self).main()
>
> class C(B, A):
>     def main(self):
>         print "C"
>         super(C, self).main()
>
> >>> C().main()
> C
> B
> A
>
> This is used, for example, in django-braces<https://github.com/brack3t/django-braces/blob/master/braces/views.py#L82>.
> Each dispatch method will be called in order from left to right, and as
> long as all call super except the rightmost, each block will be executed.
> The difficulty is if you need custom dispatch logic and don't plan on
> calling the View dispatch method at all.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/dimagi/commcare-hq/pull/918/files#r5993624>
> .
>