Kaydet (Commit) b387189d authored tarafından Stanislav Karpov's avatar Stanislav Karpov Kaydeden (comit) Tim Graham

Fixed #26919 -- Added the action form's media in the changelist view.

üst b785927b
......@@ -1642,6 +1642,7 @@ class ModelAdmin(BaseModelAdmin):
if actions:
action_form = self.action_form(auto_id=None)
action_form.fields['action'].choices = self.get_action_choices(request)
media += action_form.media
else:
action_form = None
......
......@@ -22,6 +22,7 @@ from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.six import StringIO
from .forms import MediaActionForm
from .models import (
Actor, AdminOrderedAdminMethod, AdminOrderedCallable, AdminOrderedField,
AdminOrderedModelMethod, Album, Answer, Article, BarAccount, Book,
......@@ -235,6 +236,7 @@ class PersonaAdmin(admin.ModelAdmin):
class SubscriberAdmin(admin.ModelAdmin):
actions = ['mail_admin']
action_form = MediaActionForm
def mail_admin(self, request, selected):
EmailMessage(
......
from django import forms
from django.contrib.admin.forms import AdminAuthenticationForm
from django.contrib.admin.helpers import ActionForm
class CustomAdminAuthenticationForm(AdminAuthenticationForm):
......@@ -12,3 +13,8 @@ class CustomAdminAuthenticationForm(AdminAuthenticationForm):
if username == 'customform':
raise forms.ValidationError('custom form error')
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 .admin import CityAdmin, site, site2
from .forms import MediaActionForm
from .models import (
Actor, AdminOrderedAdminMethod, AdminOrderedCallable, AdminOrderedField,
AdminOrderedModelMethod, Answer, Article, BarAccount, Book, Bookmark,
......@@ -3374,6 +3375,17 @@ action)</option>
self.assertEqual(len(mail.outbox), 1)
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):
"""
User should see a warning when 'Go' is pressed and no items are selected.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment