Example #1
0
    def get(self, request, project, version):
        """
        List a Project Release's Files
        ``````````````````````````````

        Retrieve a list of files for a given release.

        :pparam string organization_slug: the slug of the organization the
                                          release belongs to.
        :pparam string project_slug: the slug of the project to list the
                                     release files of.
        :pparam string version: the version identifier of the release.
        :auth: required
        """
        try:
            release = Release.objects.get(
                organization_id=project.organization_id,
                projects=project,
                version=version,
            )
        except Release.DoesNotExist:
            raise ResourceDoesNotExist

        file_list = ReleaseFile.objects.filter(
            release=release, ).select_related('file').order_by('name')

        return self.paginate(
            request=request,
            queryset=file_list,
            order_by='name',
            paginator_cls=OffsetPaginator,
            on_results=lambda r: serialize(load_dist(r), request.user),
        )
Example #2
0
    def get(self, request, project, version):
        """
        List a Project Release's Files
        ``````````````````````````````

        Retrieve a list of files for a given release.

        :pparam string organization_slug: the slug of the organization the
                                          release belongs to.
        :pparam string project_slug: the slug of the project to list the
                                     release files of.
        :pparam string version: the version identifier of the release.
        :qparam string query: If set, this parameter is used to search files.
        :auth: required
        """
        query = request.GET.getlist("query")

        try:
            release = Release.objects.get(
                organization_id=project.organization_id,
                projects=project,
                version=version)
        except Release.DoesNotExist:
            raise ResourceDoesNotExist

        file_list = (ReleaseFile.objects.filter(
            release=release).select_related("file").order_by("name"))

        if query:
            if not isinstance(query, list):
                query = [query]

            condition = Q(name__icontains=query[0])
            for name in query[1:]:
                condition |= Q(name__icontains=name)
            file_list = file_list.filter(condition)

        return self.paginate(
            request=request,
            queryset=file_list,
            order_by="name",
            paginator_cls=OffsetPaginator,
            max_offset=MAX_RELEASE_FILES_OFFSET,
            on_results=lambda r: serialize(load_dist(r), request.user),
        )