@@ -54,7 +54,9 @@ class class_decorator(object):
54
54
- ``DetailView``, it will decorate ``get_object()``, to run
55
55
``rules_light.require('yourapp.yourmodel.read', obj)``,
56
56
- others views, if the rule name is specified in the decorator for example
57
- ``@class_decorator('some_rule')``, then it will decorate ``dispatch()``,
57
+ ``@class_decorator('some_rule')``, then it will decorate either
58
+ ``get_object()`` if the CBV is subclassed from ``SingleObjectMixin``
59
+ else it will decorate ``dispatch()``,
58
60
- Else it raises an exception.
59
61
"""
60
62
rule = None
@@ -119,13 +121,16 @@ def new_get_form(self, form_class, *args, **kwargs):
119
121
patch_get_object (cls , 'delete' , self .rule )
120
122
121
123
elif self .rule :
122
- old_dispatch = cls .dispatch
124
+ if issubclass (cls , generic .detail .SingleObjectMixin ):
125
+ patch_get_object (cls , 'generic' , self .rule )
126
+ else :
127
+ old_dispatch = cls .dispatch
123
128
124
- def new_dispatch (self , request , * args , ** kwargs ):
125
- registry .require (request .user , self .dispatch ._rule )
126
- return old_dispatch (self , request , * args , ** kwargs )
127
- new_dispatch ._rule = self .rule
128
- cls .dispatch = new_dispatch
129
+ def new_dispatch (self , request , * args , ** kwargs ):
130
+ registry .require (request .user , self .dispatch ._rule )
131
+ return old_dispatch (self , request , * args , ** kwargs )
132
+ new_dispatch ._rule = self .rule
133
+ cls .dispatch = new_dispatch
129
134
130
135
else :
131
136
raise RulesLightException ('Dont understand what to do' )
0 commit comments