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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import json
from utils.base import APIView, get_offset_count
from utils.logger import error_logger
class TopicHomeRecommendList(APIView):
def get(self, request):
sort_ = request.GET.get('sort_params', '-topic_id')
offset, count = get_offset_count(request)
try:
data = self.rpc['venus/sun/operation/topic_recommend/list'](sort_=sort_, offset=offset,
count=count).unwrap()
except Exception as e:
error_logger.error(u'获取首页推荐帖子列表失败%s', e)
raise
return data
class TopicHomeRecommendEdit(APIView):
def post(self, request):
id_ = request.POST.get('id')
is_online = request.POST.get("is_online")
rank = request.POST.get("rank")
data = {}
if is_online is not None:
data["is_online"] = int(is_online)
if rank is not None:
data["rank"] = int(rank)
if not data and not id_:
return {'message': '参数不全'}
try:
self.rpc['venus/sun/operation/topic_recommend/edit'](id_=id_, data=data).unwrap()
except Exception as e:
error_logger.error(u'更新失败', e)
raise
return {
'message': '更新成功'
}
class TopicHomeFixOperation(APIView):
def get(self, request):
try:
pos = request.GET.get("pos", 4)
data = self.rpc['venus/sun/operation/home_fix/info'](pos=pos).unwrap()
except Exception as e:
error_logger.error(u'运营位获取失败%s', e)
raise
return {'data': data}
def post(self, request):
image = request.POST.get('image')
protocol = request.POST.get("protocol")
pos = request.POST.get("pos", 4)
version = request.POST.get("version", 4)
if not image or not protocol:
return {'message': '参数不全'}
try:
self.rpc['venus/sun/operation/home_fix/edit'](image=image, protocol=protocol, pos=pos,
version=version).unwrap()
except Exception as e:
error_logger.error(u'更新失败', e)
raise
return {
'message': '更新成功'
}
class PictorialHomeRecommendList(APIView):
"""获取画报首页运营位推荐画报列表"""
def get(self, request):
offset, count = get_offset_count(request)
filters = json.loads(request.GET.get('filters', '{}'))
sort_by = request.GET.get('sort_by', None)
try:
data = self.rpc['venus/sun/operation/recommend/pictorial/list'](filters=filters, sort_by=sort_by, offset=offset, count=count).unwrap()
except Exception as e:
error_logger.error(u'获取数据失败', e)
raise
return data
class PictorialHomeRecommendUpdate(APIView):
"""更新画报首页运营位推荐画报"""
def post(self, request):
pictorial_id = request.POST.get('id')
rank = request.POST.get('rank')
try:
if rank:
data = self.rpc['venus/sun/operation/recommend/pictorial/rank'](pictorial_id=pictorial_id, rank=rank).unwrap()
elif pictorial_id:
data = self.rpc['venus/sun/operation/recommend/pictorial/delete'](pictorial_id=pictorial_id).unwrap()
except Exception as e:
error_logger.error(u'操作失败', e)
raise
if not data:
return u'操作失败'
return data
class OperationDelete(APIView):
"""删除运营位"""
def post(self, request):
operation_id = request.POST.get('id')
try:
data = self.rpc['venus/sun/operation/delete'](id_=operation_id).unwrap()
except Exception as e:
error_logger.error(u'操作失败', e)
raise
if not data:
return u'操作失败'
return data
class OperationEdit(APIView):
"""编辑运营位"""
def post(self, request):
operation_id = request.POST.get('id')
operation_type = int(request.POST.get('operation_type'))
image_url = request.POST.get('image_url')
url = request.POST.get('url')
start_time = int(request.POST.get('start_time'))
end_time = int(request.POST.get('end_time'))
long_image_url = request.POST.get('long_image_url')
is_repeat_read = int(request.POST.get('is_repeat_read', 1))
data = {
"operation_type": operation_type,
"image_url": image_url,
"long_image_url": long_image_url,
"url": url,
"start_time": start_time,
"end_time": end_time,
"is_repeat_read": is_repeat_read
}
try:
data = self.rpc['venus/sun/operation/edit'](id_=operation_id, data=data).unwrap()
except Exception as e:
error_logger.error(u'操作失败', e)
raise
if not data:
return u'操作失败'
return data
class OperationList(APIView):
"""获取运营位列表"""
def get(self, request):
operation_type = request.GET.get('operation_type')
try:
data = self.rpc['venus/sun/operation/list'](operation_type=operation_type).unwrap()
except Exception as e:
error_logger.error(u'获取失败', e)
raise
return data
class OperationSearchKeyword(APIView):
def get(self, request):
try:
data = self.rpc['venus/sun/operation/search_keyword/get']().unwrap()
except Exception as e:
error_logger.error(u'获取搜索热门词失败%s', e)
raise
return data
def post(self, request):
update = json.loads(request.POST.get('update'))
try:
data = self.rpc['venus/sun/operation/search_keyword/edit'](data=update).unwrap()
except Exception as e:
error_logger.error(u'获取搜索热门词失败%s', e)
raise
return data