Django DRY need

I call the "dispatch" method in all of my CRUD classes. How can I put it somewhere else to avoid repetition? ideally in an external file Thanks a lot

class PublicationsListView(LoginRequiredMixin, TemplateView):

    template_name = 'pages/publications/index.html'

    def dispatch(self, request, *args, **kwargs):
        if (self.request.user.groups.filter(Q (name='proprietaire') | Q (name='super-administrateur')).exists()) and 'flotte_id' not in self.request.session :
            messages.warning(self.request, mark_safe("Veuiller choisir ..."))
            return redirect('dashboards:home')
        else :
            return super().dispatch(request, *args, **kwargs)

    def get_context_data(self, **kwargs):

i tried de put the method elsewhere , but each time : "self" or "request" undefined

You can put in in a Mixin or in a parent Class

Back to Top