|
| 1 | +import warnings |
1 | 2 | from copy import deepcopy
|
2 | 3 | from pathlib import Path
|
3 | 4 |
|
@@ -109,35 +110,67 @@ def get_context_data(self, **kwargs):
|
109 | 110 |
|
110 | 111 |
|
111 | 112 | 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 | + |
112 | 118 | 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 | + |
113 | 125 | response = super().form_valid(form)
|
114 | 126 |
|
115 | 127 | component = self.component
|
116 | 128 | if component.identifier in components.projects:
|
117 | 129 | signals.project_component_updated.send(
|
118 | 130 | sender=component.__class__,
|
119 |
| - project=self.project, |
| 131 | + project=project, |
120 | 132 | component=component,
|
121 | 133 | user=self.request.user,
|
122 | 134 | )
|
123 | 135 | else:
|
124 | 136 | signals.module_component_updated.send(
|
125 | 137 | sender=component.__class__,
|
126 |
| - module=self.module, |
| 138 | + module=module, |
127 | 139 | component=component,
|
128 | 140 | user=self.request.user,
|
129 | 141 | )
|
130 | 142 | return response
|
131 | 143 |
|
132 | 144 |
|
133 | 145 | 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 | + ) |
135 | 168 | # Project and module have to be stored before delete is called as
|
136 | 169 | # they may rely on the still existing db object.
|
137 | 170 | project = self.project
|
138 | 171 | module = self.module
|
139 | 172 |
|
140 |
| - response = super().form_valid(request, *args, **kwargs) |
| 173 | + response = super().delete(request, *args, **kwargs) |
141 | 174 |
|
142 | 175 | component = self.component
|
143 | 176 | if component.identifier in components.projects:
|
|
0 commit comments