0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Consistently use create_form and search_form as context variables

This commit is contained in:
Matt Westcott 2021-12-07 21:51:49 +00:00 committed by LB (Ben Johnston)
parent 05fdea0394
commit ef31e160d9
5 changed files with 31 additions and 31 deletions

View File

@ -12,8 +12,8 @@
<div class="tab-content">
{% if can_create %}
<section id="new" class="active nice-padding">
{% if createform %}
{% include "wagtailadmin/workflows/task_chooser/includes/create_form.html" with form=createform %}
{% if create_form %}
{% include "wagtailadmin/workflows/task_chooser/includes/create_form.html" %}
{% else %}
{% include "wagtailadmin/workflows/task_chooser/includes/select_task_type.html" %}
{% endif %}
@ -22,7 +22,7 @@
<section id="existing" class="nice-padding{% if not can_create %} active{% endif %}">
<form class="task-search search-bar" action="{% url 'wagtailadmin_workflows:task_chooser_results' %}" method="GET" novalidate>
<ul class="fields">
{% for field in searchform %}
{% for field in search_form %}
{% include "wagtailadmin/shared/field_as_li.html" with field=field %}
{% endfor %}
</ul>

View File

@ -1,7 +1,7 @@
{% load i18n wagtailadmin_tags %}
{{ form.media.css }}
{{ form.media.js }}
{{ create_form.media.css }}
{{ create_form.media.js }}
{% if task_types|length > 1 %}
<a href="{% url 'wagtailadmin_workflows:task_chooser_create' %}" class="choose-different-task-type">{% trans "Choose a different task type" %}</a>
@ -11,7 +11,7 @@
{% csrf_token %}
<ul class="fields">
{% for field in form %}
{% for field in create_form %}
{% if field.is_hidden %}
{{ field }}
{% else %}

View File

