| @@ 175-192 (lines=18) @@ | ||
| 172 | class DeleteMaterialMixin(OwnerMixin): |
|
| 173 | """A common DeleteMixin for Material classes (Sample/Animal)""" |
|
| 174 | ||
| 175 | def dispatch(self, request, *args, **kwargs): |
|
| 176 | handler = super(DeleteMaterialMixin, self).dispatch( |
|
| 177 | request, *args, **kwargs) |
|
| 178 | ||
| 179 | # here I've done get_queryset. Check for submission status |
|
| 180 | if hasattr(self, "object") and not self.object.can_edit(): |
|
| 181 | message = "Cannot delete %s: submission status is: %s" % ( |
|
| 182 | self.object, self.object.submission.get_status_display()) |
|
| 183 | ||
| 184 | logger.warning(message) |
|
| 185 | messages.warning( |
|
| 186 | request=self.request, |
|
| 187 | message=message, |
|
| 188 | extra_tags="alert alert-dismissible alert-warning") |
|
| 189 | ||
| 190 | return redirect(self.object.get_absolute_url()) |
|
| 191 | ||
| 192 | return handler |
|
| 193 | ||
| 194 | def get_success_url(self): |
|
| 195 | return reverse( |
|
| @@ 107-124 (lines=18) @@ | ||
| 104 | # override this attribute with a real validation class |
|
| 105 | validationresult_class = None |
|
| 106 | ||
| 107 | def dispatch(self, request, *args, **kwargs): |
|
| 108 | handler = super(UpdateMaterialMixin, self).dispatch( |
|
| 109 | request, *args, **kwargs) |
|
| 110 | ||
| 111 | # here I've done get_queryset. Check for submission status |
|
| 112 | if hasattr(self, "object") and not self.object.can_edit(): |
|
| 113 | message = "Cannot edit %s: submission status is: %s" % ( |
|
| 114 | self.object, self.object.submission.get_status_display()) |
|
| 115 | ||
| 116 | logger.warning(message) |
|
| 117 | messages.warning( |
|
| 118 | request=self.request, |
|
| 119 | message=message, |
|
| 120 | extra_tags="alert alert-dismissible alert-warning") |
|
| 121 | ||
| 122 | return redirect(self.object.get_absolute_url()) |
|
| 123 | ||
| 124 | return handler |
|
| 125 | ||
| 126 | # add the request to the kwargs |
|
| 127 | # https://chriskief.com/2012/12/18/django-modelform-formview-and-the-request-object/ |
|
| @@ 376-393 (lines=18) @@ | ||
| 373 | template_name = "submissions/submission_confirm_delete.html" |
|
| 374 | success_url = reverse_lazy('image_app:dashboard') |
|
| 375 | ||
| 376 | def dispatch(self, request, *args, **kwargs): |
|
| 377 | handler = super(DeleteSubmissionView, self).dispatch( |
|
| 378 | request, *args, **kwargs) |
|
| 379 | ||
| 380 | # here I've done get_queryset. Check for submission status |
|
| 381 | if hasattr(self, "object") and not self.object.can_edit(): |
|
| 382 | message = "Cannot delete %s: submission status is: %s" % ( |
|
| 383 | self.object, self.object.get_status_display()) |
|
| 384 | ||
| 385 | logger.warning(message) |
|
| 386 | messages.warning( |
|
| 387 | request=self.request, |
|
| 388 | message=message, |
|
| 389 | extra_tags="alert alert-dismissible alert-warning") |
|
| 390 | ||
| 391 | return redirect(self.object.get_absolute_url()) |
|
| 392 | ||
| 393 | return handler |
|
| 394 | ||
| 395 | # https://stackoverflow.com/a/39533619/4385116 |
|
| 396 | def get_context_data(self, **kwargs): |
|
| @@ 283-300 (lines=18) @@ | ||
| 280 | Q(animal__isnull=False) | Q(sample__isnull=False)) |
|
| 281 | ).order_by('id') |
|
| 282 | ||
| 283 | def dispatch(self, request, *args, **kwargs): |
|
| 284 | handler = super(EditSubmissionView, self).dispatch( |
|
| 285 | request, *args, **kwargs) |
|
| 286 | ||
| 287 | # here I've done get_queryset. Check for submission status |
|
| 288 | if hasattr(self, "submission") and not self.submission.can_edit(): |
|
| 289 | message = "Cannot edit submission: current status is: %s" % ( |
|
| 290 | self.submission.get_status_display()) |
|
| 291 | ||
| 292 | logger.warning(message) |
|
| 293 | messages.warning( |
|
| 294 | request=self.request, |
|
| 295 | message=message, |
|
| 296 | extra_tags="alert alert-dismissible alert-warning") |
|
| 297 | ||
| 298 | return redirect(self.submission.get_absolute_url()) |
|
| 299 | ||
| 300 | return handler |
|
| 301 | ||
| 302 | def get_context_data(self, **kwargs): |
|
| 303 | # Call the base implementation first to get a context |
|