add message

This commit is contained in:
baoliang 2020-10-21 21:37:19 +08:00
parent 6b505bbbe4
commit 7ce105c332
12 changed files with 27 additions and 195 deletions

View File

@ -130,6 +130,9 @@ class Organization(models.Model):
def __str__(self): def __str__(self):
return self.name return self.name
def is_direct(self):
return self.province != '' and self.cities == ''
# 扩展用户表 # 扩展用户表
class Userprofile(models.Model): class Userprofile(models.Model):
@ -166,9 +169,12 @@ class Userprofile(models.Model):
def level1_admin(cls): def level1_admin(cls):
return Userprofile.objects.filter(organization__level__level=1) return Userprofile.objects.filter(organization__level__level=1)
def __str__(self): def __str__(self):
return self.user.username+":"+self.name if self.is_leve1:
return '省级管理员%s' % (self.name,)
elif self.is_level2:
return '市级管理员%s' % (self.name,)
return self.name
def create_user_profile(sender, instance, created, **kwargs): def create_user_profile(sender, instance, created, **kwargs):

View File

@ -45,6 +45,7 @@ class Notice(models.Model):
type = models.IntegerField( type = models.IntegerField(
'category', choices=NOTICE_TYPE_CHOICES, default=0) 'category', choices=NOTICE_TYPE_CHOICES, default=0)
content = models.CharField('内容', max_length=256, null=False) content = models.CharField('内容', max_length=256, null=False)
group_id = models.CharField('group_id', max_length=256, null=True, blank=True)
app = models.CharField('app', max_length=256, null=True, blank=True) app = models.CharField('app', max_length=256, null=True, blank=True)
model = models.CharField('model', max_length=256, null=True, blank=True) model = models.CharField('model', max_length=256, null=True, blank=True)
field = models.CharField('field', max_length=256, null=True, blank=True) field = models.CharField('field', max_length=256, null=True, blank=True)
@ -67,8 +68,8 @@ class Notice(models.Model):
return now <= self.timeouted return now <= self.timeouted
@classmethod @classmethod
def create_normal_notice(cls, user_id, content): def create_normal_notice(cls, user_id, content, group_id):
return Notice.objects.create(user_id=user_id, content=content) return Notice.objects.create(user_id=user_id, content=content, group_id=group_id)
@classmethod @classmethod
def create_reply_notice(cls, user_id, content, app, model, field, record_id, record_pass_value, record_reject_value): def create_reply_notice(cls, user_id, content, app, model, field, record_id, record_pass_value, record_reject_value):

View File