@ -1,6 +1,6 @@
{% load i18n wagtailadmin_tags %}
{% if tasks %}
{% if searchform.is_searching %}
{% if search_form.is_searching %}
<h2 role="alert">
{% blocktrans count counter=tasks.paginator.count %}
There is {{ counter }} match
@ -18,7 +18,7 @@
<th>
{% trans "Name" %}
</th>
{% if searchform.specific_task_model_selected %}
{% if search_form.specific_task_model_selected %}
{# TODO #}
{% else %}
<th>
@ -36,7 +36,7 @@
<td class="title">
<div class="title-wrapper"><a href="{% url 'wagtailadmin_workflows:task_chosen' task.id %}" class="task-choice">{{ task.name }}</a></div>
</td>
{% if searchform.specific_task_model_selected %}
{% if search_form.specific_task_model_selected %}
{# TODO #}
{% else %}
<td>

View File

@ -1606,7 +1606,7 @@ class TestTaskChooserView(TestCase, WagtailTestUtils):
self.assertTemplateUsed(response, "wagtailadmin/workflows/task_chooser/includes/select_task_type.html")
self.assertTemplateUsed(response, "wagtailadmin/workflows/task_chooser/includes/results.html")
self.assertTemplateNotUsed(response, "wagtailadmin/workflows/task_chooser/includes/create_form.html")
self.assertFalse(response.context['searchform'].is_searching())
self.assertFalse(response.context['search_form'].is_searching())
# check that only active (non-disabled) tasks are listed
self.assertEqual([task.name for task in response.context['tasks'].object_list], ['Enabled foo', 'Moderators approval'])
@ -1617,7 +1617,7 @@ class TestTaskChooserView(TestCase, WagtailTestUtils):
self.assertTemplateUsed(response, "wagtailadmin/workflows/task_chooser/includes/results.html")
self.assertTemplateNotUsed(response, "wagtailadmin/workflows/task_chooser/chooser.html")
self.assertTrue(response.context['searchform'].is_searching())
self.assertTrue(response.context['search_form'].is_searching())
self.assertEqual(response.context['query_string'], 'foo')
# check that only active (non-disabled) tasks are listed
self.assertEqual([task.name for task in response.context['tasks'].object_list], ['Enabled foo'])
@ -1630,7 +1630,7 @@ class TestTaskChooserView(TestCase, WagtailTestUtils):
# When pagination is used, only the results template should be rendered
self.assertTemplateUsed(response, "wagtailadmin/workflows/task_chooser/includes/results.html")
self.assertTemplateNotUsed(response, "wagtailadmin/workflows/task_chooser/chooser.html")
self.assertFalse(response.context['searchform'].is_searching())
self.assertFalse(response.context['search_form'].is_searching())
def test_get_with_create_model_selected(self):
response = self.client.get(reverse('wagtailadmin_workflows:task_chooser_create') + '?create_model=wagtailcore.GroupApprovalTask')

View File

@ -572,28 +572,28 @@ class TaskChooserView(BaseTaskChooserView):
def get(self, request):
create_form_class = self.get_create_form_class()
if create_form_class:
self.createform = create_form_class(prefix='create-task')
self.create_form = create_form_class(prefix='create-task')
else:
self.createform = None
self.create_form = None
return self.render_to_response()
def render_to_response(self):
searchform = TaskChooserSearchForm(task_type_choices=self.get_task_type_filter_choices())
tasks = searchform.task_model.objects.filter(active=True).order_by(Lower('name'))
search_form = TaskChooserSearchForm(task_type_choices=self.get_task_type_filter_choices())
tasks = search_form.task_model.objects.filter(active=True).order_by(Lower('name'))
paginator = Paginator(tasks, per_page=10)
tasks = paginator.get_page(self.request.GET.get('p'))
chooser_html_context = {
'tasks': tasks,
'searchform': searchform,
'createform': self.createform,
'search_form': search_form,
'create_form': self.create_form,
'can_create': self.can_create,
'add_url': reverse('wagtailadmin_workflows:task_chooser_create') + '?' + self.request.GET.urlencode() if self.create_model else None
}
if not self.createform:
if not self.create_form:
chooser_html_context['task_types'] = self.get_task_type_options()
js_context = self.get_form_js_context()
@ -609,9 +609,9 @@ class TaskChooserCreateView(BaseTaskChooserView):
def get(self, request):
create_form_class = self.get_create_form_class()
if create_form_class:
self.createform = create_form_class(prefix='create-task')
self.create_form = create_form_class(prefix='create-task')
else:
self.createform = None
self.create_form = None
return self.render_to_response()
@ -620,18 +620,18 @@ class TaskChooserCreateView(BaseTaskChooserView):
if not create_form_class:
return HttpResponseBadRequest()
self.createform = create_form_class(request.POST, request.FILES, prefix='create-task')
self.create_form = create_form_class(request.POST, request.FILES, prefix='create-task')
if self.createform.is_valid():
task = self.createform.save()
if self.create_form.is_valid():
task = self.create_form.save()
return get_task_chosen_response(request, task)
else:
return self.render_to_response()
def render_to_response(self):
if self.createform:
if self.create_form:
tab_html = render_to_string("wagtailadmin/workflows/task_chooser/includes/create_form.html", {
'form': self.createform,
'create_form': self.create_form,
'add_url': reverse('wagtailadmin_workflows:task_chooser_create') + '?' + self.request.GET.urlencode() if self.create_model else None,
'task_types': self.get_task_type_options(),
}, self.request)
@ -652,17 +652,17 @@ class TaskChooserCreateView(BaseTaskChooserView):
class TaskChooserResultsView(BaseTaskChooserView):
def get(self, request):
searchform = TaskChooserSearchForm(request.GET, task_type_choices=self.get_task_type_filter_choices())
tasks = all_tasks = searchform.task_model.objects.filter(active=True).order_by(Lower('name'))
search_form = TaskChooserSearchForm(request.GET, task_type_choices=self.get_task_type_filter_choices())
tasks = all_tasks = search_form.task_model.objects.filter(active=True).order_by(Lower('name'))
q = ''
if searchform.is_searching():
if search_form.is_searching():
# Note: I decided not to use wagtailsearch here. This is because
# wagtailsearch creates a new index for each model you make
# searchable and this might affect someone's quota. I doubt there
# would ever be enough tasks to require using anything more than
# an icontains anyway.
q = searchform.cleaned_data['q']
q = search_form.cleaned_data['q']
tasks = tasks.filter(name__icontains=q)
# Pagination
@ -670,7 +670,7 @@ class TaskChooserResultsView(BaseTaskChooserView):
tasks = paginator.get_page(request.GET.get('p'))
return TemplateResponse(request, "wagtailadmin/workflows/task_chooser/includes/results.html", {
'searchform': searchform,
'search_form': search_form,
'tasks': tasks,
'all_tasks': all_tasks,
'query_string': q,