Commit 8edb6733 authored by 王浩's avatar 王浩

Merge branch 'haow/dev' into 'test'

add topic batch create by one

See merge request alpha/saturn!10
parents c92d4e19 42acb314
...@@ -11,6 +11,7 @@ urlpatterns = [ ...@@ -11,6 +11,7 @@ urlpatterns = [
# topic # topic
url(r'^v1/create_topic_for_batch$', topic.CreateTopicForBatch.as_view(), name='create_topic_for_batch'), url(r'^v1/create_topic_for_batch$', topic.CreateTopicForBatch.as_view(), name='create_topic_for_batch'),
url(r'^v1/create_topic_for_batch_by_one$', topic.CreateTopicForBatchByOne.as_view(), name='create_topic_for_batch_by_one'),
# tag # tag
url(r'^v1/create_tag_for_batch$', tag.CreateTagForBatch.as_view(), name='create_tag_for_batch'), url(r'^v1/create_tag_for_batch$', tag.CreateTagForBatch.as_view(), name='create_tag_for_batch'),
......
...@@ -82,3 +82,80 @@ class CreateTopicForBatch(BaseView): ...@@ -82,3 +82,80 @@ class CreateTopicForBatch(BaseView):
return self.error(create_err) return self.error(create_err)
return self.ok(data=result) return self.ok(data=result)
class CreateTopicForBatchByOne(BaseView):
"""
内部使用,一对一批量建帖
"""
def post(self, request):
user_ids = json.loads(request.POST.get("user_ids", '[]'))
topic_list = json.loads(request.POST.get("topic_list", '[]'))
if not user_ids:
print(user_ids, topic_list)
return self.parameter_invalid_response()
if not topic_list:
return self.ok()
topics = []
# 敏感词检测,获取可用的帖子
check_info = Sensitive.check([topic["content"] for topic in topic_list if topic.get("content")])
for topic in topic_list:
if topic.get('content'):
succ = check_info.get(topic.get("content"))
if not succ:
topics.append(topic)
else:
if topic.get('images') or topic.get('video'):
topics.append(topic)
if not topics:
return self.ok()
tag_names = []
need_create_topics = []
for item, user_id in zip(topics, user_ids):
tags = item.get("tags") or []
tag_names.extend([tag.replace("#", '').strip() for tag in tags])
item["user_id"] = user_id
need_create_topics.append(item)
check_info = Sensitive.check(tag_names)
tags = [tag_name for tag_name, succ in check_info.items() if not succ]
# 先创建标签
_tag_error, _tag_data = self.call_rpc(
"venus/community/tag/batch_create_tag_by_name",
tag_names=tags
)
if _tag_error:
return self.error(_tag_error)
# 更新发帖
# 处理标签,将文本中的标签处理成现有标签
for item in need_create_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 tags if _tag_data.get(tag_name)
]
create_err, result = self.call_rpc(
"venus/community/topic/batch_create_for_inner",
topic_list=need_create_topics
)
if create_err:
return self.error(create_err)
return self.ok(data=result)
\ No newline at end of file
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