[PATCH v4 2/7] api: Add fields to series detail view

Stephen Finucane stephen at that.guru
Sat Mar 8 21:52:56 AEDT 2025


On Thu, 2025-01-30 at 14:56 -0500, Adam Hassick wrote:
> * Add the "dependencies" and "dependents" fields to the series detail
>   view.
> * Add "parse_dependencies" to the project detail view.
> 
> Signed-off-by: Adam Hassick <ahassick at iol.unh.edu>

With one caveat below.

Reviewed-by: Stephen Finucane <stephen at that.guru>

> ---
>  patchwork/api/project.py |  2 ++
>  patchwork/api/series.py  | 26 ++++++++++++++++++++++++--
>  2 files changed, 26 insertions(+), 2 deletions(-)
> 
> diff --git a/patchwork/api/project.py b/patchwork/api/project.py
> index 2f0b478..9193633 100644
> --- a/patchwork/api/project.py
> +++ b/patchwork/api/project.py
> @@ -39,6 +39,7 @@ class ProjectSerializer(BaseHyperlinkedModelSerializer):
>              'list_archive_url',
>              'list_archive_url_format',
>              'commit_url_format',
> +            'parse_dependencies',

I'm going to change this to `show_dependencies` and, if necessary,
change later patches so that we always parse dependencies but only
expose them in the web UI and REST API when this option is `True`.

>          )
>          read_only_fields = (
>              'name',
> @@ -55,6 +56,7 @@ class ProjectSerializer(BaseHyperlinkedModelSerializer):
>                  'list_archive_url_format',
>                  'commit_url_format',
>              ),
> +            '1.4': ('parse_dependencies',),
>          }
>          extra_kwargs = {
>              'url': {'view_name': 'api-project-detail'},
> diff --git a/patchwork/api/series.py b/patchwork/api/series.py
> index b88ed1f..2b23e48 100644
> --- a/patchwork/api/series.py
> +++ b/patchwork/api/series.py
> @@ -5,7 +5,10 @@
>  
>  from rest_framework.generics import ListAPIView
>  from rest_framework.generics import RetrieveAPIView
> -from rest_framework.serializers import SerializerMethodField
> +from rest_framework.serializers import (
> +    SerializerMethodField,
> +    HyperlinkedRelatedField,
> +)
>  
>  from patchwork.api.base import BaseHyperlinkedModelSerializer
>  from patchwork.api.base import PatchworkPermission
> @@ -24,6 +27,12 @@ class SeriesSerializer(BaseHyperlinkedModelSerializer):
>      mbox = SerializerMethodField()
>      cover_letter = CoverSerializer(read_only=True)
>      patches = PatchSerializer(read_only=True, many=True)
> +    dependencies = HyperlinkedRelatedField(
> +        read_only=True, view_name='api-series-detail', many=True
> +    )
> +    dependents = HyperlinkedRelatedField(
> +        read_only=True, view_name='api-series-detail', many=True
> +    )
>  
>      def get_web_url(self, instance):
>          request = self.context.get('request')
> @@ -50,6 +59,8 @@ class SeriesSerializer(BaseHyperlinkedModelSerializer):
>              'mbox',
>              'cover_letter',
>              'patches',
> +            'dependencies',
> +            'dependents',
>          )
>          read_only_fields = (
>              'date',
> @@ -60,9 +71,15 @@ class SeriesSerializer(BaseHyperlinkedModelSerializer):
>              'mbox',
>              'cover_letter',
>              'patches',
> +            'dependencies',
> +            'dependents',
>          )
>          versioned_fields = {
>              '1.1': ('web_url',),
> +            '1.4': (
> +                'dependencies',
> +                'dependents',
> +            ),
>          }
>          extra_kwargs = {
>              'url': {'view_name': 'api-series-detail'},
> @@ -76,7 +93,12 @@ class SeriesMixin(object):
>      def get_queryset(self):
>          return (
>              Series.objects.all()
> -            .prefetch_related('patches__project', 'cover_letter__project')
> +            .prefetch_related(
> +                'patches__project',
> +                'cover_letter__project',
> +                'dependencies',
> +                'dependents',
> +            )
>              .select_related('submitter', 'project')
>          )
>  



More information about the Patchwork mailing list