mirror of https://github.com/jumpserver/jumpserver
fix(csv): 修复`JMSCSVParser`调用`serializer`导致循环调用问题
parent
3e6cd1c1d3
commit
34b188bbe7
|
@ -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…
Reference in New Issue