From d14afdc2c38f116a12b1a456f7d1ca1db2c38d5d Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Thu, 31 May 2018 18:46:56 +0100 Subject: [PATCH] Ensure that group add/edit forms import form media js/css --- .../templates/wagtailusers/groups/create.html | 1 + .../templates/wagtailusers/groups/edit.html | 1 + .../groups/includes/group_form_js.html | 2 ++ wagtail/users/views/groups.py | 22 +++++++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/wagtail/users/templates/wagtailusers/groups/create.html b/wagtail/users/templates/wagtailusers/groups/create.html index 4557504bb5..2eec897669 100644 --- a/wagtail/users/templates/wagtailusers/groups/create.html +++ b/wagtail/users/templates/wagtailusers/groups/create.html @@ -7,6 +7,7 @@ {{ block.super }} + {{ form_media.css }} {% endblock %} {% block content %} diff --git a/wagtail/users/templates/wagtailusers/groups/edit.html b/wagtail/users/templates/wagtailusers/groups/edit.html index 714891e7c2..9ed29333aa 100644 --- a/wagtail/users/templates/wagtailusers/groups/edit.html +++ b/wagtail/users/templates/wagtailusers/groups/edit.html @@ -7,6 +7,7 @@ {{ block.super }} + {{ form_media.css }} {% endblock %} {% block content %} diff --git a/wagtail/users/templates/wagtailusers/groups/includes/group_form_js.html b/wagtail/users/templates/wagtailusers/groups/includes/group_form_js.html index 0a1f04c8be..576ef4ada9 100644 --- a/wagtail/users/templates/wagtailusers/groups/includes/group_form_js.html +++ b/wagtail/users/templates/wagtailusers/groups/includes/group_form_js.html @@ -9,3 +9,5 @@ + +{{ form_media.js }} diff --git a/wagtail/users/views/groups.py b/wagtail/users/views/groups.py index 62be676a6b..b6a3abf56d 100644 --- a/wagtail/users/views/groups.py +++ b/wagtail/users/views/groups.py @@ -89,6 +89,17 @@ class CreateView(PermissionPanelFormsMixin, generic.CreateView): else: return self.form_invalid(form) + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + # add a 'form_media' variable for the collected js/css media from the form and all formsets + form_media = context['form'].media + for panel in context['permission_panels']: + form_media += panel.media + context['form_media'] = form_media + + return context + class EditView(PermissionPanelFormsMixin, generic.EditView): success_message = _("Group '{0}' updated.") @@ -116,6 +127,17 @@ class EditView(PermissionPanelFormsMixin, generic.EditView): else: return self.form_invalid(form) + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + # add a 'form_media' variable for the collected js/css media from the form and all formsets + form_media = context['form'].media + for panel in context['permission_panels']: + form_media += panel.media + context['form_media'] = form_media + + return context + class DeleteView(generic.DeleteView): success_message = _("Group '{0}' deleted.")