@ -17,90 +17,7 @@
<script src="{% static 'polls/js/echarts.min.js' %}"></script> <script src="{% static 'polls/js/echarts.min.js' %}"></script>
<script type="text/javascript"> <script type="text/javascript">
var myChart = echarts.init(document.getElementById('chart1')); var myChart = echarts.init(document.getElementById('chart1'));
var posList = [
'left', 'right', 'top', 'bottom',
'inside',
'insideTop', 'insideLeft', 'insideRight', 'insideBottom',
'insideTopLeft', 'insideTopRight', 'insideBottomLeft', 'insideBottomRight'
];
myChart.configParameters = {
rotate: {
min: -90,
max: 90
},
align: {
options: {
left: 'left',
center: 'center',
right: 'right'
}
},
verticalAlign: {
options: {
top: 'top',
middle: 'middle',
bottom: 'bottom'
}
},
position: {
options: echarts.util.reduce(posList, function (map, pos) {
map[pos] = pos;
return map;
}, {})
},
distance: {
min: 0,
max: 100
}
};
myChart.config = {
rotate: 90,
align: 'left',
verticalAlign: 'middle',
position: 'insideBottom',
distance: 15,
onChange: function () {
var labelOption = {
normal: {
rotate: myChart.config.rotate,
align: myChart.config.align,
verticalAlign: myChart.config.verticalAlign,
position: myChart.config.position,
distance: myChart.config.distance
}
};
myChart.setOption({
series: [{
label: labelOption
}, {
label: labelOption
}, {
label: labelOption
}, {
label: labelOption
}]
});
}
};
var labelOption = {
show: true,
position: myChart.config.position,
distance: myChart.config.distance,
align: myChart.config.align,
verticalAlign: myChart.config.verticalAlign,
rotate: myChart.config.rotate,
formatter: '{c} {name|{a}}',
fontSize: 8,
rich: {
name: {
textBorderColor: '#fff'
}
}
};
var option = { var option = {
title: { title: {
text: '全省政务新媒体更新次数(逐月)', text: '全省政务新媒体更新次数(逐月)',
@ -137,31 +54,26 @@
name: '微信', name: '微信',
type: 'bar', type: 'bar',
barGap: 0, barGap: 0,
label: labelOption,
data: [320, 332, 301, 334, 390] data: [320, 332, 301, 334, 390]
}, },
{ {
name: '微博', name: '微博',
type: 'bar', type: 'bar',
label: labelOption,
data: [220, 182, 191, 234, 290] data: [220, 182, 191, 234, 290]
}, },
{ {
name: '头条', name: '头条',
type: 'bar', type: 'bar',
label: labelOption,
data: [150, 232, 201, 154, 190] data: [150, 232, 201, 154, 190]
}, },
{ {
name: '抖音', name: '抖音',
type: 'bar', type: 'bar',
label: labelOption,
data: [98, 77, 101, 99, 40] data: [98, 77, 101, 99, 40]
}, },
{ {
name: '其他', name: '其他',
type: 'bar', type: 'bar',
label: labelOption,
data: [25, 32, 46, 20, 8] data: [25, 32, 46, 20, 8]
} }
] ]
@ -170,90 +82,7 @@
var myChart2 = echarts.init(document.getElementById('chart2')); var myChart2 = echarts.init(document.getElementById('chart2'));
var posList = [
'left', 'right', 'top', 'bottom',
'inside',
'insideTop', 'insideLeft', 'insideRight', 'insideBottom',
'insideTopLeft', 'insideTopRight', 'insideBottomLeft', 'insideBottomRight'
];
myChart2.configParameters = {
rotate: {
min: -90,
max: 90
},
align: {
options: {
left: 'left',
center: 'center',
right: 'right'
}
},
verticalAlign: {
options: {
top: 'top',
middle: 'middle',
bottom: 'bottom'
}
},
position: {
options: echarts.util.reduce(posList, function (map, pos) {
map[pos] = pos;
return map;
}, {})
},
distance: {
min: 0,
max: 100
}
};
myChart2.config = {
rotate: 90,
align: 'left',
verticalAlign: 'middle',
position: 'insideBottom',
distance: 15,
onChange: function () {
var labelOption = {
normal: {
rotate: myChart2.config.rotate,
align: myChart2.config.align,
verticalAlign: myChart2.config.verticalAlign,
position: myChart2.config.position,
distance: myChart2.config.distance
}
};
myChart2.setOption({
series: [{
label: labelOption
}, {
label: labelOption
}, {
label: labelOption
}, {
label: labelOption
}]
});
}
};
var labelOption = {
show: true,
position: myChart.config.position,
distance: myChart.config.distance,
align: myChart.config.align,
verticalAlign: myChart.config.verticalAlign,
rotate: myChart.config.rotate,
formatter: '{c} {name|{a}}',
fontSize: 8,
rich: {
name: {
textBorderColor: '#fff'
}
}
};
var option = { var option = {
title: { title: {
text: '全省政务新媒体开设数量(逐月)', text: '全省政务新媒体开设数量(逐月)',
@ -290,31 +119,26 @@
name: '微信', name: '微信',
type: 'bar', type: 'bar',
barGap: 0, barGap: 0,
label: labelOption,
data: [40, 80, 44, 36, 78] data: [40, 80, 44, 36, 78]
}, },
{ {
name: '微博', name: '微博',
type: 'bar', type: 'bar',
label: labelOption,
data: [25, 14, 41, 10, 18] data: [25, 14, 41, 10, 18]
}, },
{ {
name: '头条', name: '头条',
type: 'bar', type: 'bar',
label: labelOption,
data: [21, 32, 21, 14, 19] data: [21, 32, 21, 14, 19]
}, },
{ {
name: '抖音', name: '抖音',
type: 'bar', type: 'bar',
label: labelOption,
data: [98, 77, 101, 99, 40] data: [98, 77, 101, 99, 40]
}, },
{ {
name: '其他', name: '其他',
type: 'bar', type: 'bar',
label: labelOption,
data: [25, 32, 46, 20, 8] data: [25, 32, 46, 20, 8]
} }
] ]

