[Patchew-devel] [PATCH v2] Text to json convertor for mbox
Shubham Jain
shubhamjain7495 at gmail.com
Fri Apr 27 12:32:07 UTC 2018
On Fri, Apr 27, 2018 at 5:37 PM Paolo Bonzini <pbonzini at redhat.com> wrote:
> 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__'? :)
>
Since you mentioned to use browsable api "form" to check for POST. The
"__all__" helps to get all the fields in the model. This would help with
the fields which were dependent on mbox since we are not providing any
mbox.
>
> > 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?
>
Yeah this won't work with POST/PUT/PATCH (
https://github.com/encode/django-rest-framework/blob/master/rest_framework/fields.py
)
> @@ -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.
>
Yes :)
> > + 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/patchew-devel/attachments/20180427/f6872322/attachment.htm>
More information about the Patchew-devel
mailing list