1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "chenwei"
# Date: 2018/11/17
import json
from utils.base import APIView
from utils.logger import error_logger
class TagListView(APIView):
def get(self, request):
offset = int(request.GET.get('offset', 1))
limit = int(request.GET.get('limit', 10))
filter = self.handle_filter(request.GET.get('filter', ""))
try:
data = self.rpc['venus/sun/tag/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):
ids = json.loads(request.POST.get('ids', '[]'))
updates = json.loads(request.POST.get('updates', '{}'))
try:
self.rpc['venus/sun/tag/batch/update'](updates=updates, ids=ids).unwrap()
except Exception as e:
error_logger.error(u'批量更新标签列表失败%s', e)
raise
return {
"message": "更新成功"
}
class TagUpdateOrCreateView(APIView):
def get(self, request):
id = request.GET.get('id')
try:
data = self.rpc['venus/sun/tag/get'](id=id).unwrap()
except Exception as e:
error_logger.error(u'获取标签%d信息失败%s'%(id, e))
raise
if not data:
data = {}
else:
pass
return {'data': data}
def post(self, request):
id = request.POST.get('id')
down_tags = list(set(map(lambda x: x.split(":")[0], json.loads((request.POST.get('down_tags', '[]'))))))
up_tags = list(set(map(lambda x: x.split(":")[0], json.loads((request.POST.get('up_tags', '[]'))))))
tagtypes = list(set(map(lambda x: x.split(":")[0], json.loads((request.POST.get('tagtypes', '[]'))))))
data = {
'name': request.POST.get('name').lower(),
'description': request.POST.get('description'),
'down_tags': down_tags,
'up_tags': up_tags,
'tagtypes': tagtypes,
'icon_url': request.POST.get('icon_url', '')[:-2],
'platform': request.POST.get('platform')
}
try:
data = self.rpc['venus/sun/tag/edit'](id=id, data=data).unwrap()
except Exception as e:
error_logger.error(u'创建/编辑标签%d信息失败%s' % (id, e))
raise
return data
class TagTypeListView(APIView):
def get(self, request):
offset = int(request.GET.get('offset', 1))
limit = int(request.GET.get('limit', 10))
filter = self.handle_filter(request.GET.get('filter', ""))
try:
data = self.rpc['venus/sun/tag/tagtype/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):
ids = json.loads(request.POST.get('ids', '[]'))
updates = json.loads(request.POST.get('updates', '{}'))
try:
self.rpc['venus/sun/tag/tagtype/batch/update'](updates=updates, ids=ids).unwrap()
except Exception as e:
error_logger.error(u'批量更新标签类型列表失败%s', e)
raise
return {
"message": "更新成功"
}
class TagTypeUpdateOrCreateView(APIView):
def get(self, request):
id = request.GET.get('id')
try:
data = self.rpc['venus/sun/tag/tagtype/get'](id=id).unwrap()
except Exception as e:
error_logger.error(u'获取标签%d信息失败%s'%(id, e))
raise
if not data:
data = {}
else:
pass
return {'data': data}
def post(self, request):
id = request.POST.get('id')
data = {
'name': request.POST.get('name'),
}
try:
data = self.rpc['venus/sun/tag/tagtype/edit'](id=id, data=data).unwrap()
except Exception as e:
error_logger.error(u'创建/编辑标签类型%d信息失败%s' % (id, e))
raise
return data