| @@ 407-424 (lines=18) @@ | ||
| 404 | class DeleteSubmissionMixin(): |
|
| 405 | """Prevent a delete relying on statuses""" |
|
| 406 | ||
| 407 | def dispatch(self, request, *args, **kwargs): |
|
| 408 | handler = super(DeleteSubmissionMixin, self).dispatch( |
|
| 409 | request, *args, **kwargs) |
|
| 410 | ||
| 411 | # here I've done get_queryset. Check for submission status |
|
| 412 | if hasattr(self, "object") and not self.object.can_edit(): |
|
| 413 | message = "Cannot delete %s: submission status is: %s" % ( |
|
| 414 | self.object, self.object.get_status_display()) |
|
| 415 | ||
| 416 | logger.warning(message) |
|
| 417 | messages.warning( |
|
| 418 | request=self.request, |
|
| 419 | message=message, |
|
| 420 | extra_tags="alert alert-dismissible alert-warning") |
|
| 421 | ||
| 422 | return redirect(self.object.get_absolute_url()) |
|
| 423 | ||
| 424 | return handler |
|
| 425 | ||
| 426 | ||
| 427 | class BatchDeleteMixin( |
|
| @@ 223-240 (lines=18) @@ | ||
| 220 | class EditSubmissionMixin(): |
|
| 221 | """A mixin to deal with Updates, expecially when searching ListViews""" |
|
| 222 | ||
| 223 | def dispatch(self, request, *args, **kwargs): |
|
| 224 | handler = super(EditSubmissionMixin, self).dispatch( |
|
| 225 | request, *args, **kwargs) |
|
| 226 | ||
| 227 | # here I've done get_queryset. Check for submission status |
|
| 228 | if hasattr(self, "submission") and not self.submission.can_edit(): |
|
| 229 | message = "Cannot edit submission: current status is: %s" % ( |
|
| 230 | self.submission.get_status_display()) |
|
| 231 | ||
| 232 | logger.warning(message) |
|
| 233 | messages.warning( |
|
| 234 | request=self.request, |
|
| 235 | message=message, |
|
| 236 | extra_tags="alert alert-dismissible alert-warning") |
|
| 237 | ||
| 238 | return redirect(self.submission.get_absolute_url()) |
|
| 239 | ||
| 240 | return handler |
|
| 241 | ||
| 242 | ||
| 243 | class SubmissionValidationSummaryFixErrorsView( |
|
| @@ 179-196 (lines=18) @@ | ||
| 176 | class DeleteMaterialMixin(OwnerMixin): |
|
| 177 | """A common DeleteMixin for Material classes (Sample/Animal)""" |
|
| 178 | ||
| 179 | def dispatch(self, request, *args, **kwargs): |
|
| 180 | handler = super(DeleteMaterialMixin, self).dispatch( |
|
| 181 | request, *args, **kwargs) |
|
| 182 | ||
| 183 | # here I've done get_queryset. Check for submission status |
|
| 184 | if hasattr(self, "object") and not self.object.can_edit(): |
|
| 185 | message = "Cannot delete %s: submission status is: %s" % ( |
|
| 186 | self.object, self.object.submission.get_status_display()) |
|
| 187 | ||
| 188 | logger.warning(message) |
|
| 189 | messages.warning( |
|
| 190 | request=self.request, |
|
| 191 | message=message, |
|
| 192 | extra_tags="alert alert-dismissible alert-warning") |
|
| 193 | ||
| 194 | return redirect(self.object.get_absolute_url()) |
|
| 195 | ||
| 196 | return handler |
|
| 197 | ||
| 198 | def get_success_url(self): |
|
| 199 | return reverse( |
|
| @@ 111-128 (lines=18) @@ | ||
| 108 | # override this attribute with a real validation class |
|
| 109 | validationresult_class = None |
|
| 110 | ||
| 111 | def dispatch(self, request, *args, **kwargs): |
|
| 112 | handler = super(UpdateMaterialMixin, self).dispatch( |
|
| 113 | request, *args, **kwargs) |
|
| 114 | ||
| 115 | # here I've done get_queryset. Check for submission status |
|
| 116 | if hasattr(self, "object") and not self.object.can_edit(): |
|
| 117 | message = "Cannot edit %s: submission status is: %s" % ( |
|
| 118 | self.object, self.object.submission.get_status_display()) |
|
| 119 | ||
| 120 | logger.warning(message) |
|
| 121 | messages.warning( |
|
| 122 | request=self.request, |
|
| 123 | message=message, |
|
| 124 | extra_tags="alert alert-dismissible alert-warning") |
|
| 125 | ||
| 126 | return redirect(self.object.get_absolute_url()) |
|
| 127 | ||
| 128 | return handler |
|
| 129 | ||
| 130 | # add the request to the kwargs |
|
| 131 | # https://chriskief.com/2012/12/18/django-modelform-formview-and-the-request-object/ |
|