4👍
✅
When you change back self.user
to a User
instance here:
self.user = self.user.resolve(context)
it works the first time, but the next time, because self.user
is no longer a template.Variable
instance, you get the exception: ‘User’ object has no attribute ‘resolve'”
One solution is to save user
& object
instance in local variables:
def render(self, context):
user_inst = self.user.resolve(context)
object_inst = self.object.resolve(context)
permissions_obj = object_inst.permissions(user_inst)
content = self.nodelist.render(context)
if hasattr(permissions_obj, self.permission):
perm_func = getattr(permissions_obj, self.permission)
if perm_func():
return content
return ""
Source:stackexchange.com