Пример #1
0
    def save(self, *args, **kwargs):
        if self.end_date and self.end_date < self.start_date:
            raise ModelSaveError('end_date must be greater than ' 'start_date')

        if self.end_date is None:
            # If end_date is None, need to check that no other PayRates have
            # end_date is None, nor do they overlap.
            if type(self).objects.exclude(id=self.id).filter(
                (Q(end_date__gte=self.start_date) | Q(end_date__isnull=True)),
                    worker=self.worker).exists():
                raise ModelSaveError(
                    'Date range overlaps with existing PayRate entry')
        else:
            # If end_date is not None, need to check if other PayRates overlap.
            if (type(self).objects.exclude(id=self.id).filter(
                    start_date__lte=self.end_date,
                    end_date__isnull=True,
                    worker=self.worker).exists()
                    or type(self).objects.exclude(id=self.id).filter(
                        (Q(start_date__lte=self.end_date)
                         & Q(end_date__gte=self.start_date)),
                        worker=self.worker).exists()):
                raise ModelSaveError(
                    'Date range overlaps with existing PayRate entry')
        super().save(*args, **kwargs)
Пример #2
0
    def save(self, *args, **kwargs):
        if self.task.step.is_human:
            if self.worker is None:
                raise ModelSaveError('Worker has to be present '
                                     'if worker type is Human')
        else:
            if self.worker is not None:
                raise ModelSaveError('Worker should not be assigned '
                                     'if worker type is Machine')

        super(TaskAssignment, self).save(*args, **kwargs)
Пример #3
0
 def save(self, *args, **kwargs):
     if self.role == WorkerCertification.Role.REVIEWER:
         if not (WorkerCertification.objects.filter(
                 worker=self.worker,
                 task_class=self.task_class,
                 certification=self.certification,
                 role=WorkerCertification.Role.ENTRY_LEVEL).exists()):
             raise ModelSaveError(
                 'You are trying to add a reviewer '
                 'certification ({}) for a worker without '
                 'an entry-level certification'.format(self))
     super(WorkerCertification, self).save(*args, **kwargs)