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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "chenwei"
# Date: 2018/11/15
from utils.base import APIView
from utils.logger import error_logger
class PushListView(APIView):
def get(self, request):
page = int(request.GET.get('page', 1))
limit = int(request.GET.get('limit', 10))
filter = self.handle_filter(request.GET.get('filter', ""))
try:
data = self.rpc['venus/sun/push/list'](offset=(page-1) * limit, limit=limit, filters=filter).unwrap()
except Exception as e:
error_logger.error(u'获取push列表失败%s', e)
raise
return data
class PushUpdateOrCreateView(APIView):
def get(self, request):
id = request.GET.get('id')
try:
data = self.rpc['venus/sun/push/get'](id=id).unwrap()
except Exception as e:
error_logger.error(u'获取%s-push信息失败%s' %(id, e))
raise
return {'data': data}
def post(self, request):
id = request.POST.get('id', '')
creator_id = request.POST.get('creator_id')
group_topic_id = request.POST.get('group_topic_id', '')
icon = request.POST.get('icon', '')
if icon.endswith('-w'):
icon = request.POST.get('icon', '')[:-2]
url = request.POST.get('url', '')
if url == '推送帖子':
url = 'alpha://topic_detail?topic_id='
elif url == '推送小组':
url = 'alpha://group_detail?group_id='
full_url = url + group_topic_id
data = {
'url': full_url,
'push_time': request.POST.get('push_time'),
'icon': icon,
'content': request.POST.get('content', ''),
'title': request.POST.get('title', ''),
'creator_id': creator_id
}
try:
rep = self.rpc['venus/sun/push/edit'](id=id, data=data).unwrap()
except Exception as e:
error_logger.error(u'创建/编辑%s-push信息失败%s' % (id, e))
raise
return {
"message": '更新成功',
"id": rep['id']
}
class EffectPushTaskView(APIView):
def get(self, request):
push_task_id = request.GET.get('id')
try:
self.rpc['venus/sun/push/effect_push_task'](id=push_task_id).unwrap()
except Exception as e:
error_logger.error(u'%s-push生效失败%s' % (push_task_id, e))
raise
return {
'message': '操作成功'
}