Commit 43dabfeb authored by 张英杰's avatar 张英杰

修改输入内容判断

parent 3f1ee7a2
......@@ -2,7 +2,11 @@
# -*- coding: utf-8 -*-
import json
import string
import re
from zhon import (
hanzi,
pinyin,
)
from alpha_types.venus.enum import (
SKIN_ALL_CLASSIFY,
......@@ -94,7 +98,6 @@ class SkinCheckConfig(APIView):
:param text:
:return:
"""
text = text.encode("utf-8").decode("utf-8")
return text.replace(" ", "")
def _input_string_check(self, text, check_str):
......@@ -104,9 +107,17 @@ class SkinCheckConfig(APIView):
:param check_str:
:return: 没有标签符号,默认返回True
"""
punctuation_marks = list(filter(lambda x: x in string.punctuation, text))
if punctuation_marks:
if re.search("[{}]+".format(hanzi.punctuation), text): # 如果存在中文标点符号
return False
punctuation_marks = re.findall("[{}]+".format(pinyin.punctuation), text) # 英文标点符号
if len(punctuation_marks) == len(text): # 如果全部是英文标点符号
return False
elif punctuation_marks: # 判断是否都是以 check_str 分隔
return all(map(lambda p: p == check_str, punctuation_marks))
return True
def get(self, request):
......@@ -200,7 +211,7 @@ class SkinCheckConfig(APIView):
if _raise_message:
return {
"message": u"{} 标点符号错误!请以英文逗号分隔".format(_raise_message),
"message": u"{} 文案有误!请输入文字,多个文字之间以英文逗号分隔!".format(_raise_message),
}
info_logger.info("skin_check config modify data: {}".format(json.dumps(modify_data)))
......
......@@ -20,3 +20,4 @@ kombu==4.2.2.post1
requests==2.21.0
redis==2.10.6
openpyxl==2.6.2
zhon==1.1.5
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment