[Patchew-devel] [PATCH v2] Text to json convertor for mbox
Paolo Bonzini
pbonzini at redhat.com
Fri Apr 27 12:07:47 UTC 2018
Very good progress, thanks!
On 27/04/2018 13:53, Shubham Jain wrote:
> class BaseMessageViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
> @@ -285,7 +285,8 @@ class ProjectSeriesViewSet(ProjectMessagesViewSetMixin,
> class MessageSerializer(BaseMessageSerializer):
> class Meta:
> model = Message
> - fields = BaseMessageSerializer.Meta.fields + ('mbox', )
> + # fields = BaseMessageSerializer.Meta.fields + ('mbox', )
> + fields = '__all__'
What is fields = '__all__'? :)
> def get_mbox(self, obj):
> return obj.get_mbox()
As far as I understand, read_only=True is used to make fields that are
included in the API output, but should not be included in the
POST/PUT/PATCH input. I thought SerializerMethodField had
read_only=True automatically, but maybe it doesn't?
> @@ -311,9 +312,9 @@ class StaticTextRenderer(renderers.BaseRenderer):
> return data
>
> class MessagesViewSet(ProjectMessagesViewSetMixin,
> - BaseMessageViewSet):
> + BaseMessageViewSet, mixins.CreateModelMixin):
> serializer_class = MessageSerializer
> -
> +
> @detail_route(renderer_classes=[StaticTextRenderer])
> def mbox(self, request, *args, **kwargs):
> message = self.get_object()
Can you also write a testcase for the POST operation? You can create a
new file 0001-simple-patch.json.gz to keep the testcase code simple.
> + msg['sender'] = json.dumps(self.get_from())
> + msg['recipients'] = json.dumps(self.get_to() + self.get_cc())
The json.dumps of course is only temporary; it can be removed when my
JSONField patch is applied and the sender/recipients
SerializerMethodFields are replaced by a Serializer.
> + 'sender': '["Fam Zheng", "famz at redhat.com"]',
> + 'recipients': '[["qemu-devel at nongnu.org", "qemu-devel at nongnu.org"], ["Kevin Wolf", "kwolf at redhat.com"], ["Alberto Garcia", "berto at igalia.com"], ["qemu-block at nongnu.org", "qemu-block at nongnu.org"], ["Max Reitz", "mreitz at redhat.com"]]',
So that these also becomes arrays rather than strings, and the
individual pairs use {'name': ..., 'address': ...} as in the GET output.
Thanks,
Paolo
More information about the Patchew-devel
mailing list