3
3
from django .contrib import messages
4
4
from django .contrib .auth .mixins import LoginRequiredMixin
5
5
from django .db .models import Q
6
- from django .http .response import HttpResponseRedirect
6
+ from django .http .response import Http404 , HttpResponseRedirect
7
7
from django .urls .base import reverse , reverse_lazy
8
8
from django .utils .functional import cached_property
9
9
from django .utils .translation import gettext as _
16
16
from view_breadcrumbs import BaseBreadcrumbMixin
17
17
18
18
from open_inwoner .components .utils import RenderableTag
19
+ from open_inwoner .configurations .models import SiteConfiguration
19
20
from open_inwoner .htmx .views import HtmxTemplateTagModelFormView
20
21
from open_inwoner .utils .logentry import get_change_message
21
22
from open_inwoner .utils .mixins import ExportMixin
25
26
from ..models import Action
26
27
27
28
29
+ class ActionsEnabledMixin :
30
+ def dispatch (self , request , * args , ** kwargs ):
31
+ config = SiteConfiguration .get_solo ()
32
+ if not config .show_actions :
33
+ raise Http404 ("actions not enabled" )
34
+ return super ().dispatch (request , * args , ** kwargs )
35
+
36
+
28
37
class BaseActionFilter :
29
38
"""
30
39
For when in the template the action tag is used. This will filter the actions correctly.
@@ -44,7 +53,11 @@ def get_actions(self, actions):
44
53
45
54
46
55
class ActionListView (
47
- LoginRequiredMixin , BaseBreadcrumbMixin , BaseActionFilter , ListView
56
+ ActionsEnabledMixin ,
57
+ LoginRequiredMixin ,
58
+ BaseBreadcrumbMixin ,
59
+ BaseActionFilter ,
60
+ ListView ,
48
61
):
49
62
template_name = "pages/profile/actions/list.html"
50
63
model = Action
@@ -78,7 +91,9 @@ def get_context_data(self, **kwargs):
78
91
return context
79
92
80
93
81
- class ActionUpdateView (LogMixin , LoginRequiredMixin , BaseBreadcrumbMixin , UpdateView ):
94
+ class ActionUpdateView (
95
+ ActionsEnabledMixin , LogMixin , LoginRequiredMixin , BaseBreadcrumbMixin , UpdateView
96
+ ):
82
97
template_name = "pages/profile/actions/edit.html"
83
98
model = Action
84
99
slug_field = "uuid"
@@ -149,7 +164,12 @@ def form_valid(self, form):
149
164
150
165
151
166
class ActionDeleteView (
152
- LogMixin , LoginRequiredMixin , DeletionMixin , SingleObjectMixin , View
167
+ ActionsEnabledMixin ,
168
+ LogMixin ,
169
+ LoginRequiredMixin ,
170
+ DeletionMixin ,
171
+ SingleObjectMixin ,
172
+ View ,
153
173
):
154
174
model = Action
155
175
slug_field = "uuid"
@@ -183,7 +203,9 @@ def on_delete_action(self, action):
183
203
)
184
204
185
205
186
- class ActionCreateView (LogMixin , LoginRequiredMixin , BaseBreadcrumbMixin , CreateView ):
206
+ class ActionCreateView (
207
+ ActionsEnabledMixin , LogMixin , LoginRequiredMixin , BaseBreadcrumbMixin , CreateView
208
+ ):
187
209
template_name = "pages/profile/actions/edit.html"
188
210
model = Action
189
211
form_class = ActionForm
@@ -212,7 +234,9 @@ def form_valid(self, form):
212
234
return HttpResponseRedirect (self .get_success_url ())
213
235
214
236
215
- class ActionListExportView (LogMixin , LoginRequiredMixin , ExportMixin , ListView ):
237
+ class ActionListExportView (
238
+ ActionsEnabledMixin , LogMixin , LoginRequiredMixin , ExportMixin , ListView
239
+ ):
216
240
template_name = "export/profile/action_list_export.html"
217
241
model = Action
218
242
@@ -228,7 +252,9 @@ def get_queryset(self):
228
252
)
229
253
230
254
231
- class ActionExportView (LogMixin , LoginRequiredMixin , ExportMixin , DetailView ):
255
+ class ActionExportView (
256
+ ActionsEnabledMixin , LogMixin , LoginRequiredMixin , ExportMixin , DetailView
257
+ ):
232
258
template_name = "export/profile/action_export.html"
233
259
model = Action
234
260
slug_field = "uuid"
@@ -241,7 +267,9 @@ def get_queryset(self):
241
267
)
242
268
243
269
244
- class ActionPrivateMediaView (LogMixin , LoginRequiredMixin , PrivateMediaView ):
270
+ class ActionPrivateMediaView (
271
+ ActionsEnabledMixin , LogMixin , LoginRequiredMixin , PrivateMediaView
272
+ ):
245
273
model = Action
246
274
slug_field = "uuid"
247
275
slug_url_kwarg = "uuid"
@@ -262,7 +290,9 @@ def has_permission(self):
262
290
return False
263
291
264
292
265
- class ActionHistoryView (LoginRequiredMixin , BaseBreadcrumbMixin , DetailView ):
293
+ class ActionHistoryView (
294
+ ActionsEnabledMixin , LoginRequiredMixin , BaseBreadcrumbMixin , DetailView
295
+ ):
266
296
template_name = "pages/history.html"
267
297
model = Action
268
298
slug_field = "uuid"
0 commit comments