Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gjl2004yn
jumpserver
提交
4b1e84ed
J
jumpserver
项目概览
gjl2004yn
/
jumpserver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jumpserver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4b1e84ed
编写于
6月 30, 2020
作者:
B
Bai
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' into dev_login_password_encrypt
上级
71ee33e3
5dd24f5c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
22 deletion
+52
-22
apps/common/drf/parsers/csv.py
apps/common/drf/parsers/csv.py
+36
-11
apps/locale/zh/LC_MESSAGES/django.mo
apps/locale/zh/LC_MESSAGES/django.mo
+0
-0
apps/locale/zh/LC_MESSAGES/django.po
apps/locale/zh/LC_MESSAGES/django.po
+16
-11
未找到文件。
apps/common/drf/parsers/csv.py
浏览文件 @
4b1e84ed
...
...
@@ -6,18 +6,27 @@ import chardet
import
codecs
import
unicodecsv
from
django.utils.translation
import
ugettext
as
_
from
rest_framework.parsers
import
BaseParser
from
rest_framework.exceptions
import
ParseError
from
rest_framework.exceptions
import
ParseError
,
APIException
from
rest_framework
import
status
from
common.utils
import
get_logger
logger
=
get_logger
(
__file__
)
class
CsvDataTooBig
(
APIException
):
status_code
=
status
.
HTTP_400_BAD_REQUEST
default_code
=
'csv_data_too_big'
default_detail
=
_
(
'The max size of CSV is %d bytes'
)
class
JMSCSVParser
(
BaseParser
):
"""
Parses CSV file to serializer data
"""
CSV_UPLOAD_MAX_SIZE
=
1024
*
1024
*
10
media_type
=
'text/csv'
...
...
@@ -46,23 +55,31 @@ class JMSCSVParser(BaseParser):
return
fields_map
@
staticmethod
def
_process_row
(
row
):
def
_replace_chinese_quot
(
str_
):
trans_table
=
str
.
maketrans
({
'“'
:
'"'
,
'”'
:
'"'
,
'‘'
:
'"'
,
'’'
:
'"'
,
'
\'
'
:
'"'
})
return
str_
.
translate
(
trans_table
)
@
classmethod
def
_process_row
(
cls
,
row
):
"""
构建json数据前的行处理
"""
_row
=
[]
for
col
in
row
:
# 列表转换
if
isinstance
(
col
,
str
)
and
col
.
find
(
"["
)
!=
-
1
and
col
.
find
(
"]"
)
!=
-
1
:
# 替换中文格式引号
col
=
col
.
replace
(
"“"
,
'"'
).
replace
(
"”"
,
'"'
).
\
replace
(
"‘"
,
'"'
).
replace
(
'’'
,
'"'
).
replace
(
"'"
,
'"'
)
if
isinstance
(
col
,
str
)
and
col
.
startswith
(
'['
)
and
col
.
endswith
(
']'
):
col
=
cls
.
_replace_chinese_quot
(
col
)
col
=
json
.
loads
(
col
)
# 字典转换
if
isinstance
(
col
,
str
)
and
col
.
find
(
"{"
)
!=
-
1
and
col
.
find
(
"}"
)
!=
-
1
:
# 替换中文格式引号
col
=
col
.
replace
(
"“"
,
'"'
).
replace
(
"”"
,
'"'
).
\
replace
(
"‘"
,
'"'
).
replace
(
'’'
,
'"'
).
replace
(
"'"
,
'"'
)
if
isinstance
(
col
,
str
)
and
col
.
startswith
(
"{"
)
and
col
.
endswith
(
"}"
):
col
=
cls
.
_replace_chinese_quot
(
col
)
col
=
json
.
loads
(
col
)
_row
.
append
(
col
)
return
_row
...
...
@@ -82,11 +99,19 @@ class JMSCSVParser(BaseParser):
def
parse
(
self
,
stream
,
media_type
=
None
,
parser_context
=
None
):
parser_context
=
parser_context
or
{}
try
:
serializer
=
parser_context
[
"view"
].
get_serializer
()
view
=
parser_context
[
'view'
]
meta
=
view
.
request
.
META
serializer
=
view
.
get_serializer
()
except
Exception
as
e
:
logger
.
debug
(
e
,
exc_info
=
True
)
raise
ParseError
(
'The resource does not support imports!'
)
content_length
=
int
(
meta
.
get
(
'CONTENT_LENGTH'
,
meta
.
get
(
'HTTP_CONTENT_LENGTH'
,
0
)))
if
content_length
>
self
.
CSV_UPLOAD_MAX_SIZE
:
msg
=
CsvDataTooBig
.
default_detail
%
self
.
CSV_UPLOAD_MAX_SIZE
logger
.
error
(
msg
)
raise
CsvDataTooBig
(
msg
)
try
:
stream_data
=
stream
.
read
()
stream_data
=
stream_data
.
strip
(
codecs
.
BOM_UTF8
)
...
...
apps/locale/zh/LC_MESSAGES/django.mo
浏览文件 @
4b1e84ed
无法预览此类型文件
apps/locale/zh/LC_MESSAGES/django.po
浏览文件 @
4b1e84ed
...
...
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: JumpServer 0.3.3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-06-2
4 16:46
+0800\n"
"POT-Creation-Date: 2020-06-2
8 18:58
+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: ibuler <ibuler@qq.com>\n"
"Language-Team: JumpServer team<ibuler@qq.com>\n"
...
...
@@ -608,7 +608,7 @@ msgid "Assets"
msgstr "资产管理"
#: assets/models/user.py:111 templates/_nav.html:17
#: users/views/profile/password.py:4
2
users/views/profile/pubkey.py:36
#: users/views/profile/password.py:4
0
users/views/profile/pubkey.py:36
msgid "Users"
msgstr "用户管理"
...
...
@@ -1133,8 +1133,8 @@ msgid ""
"after {} minutes)"
msgstr "账号已被锁定(请联系管理员解锁 或 {}分钟后重试)"
#: authentication/errors.py:48 users/views/profile/otp.py:
107
#: users/views/profile/otp.py:1
46 users/views/profile/otp.py:166
#: authentication/errors.py:48 users/views/profile/otp.py:
63
#: users/views/profile/otp.py:1
02 users/views/profile/otp.py:121
msgid "MFA code invalid, or ntp sync server time"
msgstr "MFA验证码不正确,或者服务器端时间不对"
...
...
@@ -1364,6 +1364,11 @@ msgstr "%(name)s 创建成功"
msgid "%(name)s was updated successfully"
msgstr "%(name)s 更新成功"
#: common/drf/parsers/csv.py:22
#, python-format
msgid "The max size of CSV is %d bytes"
msgstr "CSV 文件最大为 %d 字节"
#: common/fields/form.py:33
msgid "Not a valid json"
msgstr "不是合法json"
...
...
@@ -2647,7 +2652,7 @@ msgstr "复制用户公钥到这里"
msgid "Join user groups"
msgstr "添加到用户组"
#: users/forms/user.py:103 users/views/profile/password.py:5
9
#: users/forms/user.py:103 users/views/profile/password.py:5
7
#: users/views/profile/reset.py:123
msgid "* Your password does not meet the requirements"
msgstr "* 您的密码不符合要求"
...
...
@@ -3483,27 +3488,27 @@ msgstr ""
" <br>\n"
" "
#: users/views/profile/otp.py:1
90
#: users/views/profile/otp.py:1
45
msgid "MFA enable success"
msgstr "多因子认证启用成功"
#: users/views/profile/otp.py:1
91
#: users/views/profile/otp.py:1
46
msgid "MFA enable success, return login page"
msgstr "多因子认证启用成功,返回到登录页面"
#: users/views/profile/otp.py:1
93
#: users/views/profile/otp.py:1
48
msgid "MFA disable success"
msgstr "多因子认证禁用成功"
#: users/views/profile/otp.py:1
94
#: users/views/profile/otp.py:1
49
msgid "MFA disable success, return login page"
msgstr "多因子认证禁用成功,返回登录页面"
#: users/views/profile/password.py:4
3
#: users/views/profile/password.py:4
1
msgid "Password update"
msgstr "密码更新"
#: users/views/profile/password.py:7
4
#: users/views/profile/password.py:7
2
msgid "Password invalid"
msgstr "用户名或密码无效"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录