Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement bulk actions for form submissions #11847

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions wagtail/contrib/forms/bulk_actions/delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext

from wagtail.contrib.forms.bulk_actions.form_bulk_action import FormSubmissionBulkAction
from wagtail.contrib.forms.utils import get_forms_for_user


class DeleteBulkAction(FormSubmissionBulkAction):
display_name = _("Delete")
aria_label = _("Delete selected objects")
action_type = "delete"
template_name = "bulk_actions/confirm_bulk_delete.html"

def check_perm(self, obj):
return get_forms_for_user(self.request.user).exists()

@classmethod
def execute_action(cls, objects, **kwargs):
num_forms = 0
for obj in objects:
num_forms = num_forms + 1
obj.delete()
return num_forms, 0

def get_success_message(self, count, num_child_objects):

return ngettext(
"One submission has been deleted.",
"%(count)d submissions have been deleted.",
count,
) % {"count": count}
10 changes: 10 additions & 0 deletions wagtail/contrib/forms/bulk_actions/form_bulk_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from wagtail.admin.views.bulk_action import BulkAction
from wagtail.contrib.forms.models import FormSubmission


class FormSubmissionBulkAction(BulkAction):
models = [FormSubmission]

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
return context
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% extends 'wagtailadmin/bulk_actions/confirmation/base.html' %}
{% load i18n wagtailadmin_tags %}

{% block titletag %}{% blocktrans count counter=items|length %}Delete 1 item{% plural %}Delete {{ counter }} items{% endblocktrans %}{% endblock %}

{% block header %}
{% trans "Delete" as del_str %}
{% include "wagtailadmin/shared/header.html" with title=del_str icon="doc-empty-inverse" %}
{% endblock header %}


{% block items_with_access %}
{% if items %}
<p>
{% blocktrans trimmed count counter=items|length %}
Are you sure you want to delete this form submission?
{% plural %}
Are you sure you want to delete these form submissions?
{% endblocktrans %}
</p>

{% include 'bulk_actions/list_form_submissions.html' %}
{% endif %}
{% endblock items_with_access %}

{% block items_with_no_access %}

{% blocktranslate trimmed asvar no_access_msg count counter=items_with_no_access|length %}You don't have permission to delete this item{% plural %}You don't have permission to delete these items{% endblocktranslate %}
{% include 'bulk_actions/list_items_with_no_access.html' with items=items_with_no_access %}

{% endblock items_with_no_access %}

{% block form_section %}
{% if items %}
{% trans 'Yes, delete' as action_button_text %}
{% trans "No, don't delete" as no_action_button_text %}
{% include 'wagtailadmin/bulk_actions/confirmation/form.html' with action_button_class="serious" %}
{% else %}
{% include 'wagtailadmin/bulk_actions/confirmation/go_back.html' %}
{% endif %}
{% endblock form_section %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% load i18n %}
<table class="listing">
<thead>
<tr>
<th id="submit_time" class="">
Submission date
</th>
{% for heading in data_headings %}
<th>
{{ heading.name }}
</th>
{% endfor %}
</tr>
</thead>
{% for item in items %}
<tbody>
<tr>
<td>
{{item.item.submit_time}}
</td>
{% for label,data in item.item.form_data.items %}
<td>
{{ data }}
</td>
{% endfor %}
</tr>
</tbody>
{% endfor %}
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends 'wagtailadmin/bulk_actions/confirmation/list_items_with_no_access.html' %}
{% load i18n wagtailadmin_tags %}

{% block per_item %}
{{ item }}
{% endblock per_item %}
23 changes: 0 additions & 23 deletions wagtail/contrib/forms/templates/wagtailforms/confirm_delete.html
Original file line number Diff line number Diff line change
@@ -1,23 +0,0 @@
{% extends "wagtailadmin/base.html" %}
{% load i18n %}
{% block titletag %}{% blocktrans trimmed with title=page.title %}Delete form data {{ title }}{% endblocktrans %}{% endblock %}
{% block bodyclass %}menu-explorer{% endblock %}

