From 1af3a46245713144e795f19479109da982e5ca2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20St=C3=A4hli?= Date: Sat, 15 Oct 2022 15:01:07 +0200 Subject: [PATCH] WIP #28 --- painless_redirects/admin.py | 7 ++++++- painless_redirects/tests/test_admin.py | 21 +++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/painless_redirects/admin.py b/painless_redirects/admin.py index 4669b1b..78834bc 100644 --- a/painless_redirects/admin.py +++ b/painless_redirects/admin.py @@ -22,7 +22,7 @@ class RedirectAdmin(admin.ModelAdmin): search_fields = ['old_path', 'domain', 'new_path', ] list_display_links = [] list_display = ('old_loc', 'new_path', 'total_hits', 'enabled', 'permanent', 'ignored', 'auto_created',) - list_editable = ('enabled', 'ignored', 'new_path', 'permanent') + # list_editable = ('enabled', 'ignored', 'new_path', 'permanent') list_filter = [ 'enabled', 'ignored', @@ -67,7 +67,10 @@ def get_queryset(self, request): # https://stackoverflow.com/a/24799844/1029469 def changelist_view(self, request=None, extra_context=None): + print(request.POST) + print(request.method) if 'action' in request.POST and request.POST['action'] in self.actions: + print("asdvaisdvlaisdvlnasdnlvdasnil") if not request.POST.getlist(ACTION_CHECKBOX_NAME): post = request.POST.copy() for u in Redirect.objects.all()[:10]: @@ -76,6 +79,8 @@ def changelist_view(self, request=None, extra_context=None): return super().changelist_view(request, extra_context) def set_ignored(self, request, queryset): + print("set_ignrore") + print(queryset) queryset.update(ignored=True) set_ignored.short_description = "Ignore selected" diff --git a/painless_redirects/tests/test_admin.py b/painless_redirects/tests/test_admin.py index 31ac641..c2d977c 100644 --- a/painless_redirects/tests/test_admin.py +++ b/painless_redirects/tests/test_admin.py @@ -40,15 +40,24 @@ def test_basic_admin_change_view(self): response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) - def test_admin_action_ignor(self): + def test_admin_action_ignore(self): self.client.login(username=self.USER, password=self.PASSWORD) obj = Redirect.objects.create( old_path="/the-old-path/", new_path="/the-new-path/", ) url = reverse('admin:painless_redirects_redirect_changelist') - response = self.client.get(url, follow=True) - self.assertEqual(response.status_code, 200) - url = reverse('admin:painless_redirects_redirect_change', args=(obj.id, )) - response = self.client.get(url, follow=True) - self.assertEqual(response.status_code, 200) + data = { + # csrfmiddlewaretoken: xXBOESWn3YbibfJLW1Q1i348dUe0WDlYCf5JsXVoxbRkfGTJ9fkaHCG5dbDmNu9T + 'action': 'set_ignored', + 'select_across': 0, + 'index': 0, + '_selected_action': obj.id, + } + print(url) + print(data) + response = self.client.post(url, data, follow=False) + self.assertLess(response.status_code, 400) + print(response.content) + obj = Redirect.objects.get(pk=obj.id) + self.assertTrue(obj.ignored)