|
1 | 1 | from typing import TYPE_CHECKING
|
2 | 2 |
|
3 | 3 | from bolt.db import models
|
4 |
| -from bolt.http import HttpResponse |
| 4 | +from bolt.http import HttpResponse, HttpResponseRedirect |
5 | 5 | from bolt.paginator import Paginator
|
6 | 6 | from bolt.urls import reverse
|
7 | 7 | from bolt.utils.text import slugify
|
@@ -117,8 +117,8 @@ def render_card(self, card: "Card"):
|
117 | 117 |
|
118 | 118 | class AdminListView(AdminView):
|
119 | 119 | template_name = "admin/list.html"
|
120 |
| - fields: list |
121 |
| - actions: dict[str] = {} |
| 120 | + fields: list[str] |
| 121 | + actions: list[str] = [] |
122 | 122 | filters: list[str] = []
|
123 | 123 | page_size = 100
|
124 | 124 | show_search = False
|
@@ -154,16 +154,23 @@ def get_context(self):
|
154 | 154 | return context
|
155 | 155 |
|
156 | 156 | def post(self) -> HttpResponse:
|
157 |
| - action_key = self.request.POST.get("action_key") |
| 157 | + # won't be "key" anymore, just list |
| 158 | + action_name = self.request.POST.get("action_name") |
158 | 159 | actions = self.get_actions()
|
159 |
| - if action_key and action_key in actions: |
160 |
| - action_callable = actions[action_key] |
161 |
| - if isinstance(action_callable, str): |
162 |
| - action_callable = getattr(self, action_callable) |
163 |
| - return action_callable(self.request.POST.getlist("action_pks")) |
| 160 | + if action_name and action_name in actions: |
| 161 | + target_pks = self.request.POST["action_pks"].split(",") |
| 162 | + response = self.perform_action(action_name, target_pks) |
| 163 | + if response: |
| 164 | + return response |
| 165 | + else: |
| 166 | + # message in session first |
| 167 | + return HttpResponseRedirect(".") |
164 | 168 |
|
165 | 169 | raise ValueError("Invalid action")
|
166 | 170 |
|
| 171 | + def perform_action(self, action: str, target_pks: list) -> HttpResponse | None: |
| 172 | + raise NotImplementedError |
| 173 | + |
167 | 174 | def get_objects(self) -> list:
|
168 | 175 | return []
|
169 | 176 |
|
|
0 commit comments