Code Duplication    Length = 45-45 lines in 2 locations

django-data/image/samples/tasks.py 1 location

@@ 21-65 (lines=45) @@
18
logger = get_task_logger(__name__)
19
20
21
class BatchUpdateSamples(MyTask, BatchUpdateMixin):
22
    name = "Batch update samples"
23
    description = """Batch update of field in samples"""
24
25
    item_cls = Sample
26
    submission_cls = Submission
27
28
    # Ovverride default on failure method
29
    # This is not a failed validation for a wrong value, this is an
30
    # error in task that mean an error in coding
31
    def on_failure(self, exc, task_id, args, kwargs, einfo):
32
        logger.error('{0!r} failed: {1!r}'.format(task_id, exc))
33
34
        # get submission object
35
        submission_obj = Submission.objects.get(pk=args[0])
36
37
        # mark submission with ERROR
38
        submission_obj.status = ERROR
39
        submission_obj.message = ("Error in batch update for samples: %s"
40
                                  % (str(exc)))
41
        submission_obj.save()
42
43
        send_message(submission_obj)
44
45
        # send a mail to the user with the stacktrace (einfo)
46
        submission_obj.owner.email_user(
47
            "Error in batch update for samples: %s" % (args[0]),
48
            ("Something goes wrong in batch update for samples. Please report "
49
             "this to InjectTool team\n\n %s" % str(einfo)),
50
        )
51
52
        # TODO: submit mail to admin
53
54
    def run(self, submission_id, sample_ids, attribute):
55
        """Function for batch update attribute in samples
56
        Args:
57
            submission_id (int): id of submission
58
            sample_ids (dict): dict with id and values to update
59
            attribute (str): attribute to update
60
        """
61
62
        logger.info("Start batch update for samples")
63
        super(BatchUpdateSamples, self).batch_update(submission_id, sample_ids,
64
                                                     attribute)
65
        return 'success'
66
67
68
# register explicitly tasks

django-data/image/animals/tasks.py 1 location

@@ 21-65 (lines=45) @@
18
logger = get_task_logger(__name__)
19
20
21
class BatchUpdateAnimals(MyTask, BatchUpdateMixin):
22
    name = "Batch update animals"
23
    description = """Batch update of field in animals"""
24
25
    item_cls = Animal
26
    submission_cls = Submission
27
28
    # Ovverride default on failure method
29
    # This is not a failed validation for a wrong value, this is an
30
    # error in task that mean an error in coding
31
    def on_failure(self, exc, task_id, args, kwargs, einfo):
32
        logger.error('{0!r} failed: {1!r}'.format(task_id, exc))
33
34
        # get submission object
35
        submission_obj = Submission.objects.get(pk=args[0])
36
37
        # mark submission with ERROR
38
        submission_obj.status = ERROR
39
        submission_obj.message = ("Error in batch update for animals: %s"
40
                                  % (str(exc)))
41
        submission_obj.save()
42
43
        send_message(submission_obj)
44
45
        # send a mail to the user with the stacktrace (einfo)
46
        submission_obj.owner.email_user(
47
            "Error in batch update for animals: %s" % (args[0]),
48
            ("Something goes wrong  in batch update for animals. Please report "
49
             "this to InjectTool team\n\n %s" % str(einfo)),
50
        )
51
52
        # TODO: submit mail to admin
53
54
    def run(self, submission_id, animal_ids, attribute):
55
        """Function for batch update attribute in animals
56
        Args:
57
            submission_id (int): id of submission
58
            animal_ids (dict): dict with id and values to update
59
            attribute (str): attribute to update
60
        """
61
62
        logger.info("Start batch update for animals")
63
        super(BatchUpdateAnimals, self).batch_update(submission_id, animal_ids,
64
                                                     attribute)
65
        return 'success'
66
67
68
# register explicitly tasks