Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
saturn
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
0
Merge Requests
0
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
钟尚武
saturn
Commits
42acb314
Commit
42acb314
authored
Jan 17, 2019
by
王浩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add topic batch create by one
parent
c92d4e19
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
0 deletions
+79
-0
urls.py
api/urls.py
+1
-0
topic.py
api/views/topic.py
+78
-0
No files found.
api/urls.py
View file @
42acb314
...
...
@@ -11,6 +11,7 @@ urlpatterns = [
# topic
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
url
(
r'^v1/create_tag_for_batch$'
,
tag
.
CreateTagForBatch
.
as_view
(),
name
=
'create_tag_for_batch'
),
...
...
api/views/topic.py
View file @
42acb314
...
...
@@ -82,3 +82,80 @@ class CreateTopicForBatch(BaseView):
return
self
.
error
(
create_err
)
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
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