Commit 333f7248 authored by Davve's avatar Davve

完成push

parent 7dffab20
...@@ -8,33 +8,20 @@ from utils.base import APIView ...@@ -8,33 +8,20 @@ from utils.base import APIView
class AccountList(APIView): class AccountList(APIView):
def get(self, request): def get(self, request):
page = int(request.GET.get('page', 1)) page = int(request.GET.get('page', 0))
limit = int(request.GET.get('limit', 10)) limit = int(request.GET.get('limit', 10))
filter = self.handle_filter(request.GET.get('filter', "")) filter = self.handle_filter(request.GET.get('filter', ""))
try: try:
data = self.rpc['venus/community/account/get'](offset=page, limit=limit, filters=filter).unwrap() data = self.rpc['venus/community/account/get'](offset=page, limit=limit, filters=filter).unwrap()
except Exception as e: except Exception as e:
# raise e raise e
data = {
'total': 1,
'data': [
{
'id': 1,
'username': 'hahah',
'nickname': '哈哈',
'phone': '123124312423',
'email': 'www.baid.com',
'password': '2412412'
}
]
}
return data return data
def post(self, request): def post(self, request):
ids = request.POST.get('ids', '').split() ids = request.POST.get('ids', '').split()
type = request.POST.get('type', '') filter = request.POST.get('type', '')
try: try:
self.rpc['venus/community/account/update'](type=type, ids=ids).unwrap() self.rpc['venus/community/account/update'](filter=filter, ids=ids).unwrap()
except Exception as e: except Exception as e:
raise e raise e
return { return {
...@@ -48,15 +35,7 @@ class AccountUpdateOrCreateView(APIView): ...@@ -48,15 +35,7 @@ class AccountUpdateOrCreateView(APIView):
try: try:
data = self.rpc['venus/community/account/detail'](id=id).unwrap() data = self.rpc['venus/community/account/detail'](id=id).unwrap()
except Exception as e: except Exception as e:
# raise e raise e
data = {
'id': 1,
'username': 'hahah',
'nickname': '哈哈',
'phone': '123124312423',
'email': 'www.baid.com',
'password': '2412412'
}
return {'data': data} return {'data': data}
def post(self, request): def post(self, request):
......
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# __author__ = "chenwei" # __author__ = "chenwei"
# Date: 2018/11/15 # Date: 2018/11/15
import datetime
from utils.base import APIView from utils.base import APIView
from utils.time_utils import utc_to_datetime, datetime_toString, unix_time_to_datetime, analysis_time
class PushListView(APIView): class PushListView(APIView):
...@@ -12,38 +14,9 @@ class PushListView(APIView): ...@@ -12,38 +14,9 @@ class PushListView(APIView):
limit = int(request.GET.get('limit', 10)) limit = int(request.GET.get('limit', 10))
filter = self.handle_filter(request.GET.get('filter', "")) filter = self.handle_filter(request.GET.get('filter', ""))
try: try:
data = self.rpc['venus/community/push/get'](offset=page, limit=limit, filters=filter).unwrap() data = self.rpc['venus/community/push/sun_list'](offset=page, limit=limit, filters=filter).unwrap()
except Exception as e: except Exception as e:
data = { raise e
'total': 200,
'data': [
{
'id': 1,
'title': '测试1',
'content': '测试2',
'push_time': '2018-08-09 23:89:09',
'create_time': '2019-08-07 23:89:09',
'creator_id': 22,
},
{
'id': 2,
'title': '测试1',
'content': '测试2',
'push_time': '2018-08-09 23:89:09',
'create_time': '2019-08-07 23:89:09',
'creator_id': 22,
},
{
'id': 3,
'title': '测试1',
'content': '测试2',
'push_time': '2018-08-09 23:89:09',
'create_time': '2019-08-07 23:89:09',
'creator_id': 22,
},
]
}
return data return data
...@@ -51,31 +24,28 @@ class PushUpdateOrCreateView(APIView): ...@@ -51,31 +24,28 @@ class PushUpdateOrCreateView(APIView):
def get(self, request): def get(self, request):
id = request.GET.get('id') id = request.GET.get('id')
try: try:
data = self.rpc['venus/community/push/detail'](id=id).unwrap() data = self.rpc['venus/community/push/get'](id=id).unwrap()
except Exception as e: except Exception as e:
# raise e raise e
data = {
'id': 1,
'create_time': '2018-09-08 23:34:34',
'push_time': 24121273912739, # 返回时间戳
'content': '这是推送内容',
'url': 'http:www.baidu.com',
'icon': 'https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=846134627,633122759&fm=173&app=49&f=JPEG?w=600&h=400&s=84C5D14ADEA4A2575042FFAA0300F005',
'title': '这是一个推送标题',
}
return {'data': data} return {'data': data}
def post(self, request): def post(self, request):
# TODO 图片icon上传到七牛 id = request.POST.get('id', '')
try:
push_time = unix_time_to_datetime(int(request.POST.get('push_time', 0)) / 1000)
except ValueError:
push_time = utc_to_datetime(request.POST.get('push_time', '')[:-5] + 'Z')
data = { data = {
'url': request.POST.get('url', ''), 'url': request.POST.get('url', ''),
'push_time': request.POST.get('push_time', ''), 'push_time': push_time,
'icon': request.POST.get('icon', ''), 'icon': request.POST.get('icon', '')[:-2],
'content': request.POST.get('content', ''), 'content': request.POST.get('content', ''),
'title': request.POST.get('title', ''), 'title': request.POST.get('title', ''),
} }
print(data, '--------------------') try:
# try: self.rpc['venus/community/push/update_or_create'](id=id, data=data).unwrap()
# self.rpc['venus/community/push/create'](data=data).unwrap() except Exception as e:
# except Exception as e: raise e
# raise e return {
"message": '更新成功'
}
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "chenwei"
# Date: 2018/11/19
import pytz
import time
from datetime import datetime
def utc_to_local(utc_time_str, utc_format='%Y-%m-%dT%H:%M:%SZ'):
"""
UTCS时间转换为时间戳
:param utc_time_str: 2016-07-31T16:00:00Z
:param utc_format:
:return: 1542816000
"""
local_tz = pytz.timezone('Asia/Shanghai')
local_format = "%Y-%m-%d %H:%M:%S"
utc_dt = datetime.strptime(utc_time_str, utc_format)
local_dt = utc_dt.replace(tzinfo=pytz.utc).astimezone(local_tz)
time_str = local_dt.strftime(local_format)
return int(time.mktime(time.strptime(time_str, local_format)))
def unix_time_to_datetime(stamp):
"""
时间戳转化为datetime类型
:param stamp:
:return:
"""
return datetime.fromtimestamp(stamp)
def utc_to_datetime(utc_time_str):
"""
utc时间转化为datetime
:param utc_time_str:
:return:
"""
time_stamp = utc_to_local(utc_time_str)
return unix_time_to_datetime(time_stamp)
def datetime_toString(dt):
return dt.strftime("%Y-%m-%d %H:%M:%S")
def analysis_time(time):
"""
:param time:
:return:
"""
try:
target_time = unix_time_to_datetime(int(time) / 1000)
except ValueError:
target_time = utc_to_datetime(time[:-5] + 'Z')
return datetime_toString(target_time)
\ No newline at end of file
...@@ -63,7 +63,7 @@ export default { ...@@ -63,7 +63,7 @@ export default {
multipleSelection: [], multipleSelection: [],
del_list: [], del_list: [],
listQuery: { listQuery: {
page: 1, page: 0,
limit: 10, limit: 10,
filter: { filter: {
value: '', value: '',
...@@ -105,7 +105,7 @@ export default { ...@@ -105,7 +105,7 @@ export default {
this.getList() this.getList()
}, },
handleFilter() { handleFilter() {
this.listQuery.page = 1 this.listQuery.page = 0
this.getList() this.getList()
}, },
handleCreate() { handleCreate() {
......
...@@ -19,40 +19,48 @@ ...@@ -19,40 +19,48 @@
<div class="postInfo-container"> <div class="postInfo-container">
<el-row> <el-row>
<el-col :span="12"> <el-col :span="8">
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="推送ID:" prop="id" v-if="isEdit"> <el-form-item style="margin-bottom: 40px;" label-width="75px" label="推送ID:" prop="id" v-if="isEdit">
<el-input :rows="1" v-model="postForm.id" type="text" class="article-textarea" <el-input :rows="1" v-model="postForm.id" type="text" class="article-textarea"
style="width: 300px" readonly v-if="isEdit"/> style="width: 180px" readonly v-if="isEdit"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="10"> <el-col :span="8">
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="创建时间:" prop="create_time" v-if="isEdit"> <el-form-item style="margin-bottom: 40px;" label-width="75px" label="创建时间:" prop="create_time" v-if="isEdit">
<el-input :rows="1" v-model="postForm.create_time" type="text" class="article-textarea" <el-input :rows="1" v-model="postForm.create_time" type="text" class="article-textarea"
style="width: 300px" readonly v-if="isEdit"/> style="width: 199px" readonly v-if="isEdit"/>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="创建用户:" v-if="isEdit">
<el-input :rows="1" v-model="postForm.user.name" type="text" class="article-textarea"
style="width: 180px" readonly v-if="isEdit"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row> <el-row>
<el-col :span="12"> <el-col :span="8">
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="推送落地:" prop="url" > <el-form-item style="margin-bottom: 40px;" label-width="75px" label="推送落地:" prop="url" >
<el-input :rows="1" v-model="postForm.url" type="text" class="article-textarea" <el-input :rows="1" v-model="postForm.url" type="text" class="article-textarea"
style="width: 300px"/> style="width: 180px"/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="10"> <el-col :span="8">
<el-form-item label-width="80px" label="推送时间:" class="postInfo-container-item" prop="push_time" > <el-form-item label-width="80px" label="推送时间:" class="postInfo-container-item" prop="push_time" >
<el-date-picker <el-date-picker
v-model="postForm.push_time" v-model="postForm.push_time"
type="datetime" type="datetime"
format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss"
placeholder="选择日期时间" placeholder="选择日期时间"
style="width: 300px" style="width: 199px"
:picker-options="expireTimeOption" :picker-options="expireTimeOption"
/> />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="8">
</el-col>
</el-row> </el-row>
</div> </div>
</el-col> </el-col>
...@@ -89,6 +97,7 @@ const defaultForm = { ...@@ -89,6 +97,7 @@ const defaultForm = {
icon: '', icon: '',
push_time: '', push_time: '',
url: '', url: '',
name:'',
} }
export default { export default {
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
<el-table-column width="139px" align="center" label="创建用户"> <el-table-column width="139px" align="center" label="创建用户">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.creator_id }}</span> <span>{{ scope.row.user.name }}</span>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
...@@ -70,7 +70,7 @@ export default { ...@@ -70,7 +70,7 @@ export default {
multipleSelection: [], multipleSelection: [],
del_list: [], del_list: [],
listQuery: { listQuery: {
page: 1, page: 0,
limit: 10, limit: 10,
filter: { filter: {
value: '', value: '',
...@@ -107,7 +107,7 @@ export default { ...@@ -107,7 +107,7 @@ export default {
this.getList() this.getList()
}, },
handleFilter() { handleFilter() {
this.listQuery.page = 1 this.listQuery.page = 0
this.getList() this.getList()
}, },
handleCreate() { handleCreate() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment