Browse Source

fix(csv): 修复`JMSCSVParser`调用`serializer`导致循环调用问题

pull/4424/head
xinwen 4 years ago committed by 老广
parent
commit
34b188bbe7
  1. 8
      apps/common/drf/parsers/csv.py

8
apps/common/drf/parsers/csv.py

@ -47,9 +47,9 @@ class JMSCSVParser(BaseParser):
yield row
@staticmethod
def _get_fields_map(serializer):
def _get_fields_map(serializer_cls):
fields_map = {}
fields = serializer.fields
fields = serializer_cls().fields
fields_map.update({v.label: k for k, v in fields.items()})
fields_map.update({k: k for k, _ in fields.items()})
return fields_map
@ -101,7 +101,7 @@ class JMSCSVParser(BaseParser):
try:
view = parser_context['view']
meta = view.request.META
serializer = view.get_serializer()
serializer_cls = view.get_serializer_class()
except Exception as e:
logger.debug(e, exc_info=True)
raise ParseError('The resource does not support imports!')
@ -121,7 +121,7 @@ class JMSCSVParser(BaseParser):
rows = self._gen_rows(binary, charset=encoding)
header = next(rows)
fields_map = self._get_fields_map(serializer)
fields_map = self._get_fields_map(serializer_cls)
header = [fields_map.get(name.strip('*'), '') for name in header]
data = []

Loading…
Cancel
Save