{% block content %}
{% trans "Delete form data" as del_str %}
{% include "wagtailadmin/shared/header.html" with title=del_str subtitle=page.title icon="doc-empty-inverse" %}

<div class="nice-padding">
<p>
{% blocktrans trimmed count counter=submissions.count %}
Are you sure you want to delete this form submission?
{% plural %}
Are you sure you want to delete these form submissions?
{% endblocktrans %}
</p>
<form action="{% url 'wagtailforms:delete_submissions' page.id %}?{{ request.GET.urlencode }}" method="POST">
{% csrf_token %}
<input type="submit" value="{% trans 'Delete' %}" class="button serious">
</form>
</div>
{% endblock %}
21 changes: 11 additions & 10 deletions wagtail/contrib/forms/templates/wagtailforms/list_submissions.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{% extends "wagtailadmin/generic/index_results.html" %}
{% load i18n %}
{% load i18n l10n wagtailadmin_tags %}
{% block results %}
<form class="w-overflow-auto" data-controller="w-bulk" data-w-bulk-action-inactive-class="w-invisible" action="{% url 'wagtailforms:delete_submissions' form_page.id %}" method="get">
<form class="w-overflow-auto" data-controller="w-bulk" data-w-bulk-action-inactive-class="w-invisible">
<table class="listing">
<col />
<col />
<col />
<thead>
<tr>
<th><input type="checkbox" data-action="w-bulk#toggleAll" data-w-bulk-target="all" /></th>
{% include 'wagtailadmin/bulk_actions/select_all_checkbox_cell.html' %}
{% for heading in data_headings %}
<th id="{{ heading.name }}" class="{% if heading.order %}ordered icon {% if heading.order == 'ascending' %}icon-arrow-up-after{% else %}icon-arrow-down-after{% endif %}{% endif %}">
{% if heading.order %}<a href="?order_by={% if heading.order == 'ascending' %}-{% endif %}{{ heading.name }}">{{ heading.label }}</a>{% else %}{{ heading.label }}{% endif %}
Expand All @@ -17,10 +17,16 @@
</tr>
</thead>
<tbody>
{% trans "Select response" as checkbox_aria_label %}
{% for row in data_rows %}
<tr>
<td>
<input type="checkbox" name="selected-submissions" class="select-submission" value="{{ row.model_id }}" data-action="w-bulk#toggle" data-w-bulk-target="item" />
<td class="bulk-action-checkbox-cell">
<input type="checkbox"
{% if obj_type == 'data_rows' %}data-page-status="{% if instance.live %}live{% else %}draft{% endif %}"{% endif %}
data-object-id="{{ row.id|unlocalize|admin_urlquote }}" data-bulk-action-checkbox class="bulk-action-checkbox"
aria-label="{% trans "Select" %}"
{% if aria_describedby %}aria-describedby="{{ aria_describedby }}"{% endif %}
/>
</td>
{% for cell in row.fields %}
<td>
Expand All @@ -31,11 +37,6 @@
{% endfor %}
</tbody>
</table>
<div class="nice-padding">
<button class="button no w-invisible" data-w-bulk-target="action">
{% trans "Delete selected submissions" %}
</button>
</div>
</form>
{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
{% extends "wagtailadmin/generic/listing.html" %}
{% load i18n %}
{% load i18n wagtailadmin_tags %}
{% block titletag %}{% blocktrans trimmed with form_title=form_page.title|capfirst %}Submissions of {{ form_title }}{% endblocktrans %}{% endblock %}
{% block extra_js %}
<script>
window.wagtailConfig.BULK_ACTION_ITEM_TYPE = 'SNIPPET';
</script>
<script defer src="{% versioned_static 'wagtailadmin/js/bulk-actions.js' %}"></script>
{{ block.super }}
{% endblock %}

{% block bulk_actions %}
{% trans "Select all documents in listing" as select_all_text %}
{% include 'wagtailadmin/bulk_actions/footer.html' with select_all_obj_text=select_all_text app_label=app_label model_name=model_name objects=data_rows %}
{% endblock %}