mirror of https://github.com/django/django.git
Fixed #19536 -- Included object-tools when ModelAdmin.has_add_permission() is False.
This commit is contained in:
parent
d9e150b311
commit
ff19df9c2d
|
@ -40,18 +40,18 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div id="content-main">
|
<div id="content-main">
|
||||||
{% block object-tools %}
|
{% block object-tools %}
|
||||||
{% if has_add_permission %}
|
|
||||||
<ul class="object-tools">
|
<ul class="object-tools">
|
||||||
{% block object-tools-items %}
|
{% block object-tools-items %}
|
||||||
|
{% if has_add_permission %}
|
||||||
<li>
|
<li>
|
||||||
{% url cl.opts|admin_urlname:'add' as add_url %}
|
{% url cl.opts|admin_urlname:'add' as add_url %}
|
||||||
<a href="{% add_preserved_filters add_url is_popup to_field %}" class="addlink">
|
<a href="{% add_preserved_filters add_url is_popup to_field %}" class="addlink">
|
||||||
{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
|
{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% if cl.formset.errors %}
|
{% if cl.formset.errors %}
|
||||||
<p class="errornote">
|
<p class="errornote">
|
||||||
|
|
|
@ -47,6 +47,10 @@ Minor features
|
||||||
classes on inline fieldsets. Inlines with a ``collapse`` class will be
|
classes on inline fieldsets. Inlines with a ``collapse`` class will be
|
||||||
initially collapsed and their header will have a small "show" link.
|
initially collapsed and their header will have a small "show" link.
|
||||||
|
|
||||||
|
* If a user doesn't have the add permission, the ``object-tools`` block on a
|
||||||
|
model's changelist will now be rendered (without the add button, of course).
|
||||||
|
This makes it easier to add custom tools in this case.
|
||||||
|
|
||||||
:mod:`django.contrib.admindocs`
|
:mod:`django.contrib.admindocs`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,9 @@ class EventAdmin(admin.ModelAdmin):
|
||||||
def event_date_func(self, event):
|
def event_date_func(self, event):
|
||||||
return event.date
|
return event.date
|
||||||
|
|
||||||
|
def has_add_permission(self, request):
|
||||||
|
return False
|
||||||
|
|
||||||
site.register(Event, EventAdmin)
|
site.register(Event, EventAdmin)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,10 @@ from .admin import (
|
||||||
BandAdmin, ChildAdmin, ChordsBandAdmin, ConcertAdmin,
|
BandAdmin, ChildAdmin, ChordsBandAdmin, ConcertAdmin,
|
||||||
CustomPaginationAdmin, CustomPaginator, DynamicListDisplayChildAdmin,
|
CustomPaginationAdmin, CustomPaginator, DynamicListDisplayChildAdmin,
|
||||||
DynamicListDisplayLinksChildAdmin, DynamicListFilterChildAdmin,
|
DynamicListDisplayLinksChildAdmin, DynamicListFilterChildAdmin,
|
||||||
DynamicSearchFieldsChildAdmin, EmptyValueChildAdmin, FilteredChildAdmin,
|
DynamicSearchFieldsChildAdmin, EmptyValueChildAdmin, EventAdmin,
|
||||||
GroupAdmin, InvitationAdmin, NoListDisplayLinksParentAdmin, ParentAdmin,
|
FilteredChildAdmin, GroupAdmin, InvitationAdmin,
|
||||||
QuartetAdmin, SwallowAdmin, site as custom_site,
|
NoListDisplayLinksParentAdmin, ParentAdmin, QuartetAdmin, SwallowAdmin,
|
||||||
|
site as custom_site,
|
||||||
)
|
)
|
||||||
from .models import (
|
from .models import (
|
||||||
Band, Child, ChordsBand, ChordsMusician, Concert, CustomIdUser, Event,
|
Band, Child, ChordsBand, ChordsMusician, Concert, CustomIdUser, Event,
|
||||||
|
@ -761,6 +762,20 @@ class ChangeListTests(TestCase):
|
||||||
list(real_page_range),
|
list(real_page_range),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_object_tools_displayed_no_add_permission(self):
|
||||||
|
"""
|
||||||
|
When ModelAdmin.has_add_permission() returns False, the object-tools
|
||||||
|
block is still shown.
|
||||||
|
"""
|
||||||
|
superuser = self._create_superuser('superuser')
|
||||||
|
m = EventAdmin(Event, custom_site)
|
||||||
|
request = self._mocked_authenticated_request('/event/', superuser)
|
||||||
|
self.assertFalse(m.has_add_permission(request))
|
||||||
|
response = m.changelist_view(request)
|
||||||
|
self.assertIn('<ul class="object-tools">', response.rendered_content)
|
||||||
|
# The "Add" button inside the object-tools shouldn't appear.
|
||||||
|
self.assertNotIn('Add', response.rendered_content)
|
||||||
|
|
||||||
|
|
||||||
class AdminLogNodeTestCase(TestCase):
|
class AdminLogNodeTestCase(TestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue