Commit db6692de authored by zhanglu's avatar zhanglu

标签转化

parent 5cffd8b3
import json
from api.views.base_view import BaseView
from api.utils.sensitive import Sensitive
......@@ -33,7 +32,8 @@ class CreateTopicForBatch(BaseView):
tag_names = []
for item in topics:
tag_names.extend(item.get("tags", []))
tags = item.get("tags") or []
tag_names.extend([tag.replace("#", '').strip() for tag in tags])
item["user_id"] = user_id
check_info = Sensitive.check(tag_names)
......@@ -48,10 +48,20 @@ class CreateTopicForBatch(BaseView):
return self.error(_tag_error)
# 更新发帖
# 处理标签,将文本中的标签处理成现有标签
for item in topics:
tags = item.get("tags") or []
tags = [tag.replace("#", '').strip() for tag in tags]
content = item["content"]
for tag_name, tag_id in _tag_data.items():
if tag_name in tags:
alpha_tag = '<topic>{' + '"id":{},"name":"{}"'.format(tag_id, tag_name) + '}</topic>'
content = content.replace('#' + tag_name, alpha_tag)
item["content"] = content.replace('#', '')
item["tag_ids"] = [
_tag_data[tag_name]
for tag_name in item.get("tags", []) if _tag_data.get(tag_name)
for tag_name in tags if _tag_data.get(tag_name)
]
create_err, result = self.call_rpc(
......
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