View File

@ -69,7 +69,7 @@
}, },
legend: { legend: {
top: '15%', top: '15%',
data: ['兰州市', '兰州新区', '嘉峪关市', '金昌市', '白银市', '天水市', '武威市', '张掖市', '平市', '酒泉市', '庆阳市', '定西市', '陇南市', '临夏回族自治州','甘南藏族自治州'] data: ['兰州市', '兰州新区', '嘉峪关市', '金昌市', '白银市', '天水市', '武威市', '张掖市', '平市', '酒泉市', '庆阳市', '定西市', '陇南市', '临夏回族自治州','甘南藏族自治州']
}, },
series: [ series: [
{ {

View File

@ -79,13 +79,13 @@ def create_media(request):
if o.directly == '省直部门': if o.directly == '省直部门':
admins = Userprofile.level1_admin() admins = Userprofile.level1_admin()
for a in admins: for a in admins:
content = '用户%s创建了新媒体,请审核' % (profile.name,) content = '%s创建了新媒体,请审核' % (profile,)
Notice.create_reply_notice( Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '3', '0') a.user.id, content, 'dashboard', model_name, 'status', instance.id, '3', '0')
else: else:
admins = Userprofile.level2_admin(instance.organization.cities) admins = Userprofile.level2_admin(instance.organization.cities)
for a in admins: for a in admins:
content = '用户%s创建了新媒体,请审核' % (profile.name,) content = '%s创建了新媒体,请审核' % (profile,)
Notice.create_reply_notice( Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '2', '0') a.user.id, content, 'dashboard', model_name, 'status', instance.id, '2', '0')
@ -222,12 +222,12 @@ def delete_media(request):
instance = Qita.objects.get(pk=media_id) instance = Qita.objects.get(pk=media_id)
result['media_id'] = instance.qitaid result['media_id'] = instance.qitaid
if o.directly == '省直部门': if o.is_direct():
instance.status = 5 instance.status = 5
instance.save() instance.save()
managers = Userprofile.level1_admin() managers = Userprofile.level1_admin()
for a in managers: for a in managers:
content = '用户%s申请注销新媒体,请审核' % (profile.name,) content = '%s申请注销新媒体,请审核' % (profile,)
Notice.create_reply_notice( Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '0', '3') a.user.id, content, 'dashboard', model_name, 'status', instance.id, '0', '3')
else: else:
@ -235,7 +235,7 @@ def delete_media(request):
instance.save() instance.save()
managers = Userprofile.level2_admin(instance.organization.cities) managers = Userprofile.level2_admin(instance.organization.cities)
for a in managers: for a in managers:
content = '用户%s申请注销新媒体,请审核' % (profile.name,) content = '%s申请注销新媒体,请审核' % (profile,)
Notice.create_reply_notice( Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '5', '3') a.user.id, content, 'dashboard', model_name, 'status', instance.id, '5', '3')

View File

