#19536 closed Cleanup/optimization (fixed)
in ModelAdmin disabling has_add_permission results in not showing any object-tools
Reported by: | Owned by: | Igor Támara | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
in change_list.html when has_add_permission is false all the object-tools (buttons) are not shown, even if you have implemented some custom tools. This permission check should only be for the add button item.
I tweaked the code (very small change) that will fix this problem.
My proposal for this matter is attached to this ticket
Attachments (1)
Change History (13)
by , 12 years ago
Attachment: | change_list_patch.html added |
---|
comment:1 by , 12 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
Version: | 1.4 → master |
Makes sense. Please provide your attachment as patch/diff format.
comment:2 by , 12 years ago
The relevant code is:
{% block object-tools %} {% if has_add_permission %} <ul class="object-tools"> {% block object-tools-items %} <li> <a href="{% url cl.opts|admin_urlname:'add' %}{% if is_popup %}?_popup=1{% endif %}" class="addlink"> {% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %} </a> </li> {% endblock %} </ul> {% endif %} {% endblock %}
The extension strategy provided to developers wishing to implement custom tools is to override the whole object-tools
block. The modification proposed by the OP would generate an empty UL element if the current user has no add permission for the normal case (no customization of the template). IMHO we need a better solution or simply leave thing as the are. Consider me -1 on the proposal in its current form.
comment:3 by , 11 years ago
How about this solution:
{% block object-tools %} <ul class="object-tools"> <li style="display: none;"></li> {% block object-tools-items %} {% if has_add_permission %} <li> <a href="{% url cl.opts|admin_urlname:'add' %}{% if is_popup %}?_popup=1{% endif %}" class="addlink"> {% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %} </a> </li> {% endif %} {% endblock %} </ul> {% endblock %}
This way an empty UL will not be created. Of-course the first LI can also be configured through relative CSS class.
comment:4 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 11 years ago
a pull request has been done from https://github.com/ikks/django/tree/ticket_19536 , added a test to make sure it works as expected.
comment:7 by , 11 years ago
Easy pickings: | unset |
---|
comment:9 by , 9 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
Triage Stage: | Accepted → Ready for checkin |
The patch looks good to me.
comment:10 by , 9 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
Left some minor comments.
patch for ModelAdmin has_add_permission disabling all the object-tools-items