Commit 0b51eaa4 authored by zhanglu's avatar zhanglu

Merge branch 'test' into 'master'

Test

See merge request alpha/saturn!28
parents 34ec6714 a5fe2768
from engine.cache import RedisWithoutprefixProxy
from django.conf import settings
ins_cache = RedisWithoutprefixProxy(settings.REDIS_GROUP['ins_cache'])
......@@ -18,5 +18,7 @@ urlpatterns = [
# user
url(r'^v1/user/shadow/list$', user.ShadowUserList.as_view(), name='create_tag_for_batch'),
url(r'^v1/validate_3party_or_account$', user.Validate3PartyOrAccount.as_view(), name='validate_3party_or_account'),
url(r'^v1/validate_3party_account$', user.Validate3PartyAccount.as_view(), name='validate_3party_account$'),
url(r'^v1/user/batch_create_shadow_user$', user.BatchCreateShadowUser.as_view(), name='batch_create_shadow_user$'),
]
......@@ -10,16 +10,18 @@ class CreateTagForBatch(BaseView):
"""
def post(self, request):
tag_list = json.loads(request.POST.get("tags", '[]'))
need_check = request.POST.get('need_check', 0)
tags = []
# 敏感词检测,获取可用的帖子
# check_info = Sensitive.check([item["name"] for item in tag_list if item.get("name")])
# for tag in tag_list:
# succ = check_info.get(tag.get("name")) if tag.get("name") else True
# if not succ:
# tags.append(tag)
tags = tag_list
if need_check:
# 敏感词检测,获取可用的帖子
check_info = Sensitive.check([item["name"] for item in tag_list if item.get("name")])
for tag in tag_list:
succ = check_info.get(tag.get("name")) if tag.get("name") else True
if not succ:
tags.append(tag)
else:
tags = tag_list
error, data = self.call_rpc('venus/community/tag/batch_create_not_classify', data=tags)
if error:
......
......@@ -2,20 +2,28 @@ import json
from api.views.base_view import BaseView
from api.utils.sensitive import Sensitive
from api.cache.cache import ins_cache
from libs.user import get_user_by_ids
from alpha_types.venus import ERROR as CODES
from alpha_types.venus import GRAP_PLATFORM
ins_account_cache = "ins_account_cache"
class CreateTopicForBatch(BaseView):
"""
内部使用,批量建帖
"""
def post(self, request):
user_id = request.POST.get("user_id", 0)
card_level = request.POST.get("card_level", 0)
tag_id = request.POST.get("tag_id")
is_online = request.POST.get("is_online", 0)
platform = request.POST.get("platform")
topic_list = json.loads(request.POST.get("topic_list", '[]'))
if not user_id:
......@@ -55,9 +63,26 @@ class CreateTopicForBatch(BaseView):
tag_names.extend([tag.replace("#", '').strip() for tag in tags])
item["user_id"] = user_id
item["card_level"] = card_level
item["tag_id"] = tag_id
item["tag_id"] = tag_id if tag_id else None
item["is_online"] = is_online
not_exists_ids = []
topic_list = []
if platform == GRAP_PLATFORM.INS:
for item in topics:
_id = item.get("id")
if not _id:
continue
exists = ins_cache.sismember(ins_account_cache, _id)
if exists:
continue
topic_list.append(item)
not_exists_ids.append(_id)
else:
topic_list = topics
# check_info = Sensitive.check(tag_names)
# tags = [tag_name for tag_name, succ in check_info.items() if not succ]
tags = tag_names
......@@ -65,14 +90,14 @@ class CreateTopicForBatch(BaseView):
# 先创建标签
_tag_error, _tag_data = self.call_rpc(
"venus/community/tag/batch_create_tag_by_name",
tag_names=tags
tag_names=tags, is_own=1
)
if _tag_error:
return self.error(_tag_error)
# 更新发帖
# 处理标签,将文本中的标签处理成现有标签
for item in topics:
for item in topic_list:
tags = item.get("tags") or []
tags = [tag.replace("#", '').strip() for tag in tags]
content = item["content"]
......@@ -89,11 +114,15 @@ class CreateTopicForBatch(BaseView):
create_err, result = self.call_rpc(
"venus/community/topic/batch_create_for_inner",
topic_list=topics
topic_list=topic_list
)
if create_err:
return self.error(create_err)
# 将已经跑了的数据添加到缓存
if not_exists_ids:
ins_cache.sadd(ins_account_cache, *not_exists_ids)
return self.ok(data=result)
......
import json
import json
from api.views.base_view import BaseView, get_offset_count
from libs.user import get_user_by_names
from alpha_types.venus.error import ERROR as CODES
class UpdateGraspStatus(BaseView):
......@@ -59,3 +62,64 @@ class Validate3PartyAccount(BaseView):
return self.error(err)
data = {account_id: _data.get(account_id, False) for account_id in account_ids}
return self.ok(data=data)
class BatchCreateShadowUser(BaseView):
"""
批量创建马甲用户
"""
def post(self, request):
request_data = json.loads(request.POST.get('ins_data', '[]'))
print(request_data)
err, _data = self.call_rpc(
"venus/community/user/batch_create_shadow_user",
data=request_data
)
if err:
return self.error(err)
return self.ok(data=_data)
class Validate3PartyOrAccount(BaseView):
"""判断用户是否在三方账号或者alpha账号体系中。"""
def post(self, request):
try:
names = json.loads(request.POST.get("names", "[]"))
except:
names = []
if not names:
return self.error(self.get_ErrorInfo(CODES.PARAMS_INCOMPLETE))
user_list = get_user_by_names(names=names)
account_users = {}
for name in names:
for _, user in user_list.items():
if user["nick_name"] != name:
continue
account_users[name] = True
break
users = {name: account_users.get(name, False) for name in names}
err, _3party_account = self.call_rpc(
"venus/community/user/validate_has_bind_3party_account",
bind_account_ids=names
)
if err:
return self.error(err)
data = {
name: _3party_account.get(name, False) or users.get(name, False)
for name in names
}
return self.ok(data={
"users": data,
})
......@@ -46,6 +46,19 @@ def get_user_by_ids(user_ids):
return users_info
def get_user_by_names(names):
"""获取用户信息"""
try:
rpc = get_current_rpc_invoker()
users_info = rpc["venus/account/user/userinfo_list_by_name"](names=names).unwrap()
except Exception as e:
raise Exception(e)
return []
return users_info
def auth(request):
user_info = get_user_by_request(request)
if not user_info:
......
......@@ -68,8 +68,7 @@ QINIU_FACE_BUCKET = 'alpha-s'
FACE_TOP_N_CNT = 3
REDIS_GROUP = {
'desc_cache': {'host': '127.0.0.1', 'port': 6379, 'db': 1},
'qq_cache': {'host': '127.0.0.1', 'port': 6379, 'db': 1},
'ins_cache': {'host': '127.0.0.1', 'port': 6379, 'db': 1},
}
OPERTATION_POSITION = 3 # 运营卡片位置
......
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