@ -44,9 +44,7 @@ def monitor_statistics(request):
q = Weixin.objects.exclude(organization__cities='').values('organization__cities').order_by( q = Weixin.objects.exclude(organization__cities='').values('organization__cities').order_by(
'organization__cities').annotate(num_media=Count('organization__cities')) 'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q: for row in q:
print(row)
code = row['organization__cities'] code = row['organization__cities']
print(code)
compartment = COMPARTMENTS[code] compartment = COMPARTMENTS[code]
if code in results: if code in results:
nums = results[compartment] nums = results[compartment]
@ -54,7 +52,7 @@ def monitor_statistics(request):
else: else:
results[compartment] = [row['num_media']] results[compartment] = [row['num_media']]
q = Weibo.objects.exclude(organization__province='', organization__cities='').values('organization__cities').order_by( q = Weibo.objects.exclude(organization__cities='').values('organization__cities').order_by(
'organization__cities').annotate(num_media=Count('organization__cities')) 'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q: for row in q:
code = row['organization__cities'] code = row['organization__cities']
@ -65,7 +63,7 @@ def monitor_statistics(request):
else: else:
results[compartment] = [row['num_media']] results[compartment] = [row['num_media']]
q = Toutiao.objects.exclude(organization__province='', organization__cities='').values('organization__cities').order_by( q = Toutiao.objects.exclude(organization__cities='').values('organization__cities').order_by(
'organization__cities').annotate(num_media=Count('organization__cities')) 'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q: for row in q:
code = row['organization__cities'] code = row['organization__cities']
@ -76,7 +74,7 @@ def monitor_statistics(request):
else: else:
results[compartment] = [row['num_media']] results[compartment] = [row['num_media']]
q = Douyin.objects.exclude(organization__province='', organization__cities='').values('organization__cities').order_by( q = Douyin.objects.exclude(organization__cities='').values('organization__cities').order_by(
'organization__cities').annotate(num_media=Count('organization__cities')) 'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q: for row in q:
code = row['organization__cities'] code = row['organization__cities']
@ -87,7 +85,7 @@ def monitor_statistics(request):
else: else:
results[compartment] = [row['num_media']] results[compartment] = [row['num_media']]
q = Qita.objects.exclude(organization__province='', organization__cities='').values('organization__cities').order_by( q = Qita.objects.exclude(organization__cities='').values('organization__cities').order_by(
'organization__cities').annotate(num_media=Count('organization__cities')) 'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q: for row in q:
code = row['organization__cities'] code = row['organization__cities']
@ -98,6 +96,7 @@ def monitor_statistics(request):
else: else:
results[compartment] = [row['num_media']] results[compartment] = [row['num_media']]
chart2_data = [] chart2_data = []
for k in results: for k in results:
chart2_data.append({'name': k, 'value': sum(results[k])}) chart2_data.append({'name': k, 'value': sum(results[k])})

View File

@ -98,6 +98,8 @@ def detail_notice(request, notice_id):
detail['type'] = 'qita' detail['type'] = 'qita'
results['media'] = detail results['media'] = detail
detail['status'] = m.status detail['status'] = m.status
else:
detail['group_id'] = notice.group_id
results['added'] = notice.added.strftime("%Y-%m-%d %H:%M:%S") results['added'] = notice.added.strftime("%Y-%m-%d %H:%M:%S")
results['updated'] = notice.updated.strftime("%Y-%m-%d %H:%M:%S") results['updated'] = notice.updated.strftime("%Y-%m-%d %H:%M:%S")
return JsonResponse({'status': 'success', 'message': results}) return JsonResponse({'status': 'success', 'message': results})

View File

@ -71,8 +71,8 @@ def create_task(request):
users = Group_user.objects.filter(group=group) users = Group_user.objects.filter(group=group)
for u in users: for u in users:
g = Group.objects.get(id=group) g = Group.objects.get(id=group)
content = '用户%s在群组“%s”发布了任务,请查收消息' % (profile.name, g.name) content = '%s在群组“%s”发布了任务,请查收消息' % (profile, g.name)
Notice.create_normal_notice(u.user_id, content) Notice.create_normal_notice(u.user_id, content, group.id)
return JsonResponse({'status': 'success'}) return JsonResponse({'status': 'success'})