[PATCH v3 08/10] REST API: make patch.state a string rather than int
Finucane, Stephen
stephen.finucane at intel.com
Thu May 19 19:32:01 AEST 2016
On 18 May 22:31, Andy Doan wrote:
> The int value isn't very useful and the goal is to move this to an enum
> over time.
>
> Signed-off-by: Andy Doan <andy.doan at linaro.org>
Reviewed-by: Stephen Finucane <stephen.finucane at intel.com>
One nit below.
> @@ -61,10 +61,21 @@ class PatchSerializer(ModelSerializer):
> 'content', 'hash', 'msgid')
> mbox_url = SerializerMethodField()
>
> + def run_validation(self, data):
> + state = data.get('state')
> + if state:
> + for st in State.objects.all():
> + if st.name == state:
> + data['state'] = st.id
> + break
> + return super(PatchSerializer, self).run_validation(data)
> +
> def to_representation(self, instance):
> request = self.context.get('request', None)
> data = super(PatchSerializer, self).to_representation(instance)
>
> + data['state'] = instance.state.name
> +
nit: remove this whitespace
> data['mbox_url'] = request.build_absolute_uri(data['mbox_url'])
> data['project'] = request.build_absolute_uri(
> reverse('api_1.0:project-detail', args=[data['project']]))
More information about the Patchwork
mailing list