I'm trying, in vain, to create a simple Django template tag to either show or hide a "delete" link next to a submitted comment on my site.
In a nutshell, I want to pass the comment object to the template tag, determine if the currently logged in user is authorized to delete the comment and then either show or not show the link.
The usage in my template would be like so:
{% load access_tags %}
{% if_authorized comment %}
<a href="{% url delete_comment comment.id %}">Delete</a>
{% endif_authorized %}
Rest assured that I also check in the appropriate view if the user is authorized to delete the comment.
Does this type of tag have a specific name? It would certainly help me with my Google searches if it did. Thanks for your help!
UPDATE 1:
The way my site works, two people are potentially authorized to delete a comment: 1) the comment creator and 2) the owner of the post where the comment was left. Because of this, I need to determine, per comment, if one of those conditions is present.
I don't think I can use something like Django's built-in permission sytem, since it requires that permissions "be set globally per type of object, no per specific object instance".
In my case, user "Bob" may have permissions to delete a comment (if he wrote it or it is on a post he created), but he also may not be allowed to delete it (if he is looking at a comment on someone else's post).
UPDATE 2:
It appears that you can't pass objects to a template tag, only strings: "Although you can pass any number of arguments to a template tag using token.split_contents(), the arguments are all unpacked as string literals." I guess I'll pass the id of the comment object in question and pull it in the tag.
I was wrong about this, just have to access the passed in object like:
self.comment.resolve(context).user
vs.
self.comment.user