Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
sun
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
1
Merge Requests
1
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
alpha
sun
Commits
e4ebd2ce
Commit
e4ebd2ce
authored
Aug 08, 2019
by
张英杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加输入校验
parent
a8d07082
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
4 deletions
+63
-4
skin_check.py
api/skin_check.py
+63
-4
No files found.
api/skin_check.py
View file @
e4ebd2ce
...
...
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import
json
import
string
from
alpha_types.venus.enum
import
(
SKIN_ALL_CLASSIFY
,
...
...
@@ -75,6 +76,38 @@ class SkinCheckPictorial(APIView):
class
SkinCheckConfig
(
APIView
):
# 大类对应的各小类枚举类型
enum_mapping
=
{
SKIN_CHECK_ITEMIZE_TYPE
.
SKIN_COLOR
:
SKIN_QUALITY_COLOR_DESC
,
# 肤色
SKIN_CHECK_ITEMIZE_TYPE
.
TEMPERATURE
:
SKIN_QUALITY_TEMPERATURE
,
# 色温
SKIN_CHECK_ITEMIZE_TYPE
.
OIL_LEVEL
:
SKIN_QUALITY_OIL_LEVEL
,
# 干油性
SKIN_CHECK_ITEMIZE_TYPE
.
SEVERITY
:
SKIN_PORE_SEVERITY
,
# 毛孔
SKIN_CHECK_ITEMIZE_TYPE
.
ROUGHNESS
:
SKIN_ROUGHNESS_TYPE
,
# 粗糙度
SKIN_CHECK_ITEMIZE_TYPE
.
BLACK_HEAD
:
SKIN_BLACK_HEADS_TYPE
,
# 黑头
SKIN_CHECK_ITEMIZE_TYPE
.
DARK_CIRCLE
:
SKIN_DARK_CIRCLE_TYPE
,
# 黑眼圈
SKIN_CHECK_ITEMIZE_TYPE
.
ACNE
:
SKIN_ACNE_TYPE
,
# 痘痘
}
def
_text_convert
(
self
,
text
):
"""
文案修正
:param text:
:return:
"""
return
text
.
replace
(
" "
,
""
)
def
_input_string_check
(
self
,
text
,
check_str
):
"""
输入内容标签符号校验,是否都是 check_str
:param text:
:param check_str:
:return: 没有标签符号,默认返回True
"""
punctuation_marks
=
list
(
filter
(
lambda
x
:
x
in
string
.
punctuation
),
text
)
if
punctuation_marks
:
return
all
(
map
(
lambda
p
:
p
==
check_str
,
punctuation_marks
))
return
True
def
get
(
self
,
request
):
data
=
{
...
...
@@ -130,17 +163,43 @@ class SkinCheckConfig(APIView):
# 对变更数据做一层封装
modify_data
=
[]
_raise_message
=
""
for
info
in
_data
:
_fitting
=
self
.
_text_convert
(
info
.
get
(
"fitting"
,
""
))
_dread
=
self
.
_text_convert
(
info
.
get
(
"dread"
,
""
))
_itemize_type
=
info
.
get
(
"owner_enum"
,
""
),
_enum_value
=
info
.
get
(
"enum_value"
,
""
)
maping_enum
=
self
.
enum_mapping
.
get
(
_itemize_type
,
None
)
if
not
self
.
_input_string_check
(
_fitting
,
","
):
_raise_message
=
u"{} {} 宜"
.
format
(
_itemize_type
and
SKIN_CHECK_ITEMIZE_TYPE
.
getDesc
(
_itemize_type
)
or
u""
,
_enum_value
and
maping_enum
and
maping_enum
.
getDesc
(
_enum_value
)
or
u""
)
elif
not
self
.
_input_string_check
(
_dread
,
","
):
_raise_message
=
u"{} {} 忌"
.
format
(
_itemize_type
and
SKIN_CHECK_ITEMIZE_TYPE
.
getDesc
(
_itemize_type
)
or
u""
,
_enum_value
and
maping_enum
and
maping_enum
.
getDesc
(
_enum_value
)
or
u""
)
if
_raise_message
:
break
_data
=
{
"skin_check_itemize_type"
:
info
.
get
(
"owner_enum"
,
""
)
,
"enum_value"
:
info
.
get
(
"enum_value"
,
""
)
,
"fitting"
:
info
.
get
(
"fitting"
,
""
)
,
"dread"
:
info
.
get
(
"dread"
,
""
)
,
"skin_check_itemize_type"
:
_itemize_type
,
"enum_value"
:
_enum_value
,
"fitting"
:
_fitting
,
"dread"
:
_dread
,
"fitting_suggest"
:
info
.
get
(
"fitting_suggest"
,
""
),
"dread_suggest"
:
info
.
get
(
"dread_suggest"
,
""
)
}
modify_data
.
append
(
_data
)
if
_raise_message
:
raise
Exception
(
u"{} 标点符号错误!请以英文逗号分隔"
.
format
(
_raise_message
))
info_logger
.
info
(
"skin_check config modify data: {}"
.
format
(
json
.
dumps
(
modify_data
)))
if
modify_data
:
...
...
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