Class decorator


class rules_light.class_decorator.class_decorator[source]

Can be used to secure class based views.

If the view has model=YourModel, it will support:

  • CreateView, it will decorate get_form(), to run rules_light.require('yourapp.yourmodel.create'),
  • UpdateView, it will decorate get_object(), to run rules_light.require('yourapp.yourmodel.update', obj),
  • DeleteView, it will decorate get_object(), to run rules_light.require('yourapp.yourmodel.delete', obj),
  • DetailView, it will decorate get_object(), to run rules_light.require('', obj),
  • others views, if the rule name is specified in the decorator for example @class_decorator('some_rule'), then it will decorate dispatch(),
  • Else it raises an exception.


from __future__ import unicode_literals

from django.views import generic
from django.contrib.auth.models import User

import rules_light

class CreateView(generic.CreateView):
    model = User

class UpdateView(generic.UpdateView):
    model = User

class DetailView(generic.DetailView):
    model = User

class DeleteView(generic.DeleteView):
    model = User

class FunnyUpdateView(generic.UpdateView):
    model = User