|
|
|
@@ -3,6 +3,7 @@
|
|
3
|
3
|
import json
|
|
4
|
4
|
|
|
5
|
5
|
from django.db import transaction
|
|
|
6
|
+from django.utils.encoding import force_text
|
|
6
|
7
|
from django.db.models import Count, Q
|
|
7
|
8
|
from django_logit import logit
|
|
8
|
9
|
from django_response import response
|
|
|
|
@@ -45,13 +46,15 @@ def _parse_rule_sections(value):
|
|
45
|
46
|
if not isinstance(section, dict):
|
|
46
|
47
|
raise ValueError('rule section must be an object')
|
|
47
|
48
|
|
|
48
|
|
- title = (section.get('title') or '').strip()
|
|
|
49
|
+ title = force_text(section.get('title') or '').strip()
|
|
49
|
50
|
items = section.get('items') or []
|
|
50
|
51
|
|
|
51
|
52
|
if not isinstance(items, list):
|
|
52
|
53
|
raise ValueError('rule section items must be a list')
|
|
53
|
54
|
|
|
54
|
|
- items = [str(item).strip() for item in items if str(item).strip()]
|
|
|
55
|
+ # 不能用 str():py2 下 str(unicode 中文) 抛 UnicodeEncodeError,
|
|
|
56
|
+ # 而它是 ValueError 的子类,会被外层 except 吞成「参数格式不正确」
|
|
|
57
|
+ items = [text for text in (force_text(item).strip() for item in items) if text]
|
|
55
|
58
|
|
|
56
|
59
|
if title or items:
|
|
57
|
60
|
cleaned.append({'title': title, 'items': items})
|