Code Duplication    Length = 18-18 lines in 4 locations

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

@@ 214-231 (lines=18) @@
211
class EditSubmissionMixin():
212
    """A mixin to deal with Updates, expecially when searching ListViews"""
213
214
    def dispatch(self, request, *args, **kwargs):
215
        handler = super(EditSubmissionMixin, self).dispatch(
216
                request, *args, **kwargs)
217
218
        # here I've done get_queryset. Check for submission status
219
        if hasattr(self, "submission") and not self.submission.can_edit():
220
            message = "Cannot edit submission: current status is: %s" % (
221
                    self.submission.get_status_display())
222
223
            logger.warning(message)
224
            messages.warning(
225
                request=self.request,
226
                message=message,
227
                extra_tags="alert alert-dismissible alert-warning")
228
229
            return redirect(self.submission.get_absolute_url())
230
231
        return handler
232
233
234
class SubmissionValidationSummaryFixErrorsView(
@@ 425-442 (lines=18) @@
422
class DeleteSubmissionMixin():
423
    """Prevent a delete relying on statuses"""
424
425
    def dispatch(self, request, *args, **kwargs):
426
        handler = super(DeleteSubmissionMixin, self).dispatch(
427
                request, *args, **kwargs)
428
429
        # here I've done get_queryset. Check for submission status
430
        if hasattr(self, "object") and not self.object.can_edit():
431
            message = "Cannot delete %s: submission status is: %s" % (
432
                    self.object, self.object.get_status_display())
433
434
            logger.warning(message)
435
            messages.warning(
436
                request=self.request,
437
                message=message,
438
                extra_tags="alert alert-dismissible alert-warning")
439
440
            return redirect(self.object.get_absolute_url())
441
442
        return handler
443
444
445
class BatchDeleteMixin(

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

@@ 169-186 (lines=18) @@
166
class DeleteMaterialMixin(OwnerMixin):
167
    """A common DeleteMixin for Material classes (Sample/Animal)"""
168
169
    def dispatch(self, request, *args, **kwargs):
170
        handler = super(DeleteMaterialMixin, self).dispatch(
171
                request, *args, **kwargs)
172
173
        # here I've done get_queryset. Check for submission status
174
        if hasattr(self, "object") and not self.object.can_edit():
175
            message = "Cannot delete %s: submission status is: %s" % (
176
                    self.object, self.object.submission.get_status_display())
177
178
            logger.warning(message)
179
            messages.warning(
180
                request=self.request,
181
                message=message,
182
                extra_tags="alert alert-dismissible alert-warning")
183
184
            return redirect(self.object.get_absolute_url())
185
186
        return handler
187
188
    def get_success_url(self):
189
        return reverse(
@@ 101-118 (lines=18) @@
98
    # override this attribute with a real validation class
99
    validationresult_class = None
100
101
    def dispatch(self, request, *args, **kwargs):
102
        handler = super(UpdateMaterialMixin, self).dispatch(
103
                request, *args, **kwargs)
104
105
        # here I've done get_queryset. Check for submission status
106
        if hasattr(self, "object") and not self.object.can_edit():
107
            message = "Cannot edit %s: submission status is: %s" % (
108
                    self.object, self.object.submission.get_status_display())
109
110
            logger.warning(message)
111
            messages.warning(
112
                request=self.request,
113
                message=message,
114
                extra_tags="alert alert-dismissible alert-warning")
115
116
            return redirect(self.object.get_absolute_url())
117
118
        return handler
119
120
    # add the request to the kwargs
121
    # https://chriskief.com/2012/12/18/django-modelform-formview-and-the-request-object/