コード例 #1
0
    def to_internal_value(self, data):
        if not isinstance(data, dict):
            raise serializers.ValidationError(
                {'detail': "Input [%s] must be a dict." % data})

        if data.keys() != ['id']:
            raise serializers.ValidationError(
                {'detail': 'Only accepts {"id":"int"}'})

        repo_id = convert_str_to_int(data['id'])

        try:
            rc = models.Repo.objects.get(id=repo_id)
        except models.Repo.DoesNotExist:
            raise serializers.ValidationError(
                {'detail': "Repo with id %s doesn't exist" % repo_id})

        return rc
コード例 #2
0
    def to_internal_value(self, data):
        if not isinstance(data, dict):
            raise serializers.ValidationError({'detail': "Input [%s] for ReleaseComponent must be a dict." % data})

        if set(data.keys()) not in [set(['id']), set(['release', 'name'])]:
            raise serializers.ValidationError(
                {'detail': "Only accept ['id'] or ['release', 'name']"})

        kwargs = dict()
        if 'id' in data:
            kwargs['id'] = convert_str_to_int(data.get('id'))
        else:
            kwargs['release__release_id'] = data.get('release')
            kwargs['name'] = data.get('name')
        try:
            rc = ReleaseComponent.objects.get(**kwargs)
        except ReleaseComponent.DoesNotExist:
            raise serializers.ValidationError({'detail': "ReleaseComponent [%s] doesn't exist" % data})
        return rc
    def to_internal_value(self, data):
        if not isinstance(data, dict):
            raise serializers.ValidationError({'detail': "Input [%s] for ReleaseComponent must be a dict." % data})

        if set(data.keys()) not in [set(['id']), set(['release', 'name'])]:
            raise serializers.ValidationError(
                {'detail': "Only accept ['id'] or ['release', 'name']"})

        kwargs = dict()
        if 'id' in data:
            kwargs['id'] = convert_str_to_int(data.get('id'))
        else:
            kwargs['release__release_id'] = data.get('release')
            kwargs['name'] = data.get('name')
        try:
            rc = ReleaseComponent.objects.get(**kwargs)
        except ReleaseComponent.DoesNotExist:
            raise serializers.ValidationError({'detail': "ReleaseComponent [%s] doesn't exist" % data})
        return rc
コード例 #4
0
    def to_internal_value(self, data):
        if not isinstance(data, dict):
            raise serializers.ValidationError({"detail": "Input [%s] for ReleaseComponent must be a dict." % data})

        if set(data.keys()) not in [set(["id"]), set(["release", "global_component", "name"])]:
            raise serializers.ValidationError(
                {"detail": "Only accept ['id'] or ['release', 'global_component', 'name']"}
            )

        kwargs = dict()
        if "id" in data:
            kwargs["id"] = convert_str_to_int(data.get("id"))
        else:
            kwargs["release__release_id"] = data.get("release")
            kwargs["global_component__name"] = data.get("global_component")
            kwargs["name"] = data.get("name")
        try:
            rc = ReleaseComponent.objects.get(**kwargs)
        except ReleaseComponent.DoesNotExist:
            raise serializers.ValidationError({"detail": "ReleaseComponent [%s] doesn't exist" % data})
        return rc
コード例 #5
0
    def bulk_destroy(self, request):
        """
        This API call allows deleting repositories. It is an almost exact
        mirror of `create` call. The same data must be fed into it.

        __Method__: `DELETE`

        __URL__: `/repos/`

        __Data__:

            {
                "release_id":       string,
                "variant_uid":      string,
                "arch":             string,
                "service":          string,
                "repo_family":      string,
                "content_format":   string,
                "content_category": string,
                "name":             string,
                "shadow":           bool,
                "product_id":       <int|null>
            }

        It is possible to send a list of these objects so that multiple
        repositories can be deleted at the same time atomically.

        __Response__: Nothing
        """
        data = request.data
        in_bulk = True
        if not isinstance(data, list):
            data = [data]
            in_bulk = False

        for idx, input in enumerate(data):
            input_id = (' in input %d' % idx) if in_bulk else ''
            allowed_keys = set(['release_id', 'variant_uid', 'arch', 'service',
                                'repo_family', 'content_format', 'content_category',
                                'name', 'shadow', 'product_id'])
            missing_keys = allowed_keys - set(input.keys())
            additional_keys = set(input.keys()) - allowed_keys
            if missing_keys:
                resp = Response(status=status.HTTP_400_BAD_REQUEST,
                                data={'detail': 'Missing arguments: %s%s'
                                      % (', '.join(missing_keys), input_id)})
                resp.exception = True
                return resp
            if additional_keys:
                resp = Response(status=status.HTTP_400_BAD_REQUEST,
                                data={'detail': 'Unknown data fields: %s%s'
                                      % (', '.join(additional_keys), input_id)})
                resp.exception = True
                return resp

            kwargs = {'variant_arch__arch__name': input['arch'],
                      'variant_arch__variant__variant_uid': input['variant_uid'],
                      'variant_arch__variant__release__release_id': input['release_id'],
                      'service__name': input['service'],
                      'repo_family__name': input['repo_family'],
                      'content_format__name': input['content_format'],
                      'content_category__name': input['content_category'],
                      'name': input['name'],
                      'shadow': hacks.convert_str_to_bool(input['shadow'], name='shadow'),
                      'product_id': (hacks.convert_str_to_int(input['product_id'], name='product_id')
                                     if input['product_id'] is not None else None)}
            obj = models.Repo.objects.get(**kwargs)
            request.changeset.add('Repo', obj.pk, json.dumps(obj.export()), 'null')
            obj.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)