[PATCH v3 04/16] REST: Use SerializerMethod field
Daniel Axtens
dja at axtens.net
Wed Nov 30 08:56:41 AEDT 2016
> + def to_representation(self, instance):
> + data = super(PatchSerializer, self).to_representation(instance)
> + data['checks'] = data['url'] + 'checks/'
Should this URL be constructed with a method, rather than string concatenation?
> + return data
Apart from that, looks good to me but I'm not a DRF expert so I hesitate
to formally review it.
Regards,
Daniel
> class Meta:
> model = Patch
> @@ -50,24 +78,6 @@ class PatchSerializer(HyperlinkedModelSerializer):
> # render this field
> exclude = ('tags',)
>
> - def get_state(self, obj):
> - return obj.state.name
> -
> - def get_mbox(self, patch):
> - request = self.context.get('request', None)
> - return request.build_absolute_uri(patch.get_mbox_url())
> -
> - def to_representation(self, instance):
> - data = super(PatchSerializer, self).to_representation(instance)
> - data['checks'] = data['url'] + 'checks/'
> - data['check'] = instance.combined_check_state
> - headers = data.get('headers')
> - if headers is not None:
> - data['headers'] = email.parser.Parser().parsestr(headers, True)
> - data['tags'] = [{'name': x.tag.name, 'count': x.count}
> - for x in instance.patchtag_set.all()]
> - return data
> -
>
> class PatchViewSet(PatchworkViewSet):
> permission_classes = (PatchworkPermission,)
> diff --git a/patchwork/api/project.py b/patchwork/api/project.py
> index 7def2ed..b4debb6 100644
> --- a/patchwork/api/project.py
> +++ b/patchwork/api/project.py
> @@ -25,10 +25,6 @@ from patchwork.models import Project
>
>
> class ProjectSerializer(HyperlinkedModelSerializer):
> - class Meta:
> - model = Project
> - exclude = ('send_notifications', 'use_tags')
> -
> def to_representation(self, instance):
> data = super(ProjectSerializer, self).to_representation(instance)
> data['link_name'] = data.pop('linkname')
> @@ -36,6 +32,10 @@ class ProjectSerializer(HyperlinkedModelSerializer):
> data['list_id'] = data.pop('listid')
> return data
>
> + class Meta:
> + model = Project
> + exclude = ('send_notifications', 'use_tags')
> +
>
> class ProjectViewSet(PatchworkViewSet):
> permission_classes = (PatchworkPermission,)
> --
> 2.7.4
>
> _______________________________________________
> Patchwork mailing list
> Patchwork at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
More information about the Patchwork
mailing list