Skip to content

Commit

Permalink
WIP bnzk#28
Browse files Browse the repository at this point in the history
  • Loading branch information
benzkji committed Oct 15, 2022
1 parent 960374e commit 1af3a46
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
7 changes: 6 additions & 1 deletion painless_redirects/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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]:
Expand All @@ -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"

Expand Down
21 changes: 15 additions & 6 deletions painless_redirects/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 1af3a46

Please sign in to comment.