Skip to content

Commit c740468

Browse files
Julian Dehmm4ra
authored andcommitted
dashboard/mixins: change form_valid back to delete in
DashboardComponentDeleteSignalMixin and add documentation.
1 parent f9f4176 commit c740468

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

adhocracy4/dashboard/mixins.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from copy import deepcopy
23
from pathlib import Path
34

@@ -109,35 +110,67 @@ def get_context_data(self, **kwargs):
109110

110111

111112
class DashboardComponentFormSignalMixin(edit.FormMixin):
113+
"""Mixin which sends a project_component_updated or module_component_updated signal
114+
when creating, updating or deleting an object via the HTTP POST method
115+
(e.g. from the dashboard).
116+
"""
117+
112118
def form_valid(self, form):
119+
# The call to super.form_valid() may delete self.project or self.module,
120+
# to be able to still reference them below we need to store them in separate
121+
# variables before they are deleted.
122+
project = self.project
123+
module = self.module
124+
113125
response = super().form_valid(form)
114126

115127
component = self.component
116128
if component.identifier in components.projects:
117129
signals.project_component_updated.send(
118130
sender=component.__class__,
119-
project=self.project,
131+
project=project,
120132
component=component,
121133
user=self.request.user,
122134
)
123135
else:
124136
signals.module_component_updated.send(
125137
sender=component.__class__,
126-
module=self.module,
138+
module=module,
127139
component=component,
128140
user=self.request.user,
129141
)
130142
return response
131143

132144

133145
class DashboardComponentDeleteSignalMixin(edit.DeletionMixin):
134-
def form_valid(self, request, *args, **kwargs):
146+
"""Deprecated, use DashboardComponentFormSignalMixin for POST requests instead.
147+
This mixin will be removed in the next version.
148+
"""
149+
150+
def __init__(self):
151+
warnings.warn(
152+
"dashboard.mixins.DashboardComponentDeleteSignalMixin is deprecated, "
153+
"use dashboard.mixins.DashboardComponentFormSignalMixin for forms / POST "
154+
"requests. This mixin will be removed in the next version.",
155+
DeprecationWarning,
156+
)
157+
158+
super().__init__()
159+
160+
def delete(self, request, *args, **kwargs):
161+
warnings.warn(
162+
"dashboard.mixins.DashboardComponentDeleteSignalMixin.delete()"
163+
"is deprecated, use dashboard.mixins.DashboardComponentFormSignalMixin "
164+
"for forms / POST requests. This mixin will be removed in the next "
165+
"version.",
166+
DeprecationWarning,
167+
)
135168
# Project and module have to be stored before delete is called as
136169
# they may rely on the still existing db object.
137170
project = self.project
138171
module = self.module
139172

140-
response = super().form_valid(request, *args, **kwargs)
173+
response = super().delete(request, *args, **kwargs)
141174

142175
component = self.component
143176
if component.identifier in components.projects:

changelog/_00010.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### Changed
2+
3+
- **Breaking Change** Deprecated
4+
dashboard.mixins.DashboardComponentDeleteSignalMixin,
5+
for forms / POST requests use
6+
dashboard.mixins.DashboardComponentFormSignalMixin instead.
7+
DashboardComponentDeleteSignalMixin will be removed in the next version.

0 commit comments

Comments
 (0)