Commit 333f7248 authored by Davve's avatar Davve

完成push

parent 7dffab20
......@@ -8,33 +8,20 @@ from utils.base import APIView
class AccountList(APIView):
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))
filter = self.handle_filter(request.GET.get('filter', ""))
try:
data = self.rpc['venus/community/account/get'](offset=page, limit=limit, filters=filter).unwrap()
except Exception as e:
# raise e
data = {
'total': 1,
'data': [
{
'id': 1,
'username': 'hahah',
'nickname': '哈哈',
'phone': '123124312423',
'email': 'www.baid.com',
'password': '2412412'
}
]
}
raise e
return data
def post(self, request):
ids = request.POST.get('ids', '').split()
type = request.POST.get('type', '')
filter = request.POST.get('type', '')
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:
raise e
return {
......@@ -48,15 +35,7 @@ class AccountUpdateOrCreateView(APIView):
try:
data = self.rpc['venus/community/account/detail'](id=id).unwrap()
except Exception as e:
# raise e
data = {
'id': 1,
'username': 'hahah',
'nickname': '哈哈',
'phone': '123124312423',
'email': 'www.baid.com',
'password': '2412412'
}
raise e
return {'data': data}
def post(self, request):
......
......@@ -2,8 +2,10 @@
# -*- coding: utf-8 -*-
# __author__ = "chenwei"
# Date: 2018/11/15
import datetime
from utils.base import APIView
from utils.time_utils import utc_to_datetime, datetime_toString, unix_time_to_datetime, analysis_time
class PushListView(APIView):
......@@ -12,38 +14,9 @@ class PushListView(APIView):
limit = int(request.GET.get('limit', 10))
filter = self.handle_filter(request.GET.get('filter', ""))
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:
data = {
'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,
},
]
}
raise e
return data
......@@ -51,31 +24,28 @@ class PushUpdateOrCreateView(APIView):
def get(self, request):
id = request.GET.get('id')
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:
# 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': '这是一个推送标题',
}
raise e
return {'data': data}
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 = {
'url': request.POST.get('url', ''),
'push_time': request.POST.get('push_time', ''),
'icon': request.POST.get('icon', ''),
'push_time': push_time,
'icon': request.POST.get('icon', '')[:-2],
'content': request.POST.get('content', ''),
'title': request.POST.get('title', ''),
}
print(data, '--------------------')
# try:
# self.rpc['venus/community/push/create'](data=data).unwrap()
# except Exception as e:
# raise e
try:
self.rpc['venus/community/push/update_or_create'](id=id, data=data).unwrap()
except Exception as 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 {
multipleSelection: [],
del_list: [],
listQuery: {
page: 1,
page: 0,
limit: 10,
filter: {
value: '',
......@@ -105,7 +105,7 @@ export default {
this.getList()
},
handleFilter() {
this.listQuery.page = 1
this.listQuery.page = 0
this.getList()
},
handleCreate() {
......
......@@ -19,40 +19,48 @@
<div class="postInfo-container">
<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-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-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-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-col>
</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-input :rows="1" v-model="postForm.url" type="text" class="article-textarea"
style="width: 300px"/>
style="width: 180px"/>
</el-form-item>
</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-date-picker
v-model="postForm.push_time"
type="datetime"
format="yyyy-MM-dd HH:mm:ss"
placeholder="选择日期时间"
style="width: 300px"
style="width: 199px"
:picker-options="expireTimeOption"
/>
</el-form-item>
</el-col>
<el-col :span="8">
</el-col>
</el-row>
</div>
</el-col>
......@@ -89,6 +97,7 @@ const defaultForm = {
icon: '',
push_time: '',
url: '',
name:'',
}
export default {
......
......@@ -43,7 +43,7 @@
<el-table-column width="139px" align="center" label="创建用户">
<template slot-scope="scope">
<span>{{ scope.row.creator_id }}</span>
<span>{{ scope.row.user.name }}</span>
</template>
</el-table-column>
</el-table>
......@@ -70,7 +70,7 @@ export default {
multipleSelection: [],
del_list: [],
listQuery: {
page: 1,
page: 0,
limit: 10,
filter: {
value: '',
......@@ -107,7 +107,7 @@ export default {
this.getList()
},
handleFilter() {
this.listQuery.page = 1
this.listQuery.page = 0
this.getList()
},
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