Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
1631c328
Unverified
Commit
1631c328
authored
May 31, 2019
by
BaiJiangJie
Committed by
GitHub
May 31, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2767 from jumpserver/dev
[Update] 解决csv导入导出的问题
parents
d2b1b194
9721b805
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
1 deletion
+5
-1
csv.py
apps/common/parsers/csv.py
+2
-0
csv.py
apps/common/renders/csv.py
+3
-1
No files found.
apps/common/parsers/csv.py
View file @
1631c328
...
...
@@ -3,6 +3,7 @@
import
json
import
chardet
import
codecs
import
unicodecsv
from
rest_framework.parsers
import
BaseParser
...
...
@@ -82,6 +83,7 @@ class JMSCSVParser(BaseParser):
try
:
stream_data
=
stream
.
read
()
stream_data
=
stream_data
.
strip
(
codecs
.
BOM_UTF8
)
detect_result
=
chardet
.
detect
(
stream_data
)
encoding
=
detect_result
.
get
(
"encoding"
,
"utf-8"
)
binary
=
self
.
_universal_newlines
(
stream_data
)
...
...
apps/common/renders/csv.py
View file @
1631c328
...
...
@@ -2,6 +2,7 @@
#
import
unicodecsv
import
codecs
from
datetime
import
datetime
from
six
import
BytesIO
...
...
@@ -73,7 +74,8 @@ class JMSCSVRender(BaseRenderer):
table
=
self
.
_gen_table
(
data
,
header
,
labels
)
csv_buffer
=
BytesIO
()
csv_writer
=
unicodecsv
.
writer
(
csv_buffer
,
encoding
=
'utf-8-sig'
)
csv_buffer
.
write
(
codecs
.
BOM_UTF8
)
csv_writer
=
unicodecsv
.
writer
(
csv_buffer
,
encoding
=
'utf-8'
)
for
row
in
table
:
csv_writer
.
writerow
(
row
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment