| @@ 216-233 (lines=18) @@ | ||
| 213 | class EditSubmissionMixin(): |
|
| 214 | """A mixin to deal with Updates, expecially when searching ListViews""" |
|
| 215 | ||
| 216 | def dispatch(self, request, *args, **kwargs): |
|
| 217 | handler = super(EditSubmissionMixin, self).dispatch( |
|
| 218 | request, *args, **kwargs) |
|
| 219 | ||
| 220 | # here I've done get_queryset. Check for submission status |
|
| 221 | if hasattr(self, "submission") and not self.submission.can_edit(): |
|
| 222 | message = "Cannot edit submission: current status is: %s" % ( |
|
| 223 | self.submission.get_status_display()) |
|
| 224 | ||
| 225 | logger.warning(message) |
|
| 226 | messages.warning( |
|
| 227 | request=self.request, |
|
| 228 | message=message, |
|
| 229 | extra_tags="alert alert-dismissible alert-warning") |
|
| 230 | ||
| 231 | return redirect(self.submission.get_absolute_url()) |
|
| 232 | ||
| 233 | return handler |
|
| 234 | ||
| 235 | ||
| 236 | class SubmissionValidationSummaryFixErrorsView( |
|
| @@ 103-120 (lines=18) @@ | ||
| 100 | # override this attribute with a real validation class |
|
| 101 | validationresult_class = None |
|
| 102 | ||
| 103 | def dispatch(self, request, *args, **kwargs): |
|
| 104 | handler = super(UpdateMaterialMixin, self).dispatch( |
|
| 105 | request, *args, **kwargs) |
|
| 106 | ||
| 107 | # here I've done get_queryset. Check for submission status |
|
| 108 | if hasattr(self, "object") and not self.object.can_edit(): |
|
| 109 | message = "Cannot edit %s: submission status is: %s" % ( |
|
| 110 | self.object, self.object.submission.get_status_display()) |
|
| 111 | ||
| 112 | logger.warning(message) |
|
| 113 | messages.warning( |
|
| 114 | request=self.request, |
|
| 115 | message=message, |
|
| 116 | extra_tags="alert alert-dismissible alert-warning") |
|
| 117 | ||
| 118 | return redirect(self.object.get_absolute_url()) |
|
| 119 | ||
| 120 | return handler |
|
| 121 | ||
| 122 | # add the request to the kwargs |
|
| 123 | # https://chriskief.com/2012/12/18/django-modelform-formview-and-the-request-object/ |
|