drf-forms / drf-schema-adapter

Making using Django with frontend libraries and frameworks DRYer
http://drf-schema-adapter.readthedocs.io/en/latest/
MIT License
157 stars 40 forks source link

There may be some bugs #61

Closed zshongyi closed 1 year ago

zshongyi commented 4 years ago

metadata.py line:76

            for field in serializer_instance.fields.keys():
                if field in {'id', '__str__'}:
                    continue

                instance_field = serializer_instance.fields[field]
                type_ = settings.WIDGET_MAPPING.get(instance_field.__class__.__name__)

                if type_ is None:
                    raise NotImplementedError()

                field_metadata = self.get_field_dict(field, serializer)

                fields_metadata.append(field_metadata)

                for meta_info in adapter.metadata_info:
                    if meta_info.attr == 'fields':
                        metadata['fields'] = fields_metadata,
                    elif meta_info.attr == 'fieldsets':
                        metadata['fieldsets'] = [{
                            'title': None,
                            'fields': [
                                {'key': field}
                                for field in serializer_instance.fields.keys()
                                if field != 'id' and field != '__str__'
                            ]
                        }]
                    else:
                        metadata[meta_info.attr] = meta_info.default

Maybe it should be like

            for field in serializer_instance.fields.keys():
                if field in {'id', '__str__'}:
                    continue

                instance_field = serializer_instance.fields[field]
                type_ = settings.WIDGET_MAPPING.get(instance_field.__class__.__name__)

                if type_ is None:
                    raise NotImplementedError()

                field_metadata = self.get_field_dict(field, serializer)

                fields_metadata.append(field_metadata)

            for meta_info in adapter.metadata_info:
                if meta_info.attr == 'fields':
                    metadata['fields'] = fields_metadata
                elif meta_info.attr == 'fieldsets':
                    metadata['fieldsets'] = [{
                        'title': None,
                        'fields': [
                            {'key': field}
                            for field in serializer_instance.fields.keys()
                            if field != 'id' and field != '__str__'
                        ]
                    }]
                else:
                    metadata[meta_info.attr] = meta_info.default

line:92 metadata['fields'] = fields_metadata, The last comma is superfluous. Option operation will returns two-tier array line:90 for meta_info in adapter.metadata_info: It shouldn't be indented here

nanuxbe commented 1 year ago

Thanks for your patience, you are right. This has been fixed but for some reason forgot to mention it here.