def validate_foreign_keys_per_action()

in pontoon/actionlog/models.py [0:0]


    def validate_foreign_keys_per_action(self):
        if self.action_type in (
            self.ActionType.TRANSLATION_DELETED,
            self.ActionType.TM_ENTRY_DELETED,
        ):
            if self.translation or not self.entity or not self.locale:
                raise ValidationError(
                    f'For action type "{self.action_type}", only `entity` and `locale` are accepted'
                )

        elif self.action_type == self.ActionType.COMMENT_ADDED:
            if not (
                (self.translation and not self.locale and not self.entity)
                or (not self.translation and self.locale and self.entity)
            ):
                raise ValidationError(
                    f'For action type "{self.action_type}", either `translation` or `entity` and `locale` are accepted'
                )

        elif self.action_type in (
            self.ActionType.TRANSLATION_CREATED,
            self.ActionType.TRANSLATION_APPROVED,
            self.ActionType.TRANSLATION_UNAPPROVED,
            self.ActionType.TRANSLATION_REJECTED,
            self.ActionType.TRANSLATION_UNREJECTED,
        ):
            if not self.translation or self.entity or self.locale:
                raise ValidationError(
                    f'For action type "{self.action_type}", only `translation` is accepted'
                )

        elif self.action_type in (
            self.ActionType.TM_ENTRIES_EDITED,
            self.ActionType.TM_ENTRIES_UPLOADED,
        ):
            if self.translation or self.entity or self.locale:
                raise ValidationError(
                    f'For action type "{self.action_type}", only `tm_entries` is accepted'
                )