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

[refactor] Fix linting issues

This commit is contained in:
Shohan 2021-06-23 19:00:23 +05:30 committed by Matt Westcott
parent 8de4b23f38
commit 693471a942
12 changed files with 29 additions and 31 deletions

View File

@ -516,7 +516,7 @@ def page_bulk_action_choices(context, page):
bulk_actions_list = hook(context.request, bulk_actions_list)
bulk_actions_list.sort(key=lambda x: x.action_priority)
bulk_action_buttons = [
PageListingButton(
action.display_name,

View File

@ -258,7 +258,7 @@ class TestBulkDelete(TestCase, WagtailTestUtils):
self.assertEqual(response.status_code, 302)
def test_before_delete_page_hook(self):
def hook_func(request, action_type, pages, action_class_instance):
self.assertEqual(action_type, 'delete')
self.assertIsInstance(request, HttpRequest)
@ -294,7 +294,6 @@ class TestBulkDelete(TestCase, WagtailTestUtils):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b"Overridden!")
# Check that the child pages to be deleted are gone
for child_page in self.pages_to_be_deleted:
self.assertFalse(SimplePage.objects.filter(id=child_page.id).exists())

View File

@ -91,7 +91,7 @@ class TestBulkMove(TestCase, WagtailTestUtils):
# Get move page
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
html = response.content.decode()
@ -130,7 +130,7 @@ class TestBulkMove(TestCase, WagtailTestUtils):
self.root_page.add_child(instance=page)
response = self.client.post(self.url, {'chooser': page.id})
html = response.content.decode()
self.assertInHTML('<span>The following pages cannot be moved to {}</span>'.format(page.title), html)
@ -153,7 +153,7 @@ class TestBulkMove(TestCase, WagtailTestUtils):
self.section_b.add_child(instance=temp_page_2)
response = self.client.post(self.url, {'chooser': self.section_b.id})
html = response.content.decode()
self.assertInHTML('<span>The following pages cannot be moved due to duplicate slugs</span>', html)
@ -169,7 +169,6 @@ class TestBulkMove(TestCase, WagtailTestUtils):
self.assertContains(response, '<input id="id_move_applicable" name="move_applicable" type="checkbox">')
def test_bulk_move_ignore_permission_errors(self):
temp_page_1 = SimplePage(title="Hello world!", slug="hello-world-b", content="hello")
temp_page_2 = SimplePage(title="Hello world!", slug="hello-world-b-1", content="hello")

View File

@ -1,9 +1,7 @@
from unittest import mock
from django.http.response import HttpResponse
from django.contrib.auth.models import Permission
from django.http import HttpRequest
from django.http import HttpRequest, HttpResponse
from django.test import TestCase
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
@ -120,7 +118,7 @@ class TestBulkPublish(TestCase, WagtailTestUtils):
self.assertIsInstance(mock_call['instance'], child_page.specific_class)
def test_after_publish_page(self):
def hook_func(request, action_type, pages, action_class_instance):
self.assertEqual(action_type, 'publish')
self.assertIsInstance(request, HttpRequest)
@ -141,7 +139,7 @@ class TestBulkPublish(TestCase, WagtailTestUtils):
self.assertEqual(child_page.status_string, _("live"))
def test_before_publish_page(self):
def hook_func(request, action_type, pages, action_class_instance):
self.assertEqual(action_type, 'publish')
self.assertIsInstance(request, HttpRequest)

View File

@ -1,9 +1,7 @@
from unittest import mock
from django.http.response import HttpResponse
from django.contrib.auth.models import Permission
from django.http import HttpRequest
from django.http import HttpRequest, HttpResponse
from django.test import TestCase
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
@ -113,7 +111,7 @@ class TestBulkUnpublish(TestCase, WagtailTestUtils):
# Check that the page_unpublished signal was fired
self.assertEqual(mock_handler.call_count, len(self.pages_to_be_unpublished))
for i, child_page in enumerate(self.pages_to_be_unpublished):
mock_call = mock_handler.mock_calls[i][2]
self.assertEqual(mock_call['sender'], child_page.specific_class)
@ -121,7 +119,7 @@ class TestBulkUnpublish(TestCase, WagtailTestUtils):
self.assertIsInstance(mock_call['instance'], child_page.specific_class)
def test_after_unpublish_page(self):
def hook_func(request, action_type, pages, action_class_instance):
self.assertEqual(action_type, 'unpublish')
self.assertIsInstance(request, HttpRequest)
@ -142,7 +140,7 @@ class TestBulkUnpublish(TestCase, WagtailTestUtils):
self.assertEqual(child_page.status_string, _("draft"))
def test_before_unpublish_page(self):
def hook_func(request, action_type, pages, action_class_instance):
self.assertEqual(action_type, 'unpublish')
self.assertIsInstance(request, HttpRequest)

View File

@ -12,14 +12,16 @@ from wagtail.core import hooks
class BulkAction(ABC, TemplateView):
@abstractproperty
def display_name(self): pass
def display_name(self):
pass
@abstractproperty
def action_type(self): pass
@abstractproperty
def aria_label(self): pass
def action_type(self):
pass
@abstractproperty
def aria_label(self):
pass
num_child_objects = 0
num_parent_objects = 0
@ -86,7 +88,7 @@ class BulkAction(ABC, TemplateView):
else:
objects.append(obj)
return objects, objects_with_no_access
def get_context_data(self, **kwargs):
objects, objects_with_no_access = self.get_actionable_objects()
_objects = []
@ -112,4 +114,4 @@ class BulkAction(ABC, TemplateView):
success_message = self.get_success_message()
if success_message is not None:
messages.success(request, success_message)
return redirect(self.next_url)
return redirect(self.next_url)

View File

@ -1,8 +1,8 @@
from .delete import delete
from .dispatcher import index
from .move import move
from .publish import publish
from .unpublish import unpublish
from .dispatcher import index
__all__ = ['index']
__all__ = ['delete', 'index', 'move', 'publish', 'unpublish']

View File

@ -55,4 +55,4 @@ class DeleteBulkAction(PageBulkAction):
@hooks.register('register_page_bulk_action')
def delete(request, parent_page_id):
return DeleteBulkAction(request, parent_page_id)
return DeleteBulkAction(request, parent_page_id)

View File

@ -10,5 +10,5 @@ def index(request, parent_page_id, action, rest=''):
if _action.action_type != action:
continue
return _action.dispatch(request, parent_page_id)
return Http404()

View File

@ -1,6 +1,7 @@
from wagtail.admin.views.bulk_action import BulkAction
from wagtail.core.models import Page
class PageBulkAction(BulkAction):
model = Page
object_key = 'page'

View File

@ -13,7 +13,7 @@ class PublishBulkAction(PageBulkAction):
def check_perm(self, page):
return page.permissions_for_user(self.request.user).can_publish()
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['has_draft_descendants'] = any(map(lambda x: x['page'].get_descendants().not_live().count(), context['pages']))

View File

@ -19,7 +19,7 @@ class UnpublishBulkAction(PageBulkAction):
**super().object_context(page),
'live_descendant_count': page.get_descendants().live().count(),
}
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['has_live_descendants'] = any(map(lambda x: x['live_descendant_count'] > 0, context['pages']))
@ -68,6 +68,7 @@ class UnpublishBulkAction(PageBulkAction):
success_message = _("%(num_parent_objects)d pages have been unpublished") % {'num_parent_objects': self.num_parent_objects}
return success_message
@hooks.register('register_page_bulk_action')
def unpublish(request, parent_page_id):
return UnpublishBulkAction(request, parent_page_id)