From 0b328dc2bed3edb8f6967f721381ec1f392bf410 Mon Sep 17 00:00:00 2001 From: yangchenglin <yangchenglin@yangchenglindeMacBook-Pro.local> Date: Fri, 2 Aug 2019 11:31:17 +0800 Subject: [PATCH] pictorial_reply --- api/reply.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ api/topic.py | 44 ------------------------------------- api/urls.py | 9 +++++--- 3 files changed, 68 insertions(+), 47 deletions(-) create mode 100644 api/reply.py diff --git a/api/reply.py b/api/reply.py new file mode 100644 index 0000000..560c0a1 --- /dev/null +++ b/api/reply.py @@ -0,0 +1,62 @@ +import json +from utils.base import APIView +from utils.logger import error_logger + + +class ReplyUpdateOrCreateView(APIView): + def get(self, request): + topic_id = request.GET.get('topic_id') + pictorial_id = request.GET.get('pictorial_id') + offset = int(request.GET.get('page', 0)) + limit = int(request.GET.get('limit', 10)) + filter = self.handle_filter(request.GET.get('filter', "")) + + if topic_id: + filter.update({'topic_id': topic_id}) + elif pictorial_id: + filter.update({'pictorial_id': pictorial_id}) + + try: + data = self.rpc['venus/sun/reply/list'](offset=(offset-1) * limit, limit=limit, filters=filter).unwrap() + except Exception as e: + error_logger.error(u'回å¤å¸–å失败%s' , e) + raise + return data + + def post(self, request): + reply_ids = json.loads(request.POST.get('reply_ids', [])) + try: + self.rpc['venus/sun/reply/batch_delete'](ids=reply_ids).unwrap() + except Exception as e: + error_logger.error(u'批é‡æ›´æ–°å¸–å失败%s', e) + raise + return { + 'message': 'æ“作æˆåŠŸ' + } + + +class ReplyCreate(APIView): + def post(self, request): + + request.POST.get('be_replied_id', None) + data = { + 'user_id': request.POST.get('user_id').split(':')[0], + 'replied_id': request.POST.get("replied_id", None), + 'content': request.POST.get('content'), + 'replied_user_id': request.POST.get('replied_user_id', None) + } + topic_id = request.POST.get('topic_id') + pictorial_id = request.POST.get('pictorial_id') + + if topic_id: + data['topic_id'] = topic_id + + if pictorial_id: + data['pictorial_id'] = pictorial_id + + try: + data = self.rpc['venus/sun/reply/edit'](id=None, data=data).unwrap() + except Exception as e: + error_logger.error(u'编辑帖å失败%s', e) + raise + return {'data': data} \ No newline at end of file diff --git a/api/topic.py b/api/topic.py index c5f3768..061c79b 100644 --- a/api/topic.py +++ b/api/topic.py @@ -157,50 +157,6 @@ class TopicUpdateOrCreateView(APIView): } -class ReplyUpdateOrCreateView(APIView): - def get(self, request): - id = request.GET.get('id') - offset = int(request.GET.get('page', 0)) - limit = int(request.GET.get('limit', 10)) - filter = self.handle_filter(request.GET.get('filter', "")) - filter.update({'topic_id': id}) - try: - data = self.rpc['venus/sun/topic/reply/list'](offset=(offset-1) * limit, limit=limit, filters=filter).unwrap() - except Exception as e: - error_logger.error(u'回å¤å¸–å失败%s' , e) - raise - return data - - def post(self, request): - reply_ids = json.loads(request.POST.get('reply_ids', [])) - try: - self.rpc['venus/sun/topic/reply/batch_delete'](ids=reply_ids).unwrap() - except Exception as e: - error_logger.error(u'批é‡æ›´æ–°å¸–å失败%s', e) - raise - return { - 'message': 'æ“作æˆåŠŸ' - } - - -class ReplyCreate(APIView): - def post(self, request): - request.POST.get('be_replied_id', None) - data = { - 'user_id': request.POST.get('user_id').split(':')[0], - 'replied_id': request.POST.get("replied_id", None), - 'topic_id': request.POST.get("topic_id", None), - 'content': request.POST.get('content'), - 'replied_user_id': request.POST.get('replied_user_id', None) - } - try: - data = self.rpc['venus/sun/topic/reply/edit'](id=None, data=data).unwrap() - except Exception as e: - error_logger.error(u'编辑帖å失败%s', e) - raise - return {'data': data} - - class TopicListBatchUpdate(APIView): def post(self, request): diff --git a/api/urls.py b/api/urls.py index 2762f67..ffc1995 100644 --- a/api/urls.py +++ b/api/urls.py @@ -31,6 +31,7 @@ from .product import * from .category import * from .classify import * from .effect import * +from .reply import * urlpatterns = [ @@ -59,9 +60,6 @@ urlpatterns = [ url(r'^topic/detail$', TopicUpdateOrCreateView.as_view()), url(r'^topic/create$', TopicUpdateOrCreateView.as_view()), url(r'^topic/batch_update$', TopicListBatchUpdate.as_view()), - url(r'^topic/reply/list$', ReplyUpdateOrCreateView.as_view()), - url(r'^topic/reply/batch_delete$', ReplyUpdateOrCreateView.as_view()), - url(r'^topic/reply/create$', ReplyCreate.as_view()), url(r'^topic/related_pictorial_info$', TopicRelatePictorialInfo.as_view()), url(r'^topic/ballot$', TopicBallot.as_view()), url(r'^topic/product/add$', TopicProductAdd.as_view()), @@ -215,6 +213,11 @@ urlpatterns = [ # 商å“功效 url(r'^effect/list$', EffectListView.as_view()), + + #评论相关 + url(r'^reply/list$', ReplyUpdateOrCreateView.as_view()), + url(r'^reply/batch_delete$', ReplyUpdateOrCreateView.as_view()), + url(r'^reply/create$', ReplyCreate.as_view()), ] -- 2.18.0