Introduces a new field in the project endpoint called 'patches_mbox'. Signed-off-by: Mete Polat <metepolat2...@gmail.com> --- Again 'patches_mbox' and not 'mbox' in order to prevent confusion.
patchwork/api/project.py | 11 +++++++++-- patchwork/models.py | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/patchwork/api/project.py b/patchwork/api/project.py index d7bb1f2..1f8862d 100644 --- a/patchwork/api/project.py +++ b/patchwork/api/project.py @@ -4,6 +4,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later from django.shortcuts import get_object_or_404 +from rest_framework.fields import SerializerMethodField from rest_framework.generics import ListAPIView from rest_framework.generics import RetrieveUpdateAPIView from rest_framework.serializers import CharField @@ -21,16 +22,22 @@ class ProjectSerializer(BaseHyperlinkedModelSerializer): list_email = CharField(max_length=200, source='listemail', read_only=True) maintainers = UserProfileSerializer(many=True, read_only=True, source='maintainer_project') + patches_mbox = SerializerMethodField() + + def get_patches_mbox(self, instance): + request = self.context.get('request') + return request.build_absolute_uri(instance.get_mbox_url()) class Meta: model = Project fields = ('id', 'url', 'name', 'link_name', 'list_id', 'list_email', 'web_url', 'scm_url', 'webscm_url', 'maintainers', - 'subject_match') + 'subject_match', 'patches_mbox') read_only_fields = ('name', 'link_name', 'list_id', 'list_email', - 'maintainers', 'subject_match') + 'maintainers', 'subject_match', 'patches_mbox') versioned_fields = { '1.1': ('subject_match', ), + '1.2': ('patches_mbox', ), } extra_kwargs = { 'url': {'view_name': 'api-project-detail'}, diff --git a/patchwork/models.py b/patchwork/models.py index 36d6fad..770f572 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -104,6 +104,9 @@ class Project(FilenameMixin, models.Model): return [] return list(Tag.objects.all()) + def get_mbox_url(self): + return reverse('patch-list-mbox', kwargs={'project_id': self.linkname}) + def __str__(self): return self.name -- 2.22.0 _______________________________________________ Patchwork mailing list Patchwork@lists.ozlabs.org https://lists.ozlabs.org/listinfo/patchwork