In a previous post , I wrote about a way to keep track of user permissions on a model instance. For example, I suggested that each model have a permissions subclass that could be instantiated with a user instance passed as a constructor argument. Methods on that permissions class could then be called to determine if that user has permission to perform various actions. I also suggested that the threadlocals module could then be used to pass in the user instance to the permissions object in the Django template. However, from various readings, I get the impression that threadlocals may not be the best thing for passing arguments in a template function. Therefore, I decided to use a more traditional route of creating a template tag to do something similar. I created a template tag that lets you surround a block of HTML code to hide or show the contents based on the return value of the permission function. The tag below basically says, "if the logged in use...
Django Python exploration