Code Duplication    Length = 18-18 lines in 4 locations

django-data/image/submissions/views.py 2 locations

@@ 404-421 (lines=18) @@
401
class DeleteSubmissionMixin():
402
    """Prevent a delete relying on statuses"""
403
404
    def dispatch(self, request, *args, **kwargs):
405
        handler = super(DeleteSubmissionMixin, self).dispatch(
406
                request, *args, **kwargs)
407
408
        # here I've done get_queryset. Check for submission status
409
        if hasattr(self, "object") and not self.object.can_edit():
410
            message = "Cannot delete %s: submission status is: %s" % (
411
                    self.object, self.object.get_status_display())
412
413
            logger.warning(message)
414
            messages.warning(
415
                request=self.request,
416
                message=message,
417
                extra_tags="alert alert-dismissible alert-warning")
418
419
            return redirect(self.object.get_absolute_url())
420
421
        return handler
422
423
424
class BatchDeleteMixin(
@@ 220-237 (lines=18) @@
217
class EditSubmissionMixin():
218
    """A mixin to deal with Updates, expecially when searching ListViews"""
219
220
    def dispatch(self, request, *args, **kwargs):
221
        handler = super(EditSubmissionMixin, self).dispatch(
222
                request, *args, **kwargs)
223
224
        # here I've done get_queryset. Check for submission status
225
        if hasattr(self, "submission") and not self.submission.can_edit():
226
            message = "Cannot edit submission: current status is: %s" % (
227
                    self.submission.get_status_display())
228
229
            logger.warning(message)
230
            messages.warning(
231
                request=self.request,
232
                message=message,
233
                extra_tags="alert alert-dismissible alert-warning")
234
235
            return redirect(self.submission.get_absolute_url())
236
237
        return handler
238
239
240
class SubmissionValidationSummaryFixErrorsView(

django-data/image/common/views.py 2 locations

@@ 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/