This should be present on all resources.
Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 88f56051 ("api: add comments detail endpoint")
title: ID
type: integer
readOnly: true
+ url:
+ title: URL
+ type: string
+ format: uri
+ readOnly: true
web_url:
title: Web URL
type: string
title: ID
type: integer
readOnly: true
+{% if version >= (1, 3) %}
+ url:
+ title: URL
+ type: string
+ format: uri
+ readOnly: true
+{% endif %}
{% if version >= (1, 1) %}
web_url:
title: Web URL
title: ID
type: integer
readOnly: true
+{% if version >= (1, 3) %}
url:
title: URL
type: string
format: uri
readOnly: true
+{% endif %}
{% if version >= (1, 1) %}
web_url:
title: Web URL
title: ID
type: integer
readOnly: true
- url:
- title: URL
- type: string
- format: uri
- readOnly: true
msgid:
title: Message ID
type: string
title: ID
type: integer
readOnly: true
- url:
- title: URL
- type: string
- format: uri
- readOnly: true
web_url:
title: Web URL
type: string
title: ID
type: integer
readOnly: true
- url:
- title: URL
- type: string
- format: uri
- readOnly: true
web_url:
title: Web URL
type: string
title: ID
type: integer
readOnly: true
+ url:
+ title: URL
+ type: string
+ format: uri
+ readOnly: true
web_url:
title: Web URL
type: string
class BaseHyperlinkedModelSerializer(HyperlinkedModelSerializer):
def to_representation(self, instance):
- data = super(BaseHyperlinkedModelSerializer, self).to_representation(
- instance
- )
-
request = self.context.get('request')
for version in getattr(self.Meta, 'versioned_fields', {}):
# if the user has requested a version lower that than in which the
# field was added, we drop it
if not utils.has_version(request, version):
for field in self.Meta.versioned_fields[version]:
- # After a PATCH with an older API version, we may not see
- # these fields. If they don't exist, don't panic, return
- # (and then discard) None.
- data.pop(field, None)
+ if field in self.fields:
+ del self.fields[field]
+
+ data = super(BaseHyperlinkedModelSerializer, self).to_representation(
+ instance
+ )
return data
if len(set([p.project.id for p in value])) > 1:
raise ValidationError(
- 'Bundle patches must belong to the same ' 'project'
+ 'Bundle patches must belong to the same project'
)
return value
from rest_framework.serializers import SerializerMethodField
from patchwork.api.base import BaseHyperlinkedModelSerializer
+from patchwork.api.base import NestedHyperlinkedIdentityField
from patchwork.api.base import MultipleFieldLookupMixin
from patchwork.api.base import PatchworkPermission
from patchwork.api.base import CurrentCoverDefault
class Meta:
fields = (
'id',
+ 'url',
'web_url',
'msgid',
'list_archive_url',
)
read_only_fields = (
'id',
+ 'url',
'web_url',
'msgid',
'list_archive_url',
versioned_fields = {
'1.1': ('web_url',),
'1.2': ('list_archive_url',),
- '1.3': ('addressed',),
+ '1.3': (
+ 'addressed',
+ 'url',
+ ),
}
class CoverCommentSerializer(BaseCommentListSerializer):
+ url = NestedHyperlinkedIdentityField(
+ 'api-cover-comment-detail',
+ lookup_field_mapping={
+ 'cover_id': 'cover_id',
+ 'comment_id': 'id',
+ },
+ )
cover = HiddenField(default=CurrentCoverDefault())
class Meta:
model = CoverComment
- fields = BaseCommentListSerializer.Meta.fields + ('cover', 'addressed')
+ fields = BaseCommentListSerializer.Meta.fields + ('cover',)
read_only_fields = BaseCommentListSerializer.Meta.read_only_fields + (
'cover',
)
class PatchCommentSerializer(BaseCommentListSerializer):
+ url = NestedHyperlinkedIdentityField(
+ 'api-patch-comment-detail',
+ lookup_field_mapping={
+ 'patch_id': 'patch_id',
+ 'comment_id': 'id',
+ },
+ )
patch = HiddenField(default=CurrentPatchDefault())
class Meta:
'mbox',
),
'1.2': ('list_archive_url',),
+ '1.3': ('url',),
}
extra_kwargs = {
'url': {'view_name': 'api-cover-comment-detail'},
'mbox',
),
'1.2': ('list_archive_url',),
+ '1.3': ('url',),
}
extra_kwargs = {
'url': {'view_name': 'api-patch-comment-detail'},
'related',
)
read_only_fields = (
+ 'url',
'web_url',
'project',
'msgid',