diff --git a/api/tag.py b/api/tag.py index 2d9d358e502d67393accfcd656c2d568fc5964c9..c5e78713bdf9427969a2aa89a1cfb77fb1f0057f 100644 --- a/api/tag.py +++ b/api/tag.py @@ -4,7 +4,7 @@ # Date: 2018/11/17 import json -from utils.base import APIView +from utils.base import APIView, get_offset_count from utils.logger import error_logger @@ -144,3 +144,52 @@ class TagRegisterUpdateView(APIView): error_logger.error(u'é…置失败') raise return {'msg': '更改æˆåŠŸ'} + + +class TagFilterList(APIView): + + def get(self, request): + filters = {} + offset, count = get_offset_count(request) + tag_name = request.GET.get('tag_name', None) + tag_id = request.GET.get('tag_id', None) + + if tag_name: + filters['tag_name'] = tag_name + if tag_id and tag_id > 0: + filters['tag_id'] = tag_id + + data = self.rpc['venus/sun/tag/filter/list'](filters=filters, offset=offset, count=count).unwrap() + + return data + + +class TagFilterCreate(APIView): + + def post(self, request): + tag_name = request.POST.get('tag_name', None) + tag_id = request.POST.get('tag_id', None) + if not tag_id or not tag_name: + return {'message': 'å‚æ•°ä¸å®Œæ•´'} + + data = self.rpc['venus/sun/tag/filter/add'](tag_id=tag_id, tag_name=tag_name).unwrap() + if not data: + return {'message': '创建失败'} + + return {'message': '创建æˆåŠŸ'} + + +class TagFilterDelete(APIView): + + def post(self, request): + id_ = request.POST.get('id', None) + + if not id_: + return {'message': 'å‚æ•°ä¸å®Œæ•´'} + + data = self.rpc['venus/sun/tag/filter/delete'](id_=id_).unwrap() + + if not data: + return {'message': 'æ“作失败'} + + return {'message': 'æ“作æˆåŠŸ'} diff --git a/api/urls.py b/api/urls.py index 5270df938fb189e8d09a79da1fd328277d901383..8263d0aa328a765da8c3dfe64f5fee8347432f22 100644 --- a/api/urls.py +++ b/api/urls.py @@ -88,6 +88,9 @@ urlpatterns = [ url(r'^tag/create$', TagUpdateOrCreateView.as_view()), url(r'^tag/detail$', TagUpdateOrCreateView.as_view()), url(r'^tag/register_show/update$', TagRegisterUpdateView.as_view()), + url(r'^tag/filter/list$', TagFilterList.as_view()), + url(r'^tag/filter/add$', TagFilterCreate.as_view()), + url(r'^tag/filter/delete$', TagFilterDelete.as_view()), # æ ‡ç¾ç±»åž‹ç›¸å…³ url(r'^tag/tagtype/list$', TagTypeListView.as_view()),