Commit a3f5dbf9 authored by zhanglu's avatar zhanglu

Merge branch 'haow/dev' into 'master'

pictorial backend

See merge request !124
parents 12de84cd 21705bc8
import json
from utils.base import APIView
from utils.logger import error_logger
class PictorialListView(APIView):
def get(self, request):
star_id = request.GET.get('star_id')
user_id = request.GET.get('user_id')
offset = int(request.GET.get('page', 1))
limit = int(request.GET.get('limit', 10))
filters = self.handle_filter(request.GET.get('filter', '{}'))
if star_id:
filters.update({'star_id': star_id})
if user_id:
filters.update({'user_id': user_id})
try:
data = self.rpc['venus/sun/pictorial/list'](filters=filters, offset=(offset-1)*limit, limit=limit).unwrap()
except Exception as e:
error_logger.error(u'获取画报列表失败%s' , e)
raise
return data
def post(self, request):
ids = json.loads(request.POST.get('ids', '[]'))
updates = json.loads(request.POST.get('updates', '{}'))
try:
self.rpc['venus/sun/pictorial/batch/update'](updates=updates, ids=ids).unwrap()
except Exception as e:
error_logger.error(u'批量更新失败%s', e)
raise
return {
"message": "更新成功"
}
class PictorialUpdateOrCreate(APIView):
def get(self, request):
id = request.GET.get('id').split(':')[0]
try:
data = self.rpc['venus/sun/pictorial/get'](id=id).unwrap()
except Exception as e:
error_logger.error(u'获取%s用户信息失败%s'%(id, e))
raise
return data
def post(self, request):
id = request.POST.get('id')
star_ids = json.loads(request.POST.get('star', '[]'))
pictorial_user_ids = json.loads(request.POST.get('pictorial_user_ids', '[]'))
collection_tag_ids = json.loads(request.POST.get('collection_tag_ids', '[]'))
data = {
'name': request.POST.get('name', ''),
'description': request.POST.get('description', ''),
'creator_id': request.POST.get('creator_id', ''),
'celebrity_ids': star_ids,
'is_online': int(request.POST.get('is_online', 0)),
'is_recommend': int(request.POST.get('is_recommend', 0)),
'pictorial_user_ids': pictorial_user_ids,
'icon': request.POST.get('icon', ''),
'collection_tag_ids': collection_tag_ids
}
try:
data = self.rpc['venus/sun/pictorial/edit'](id=id, data=data).unwrap()
except Exception as e:
error_logger.error(u'编辑%s用户信息失败%s' % (id, e))
raise
if not data.get('id'):
return {
'message': '画报已存在'
}
return {
'message': '更新成功',
'data': data
}
class PictorialTopics(APIView):
"""多个帖子关系"""
def post(self, request):
topic_ids = json.loads(request.POST.get('topic_ids', '[]'))
pictorial_id = request.POST.get('pictorial_id')
try:
self.rpc['venus/sun/pictorial/add_topics'](topic_ids=topic_ids, pictorial_id=pictorial_id).unwrap()
except Exception as e:
error_logger.error(u'编辑%s用户信息失败%s' % (id, e))
raise
return {
'message': '更新成功'
}
......@@ -103,4 +103,17 @@ class TagTypeSearchView(APIView):
raise e
return {
'data': ['{id}:{name}'.format(id=search_data['id'], name=search_data['name']) for search_data in data]
}
\ No newline at end of file
}
class PictorialSearchView(APIView):
def get(self, request):
name = request.GET.get('name')
try:
data = self.rpc['venus/sun/pictorial/search'](name=name).unwrap()
except Exception as e:
raise e
return {
'data': ['{id}:{name}'.format(id=search_data['id'], name=search_data['name']) for search_data in data]
}
......@@ -21,6 +21,7 @@ from .face_star import *
from .advertise import *
from .channel_build import *
from .commons import *
from .pictorial import *
urlpatterns = [
# 登陆,注销相关
......@@ -127,7 +128,14 @@ urlpatterns = [
url(r'^channel_build/batch/release', BatchPublishVersion.as_view()),
url(r'^channel_build/version/create', VersionCreate.as_view()),
url(r'^suggestion/list$', SuggestionListView.as_view())
url(r'^suggestion/list$', SuggestionListView.as_view()),
# 画报相关
url(r'^pictorial/list$', PictorialListView.as_view()),
url(r'^pictorial/list/update$', PictorialListView.as_view()),
url(r'^pictorial/get$', PictorialUpdateOrCreate.as_view()),
url(r'^pictorial/create$', PictorialUpdateOrCreate.as_view()),
url(r'^pictorial/topics$', PictorialTopics.as_view()),
]
search_urlpatterns = [
......@@ -139,6 +147,7 @@ search_urlpatterns = [
url(r'search/city$', CitySearchView.as_view()),
url(r'search/topic$', TopicSearchView.as_view()),
url(r'search/tagtype$', TagTypeSearchView.as_view()),
url(r'search/pictorial$', PictorialSearchView.as_view()),
]
common_urlpatterns = [
......
......@@ -72,6 +72,7 @@ class UserUpdateOrCreate(APIView):
'phone': request.POST.get('phone'),
'email': request.POST.get('email'),
'gender': request.POST.get('gender'),
'is_tcc': int(request.POST.get('is_tcc')),
}
try:
......
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