Fixed #26919 -- Added the action form's media in the changelist view.
This commit is contained in:
parent
b785927b44
commit
b387189d86
|
@ -1642,6 +1642,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||||
if actions:
|
if actions:
|
||||||
action_form = self.action_form(auto_id=None)
|
action_form = self.action_form(auto_id=None)
|
||||||
action_form.fields['action'].choices = self.get_action_choices(request)
|
action_form.fields['action'].choices = self.get_action_choices(request)
|
||||||
|
media += action_form.media
|
||||||
else:
|
else:
|
||||||
action_form = None
|
action_form = None
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ from django.utils.html import format_html
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.six import StringIO
|
from django.utils.six import StringIO
|
||||||
|
|
||||||
|
from .forms import MediaActionForm
|
||||||
from .models import (
|
from .models import (
|
||||||
Actor, AdminOrderedAdminMethod, AdminOrderedCallable, AdminOrderedField,
|
Actor, AdminOrderedAdminMethod, AdminOrderedCallable, AdminOrderedField,
|
||||||
AdminOrderedModelMethod, Album, Answer, Article, BarAccount, Book,
|
AdminOrderedModelMethod, Album, Answer, Article, BarAccount, Book,
|
||||||
|
@ -235,6 +236,7 @@ class PersonaAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
class SubscriberAdmin(admin.ModelAdmin):
|
class SubscriberAdmin(admin.ModelAdmin):
|
||||||
actions = ['mail_admin']
|
actions = ['mail_admin']
|
||||||
|
action_form = MediaActionForm
|
||||||
|
|
||||||
def mail_admin(self, request, selected):
|
def mail_admin(self, request, selected):
|
||||||
EmailMessage(
|
EmailMessage(
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.admin.forms import AdminAuthenticationForm
|
from django.contrib.admin.forms import AdminAuthenticationForm
|
||||||
|
from django.contrib.admin.helpers import ActionForm
|
||||||
|
|
||||||
|
|
||||||
class CustomAdminAuthenticationForm(AdminAuthenticationForm):
|
class CustomAdminAuthenticationForm(AdminAuthenticationForm):
|
||||||
|
@ -12,3 +13,8 @@ class CustomAdminAuthenticationForm(AdminAuthenticationForm):
|
||||||
if username == 'customform':
|
if username == 'customform':
|
||||||
raise forms.ValidationError('custom form error')
|
raise forms.ValidationError('custom form error')
|
||||||
return username
|
return username
|
||||||
|
|
||||||
|
|
||||||
|
class MediaActionForm(ActionForm):
|
||||||
|
class Media:
|
||||||
|
js = ['path/to/media.js']
|
||||||
|
|
|
@ -43,6 +43,7 @@ from django.utils.six.moves.urllib.parse import parse_qsl, urljoin, urlparse
|
||||||
|
|
||||||
from . import customadmin
|
from . import customadmin
|
||||||
from .admin import CityAdmin, site, site2
|
from .admin import CityAdmin, site, site2
|
||||||
|
from .forms import MediaActionForm
|
||||||
from .models import (
|
from .models import (
|
||||||
Actor, AdminOrderedAdminMethod, AdminOrderedCallable, AdminOrderedField,
|
Actor, AdminOrderedAdminMethod, AdminOrderedCallable, AdminOrderedField,
|
||||||
AdminOrderedModelMethod, Answer, Article, BarAccount, Book, Bookmark,
|
AdminOrderedModelMethod, Answer, Article, BarAccount, Book, Bookmark,
|
||||||
|
@ -3374,6 +3375,17 @@ action)</option>
|
||||||
self.assertEqual(len(mail.outbox), 1)
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
self.assertEqual(mail.outbox[0].subject, 'Greetings from a function action')
|
self.assertEqual(mail.outbox[0].subject, 'Greetings from a function action')
|
||||||
|
|
||||||
|
def test_media_from_actions_form(self):
|
||||||
|
"""
|
||||||
|
The action form's media is included in changelist view's media.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse('admin:admin_views_subscriber_changelist'))
|
||||||
|
media_path = MediaActionForm.Media.js[0]
|
||||||
|
self.assertIsInstance(response.context['action_form'], MediaActionForm)
|
||||||
|
self.assertIn('media', response.context)
|
||||||
|
self.assertIn(media_path, response.context['media']._js)
|
||||||
|
self.assertContains(response, media_path)
|
||||||
|
|
||||||
def test_user_message_on_none_selected(self):
|
def test_user_message_on_none_selected(self):
|
||||||
"""
|
"""
|
||||||
User should see a warning when 'Go' is pressed and no items are selected.
|
User should see a warning when 'Go' is pressed and no items are selected.
|
||||||
|
|
Loading…
Reference in New Issue