コード例 #1
0
    def validate_owner(self, attrs, source):
        try:
            user = attrs[source]
        except KeyError:
            pass
        else:
            if user is None:
                if self.object.pk:
                    del attrs['owner']
                else:
                    attrs['owner'] = self.request.user

            elif self.object.pk:
                if self.object.is_default() and not user.is_staff:
                    raise s.ValidationError(_('Default datacenter must be owned by user with SuperAdmin rights.'))
                if user != self.object.owner:
                    self.owner_changed = self.object.owner  # Save old owner
                    # Cannot change owner while pending tasks exist
                    validate_owner(self.object, user, _('Datacenter'))

        return attrs
コード例 #2
0
ファイル: serializers.py プロジェクト: hafo821/esdc-ce
    def validate_owner(self, attrs, source):
        """Cannot change owner while pending tasks exist"""
        validate_owner(self.object, attrs.get(source, None), _('Image'))

        return attrs