@@ 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/ |
@@ 213-230 (lines=18) @@ | ||
210 | class EditSubmissionMixin(): |
|
211 | """A mixin to deal with Updates, expecially when searching ListViews""" |
|
212 | ||
213 | def dispatch(self, request, *args, **kwargs): |
|
214 | handler = super(EditSubmissionMixin, self).dispatch( |
|
215 | request, *args, **kwargs) |
|
216 | ||
217 | # here I've done get_queryset. Check for submission status |
|
218 | if hasattr(self, "submission") and not self.submission.can_edit(): |
|
219 | message = "Cannot edit submission: current status is: %s" % ( |
|
220 | self.submission.get_status_display()) |
|
221 | ||
222 | logger.warning(message) |
|
223 | messages.warning( |
|
224 | request=self.request, |
|
225 | message=message, |
|
226 | extra_tags="alert alert-dismissible alert-warning") |
|
227 | ||
228 | return redirect(self.submission.get_absolute_url()) |
|
229 | ||
230 | return handler |
|
231 | ||
232 | ||
233 | class SubmissionValidationSummaryFixErrorsView( |