refact groupuser

This commit is contained in:
baoliang 2020-10-09 20:09:15 +08:00
parent ef4f9d7004
commit 1b41271a9c
12 changed files with 358 additions and 40 deletions

View File

@ -55,29 +55,15 @@ class Group(models.Model):
def __str__(self):
return self.name
# 矩阵管理员
class Group_admin(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
user = models.ForeignKey(
User, on_delete=models.CASCADE, null=True, blank=True)
group = models.ForeignKey(
Group, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
def __str__(self):
return self.group.name
# 矩阵成员
class Group_user(models.Model):
class GroupUser(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
user = models.ForeignKey(
User, on_delete=models.CASCADE, null=True, blank=True)
group = models.ForeignKey(
Group, on_delete=models.CASCADE, null=True, blank=True)
is_admin = models.BooleanField('是否管理', default=False)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
@ -157,7 +143,6 @@ class Userprofile(models.Model):
def level1_admin(cls):
return Userprofile.objects.filter(organization__level__level=1)
def __str__(self):
return self.user.username+":"+self.name

View File

@ -0,0 +1,131 @@
{% extends 'polls/base.html' %}
{% block content%}
<div class="col-xs-12">
<h4 class="title">市州合格率排行榜</h4>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th></th>
<th>不合格</th>
<th>合格</th>
<th>数量</th>
<th>合格率</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">武威市</th>
<td>0</td>
<td>4</td>
<td>4</td>
<td>100.0%</td>
</tr>
<tr>
<th scope="row">天水市</th>
<td>0</td>
<td>13</td>
<td>13</td>
<td>100.0%</td>
</tr>
<tr>
<th scope="row">金昌市</th>
<td>2</td>
<td>53</td>
<td>55</td>
<td>96.4%</td>
</tr>
<tr>
<th scope="row">嘉峪关市</th>
<td>3</td>
<td>44</td>
<td>47</td>
<td>93.6%</td>
</tr>
<tr>
<th scope="row">甘肃省</th>
<td>20</td>
<td>132</td>
<td>152</td>
<td>86.8%</td>
</tr>
<tr>
<th scope="row">兰州市</th>
<td>4</td>
<td>25</td>
<td>29</td>
<td>86.2%</td>
</tr>
<tr>
<th scope="row">平凉市</th>
<td>5</td>
<td>29</td>
<td>34</td>
<td>85.3%</td>
</tr>
<tr>
<th scope="row">庆阳市</th>
<td>27</td>
<td>137</td>
<td>164</td>
<td>83.5%</td>
</tr>
<tr>
<th scope="row">白银市</th>
<td>3</td>
<td>15</td>
<td>18</td>
<td>83.3%</td>
</tr>
<tr>
<th scope="row">临夏州</th>
<td>2</td>
<td>7</td>
<td>9</td>
<td>77.8%</td>
</tr>
<tr>
<th scope="row">兰州新区</th>
<td>12</td>
<td>39</td>
<td>51</td>
<td>76.5%</td>
</tr>
<tr>
<th scope="row">甘南州</th>
<td>2</td>
<td>6</td>
<td>8</td>
<td>75.0%</td>
</tr>
<tr>
<th scope="row">定西市</th>
<td>3</td>
<td>8</td>
<td>11</td>
<td>72.7%</td>
</tr>
<tr>
<th scope="row">酒泉市</th>
<td>3</td>
<td>6</td>
<td>9</td>
<td>66.7%</td>
</tr>
<tr>
<th scope="row">陇南市</th>
<td>12</td>
<td>17</td>
<td>29</td>
<td>58.6%</td>
</tr>
<tr>
<th scope="row">张掖市</th>
<td>3</td>
<td>4</td>
<td>7</td>
<td>57.1%</td>
</tr>
</tbody>
</table>
</div>
{% endblock%}

View File

@ -0,0 +1,167 @@
{% extends 'polls/base.html' %}
{% load static %}
{% block content%}
<div class="flex-container">
<div class="row">
<div class="col-xs-12">
<div id="chart1" style="width: 100%%;height:400px;margin:20px 10px;"></div>
</div>
</div>
</div>
{% endblock%}
{% block add_js %}
<script src="{% static 'polls/js/echarts.min.js' %}"></script>
<script type="text/javascript">
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 = {
title: {
text: '逐月累计发文量',
subtextStyle: {
fontSize: 16,
},
left: 'center'
},
color: ['#003366', '#006699', '#4cabce', '#e5323e', '#ccc'],
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
legend: {
top: '10%',
data: ['微信', '微博', '头条', '抖音', '其它']
},
xAxis: [
{
type: 'category',
axisTick: {show: false},
data: ['6月','7月', '8月', '9月', '10月']
}
],
yAxis: [
{
type: 'value'
}
],
series: [
{
name: '微信',
type: 'bar',
barGap: 0,
label: labelOption,
data: [320, 332, 301, 334, 390]
},
{
name: '微博',
type: 'bar',
label: labelOption,
data: [220, 182, 191, 234, 290]
},
{
name: '头条',
type: 'bar',
label: labelOption,
data: [150, 232, 201, 154, 190]
},
{
name: '抖音',
type: 'bar',
label: labelOption,
data: [98, 77, 101, 99, 40]
},
{
name: '其他',
type: 'bar',
label: labelOption,
data: [25, 32, 46, 20, 8]
}
]
};
myChart.setOption(option);
</script>
{% endblock %}

View File

@ -19,7 +19,8 @@ urlpatterns = [
path('notices/read/', views.read_notice, name='polls_read_notice'),
path('notices/pass/', views.pass_notice, name='polls_pass_notice'),
path('notices/reject/', views.reject_notice, name='polls_reject_notice'),
path('notices/detail/<str:notice_id>/', views.detail_notice, name='polls_detail_notice'),
path('notices/detail/<str:notice_id>/',
views.detail_notice, name='polls_detail_notice'),
path('medias/create/', views.create_media, name='polls_add_media'),
path('medias/update/', views.update_media, name='polls_update_media'),
path('medias/list/', views.medias, name='polls_medias'),
@ -33,6 +34,9 @@ urlpatterns = [
views.news_detail, name='polls_news_detail'),
path('monitor/statistics/', views.monitor_statistics,
name='polls_monitor_statistics'),
path('monitor/media/statistics/', views.media_statistics,
name='polls_media_statistics'),
path('monitor/city/ranking/', views.city_ranking, name='polls_city_ranking'),
path('monitor/result/', views.monitor_result,
name='polls_monitor_result'),
path('tasks/list/', views.tasks, name='polls_tasks_list'),

View File

@ -2,7 +2,7 @@ from .user import index, status_500, status_401, polls_login, send_code, registe
from .notice import notices, notice_top, read_notice, pass_notice, reject_notice, detail_notice
from .media import medias, my_medias, create_media, update_media, media_detail, delete_media
from .news import news_list, news_top, news_detail
from .monitor import monitor_statistics, monitor_result
from .monitor import monitor_statistics, monitor_result, media_statistics, city_ranking
from .task import tasks, create_task, create_test_task
from .group import groups, room
from .compartment import compartments

View File

@ -17,12 +17,11 @@ def room(request):
def groups(request):
if request.method == 'POST':
return HttpResponse(status=405)
id = request.user.id
user_id = request.user.id
category = request.GET.get('category', '0')
if not category:
return JsonResponse({'status': 'error', 'message': '参数错误'})
groups = Group.objects.filter(status='1',classify=category)
groups = Group.objects.filter(status='1',classify=category, group_user__user__id=user_id)
results = []
for o in groups:
result = dict()

View File

@ -52,33 +52,42 @@ def create_media(request):
attention = request.POST.get('attention', '')
remark = request.POST.get('remark', '')
model_name = ''
status = 2 if o.directly == '省直部门' else 1
if category == 'weixin':
model_name = 'Weixin'
instance = Weixin(code=code, weixinid=media_id, alias=alias,
image=f, status=1, organization=o, attention=attention, remark=remark)
image=f, status=status, organization=o, attention=attention, remark=remark)
elif category == 'weibo':
model_name = 'Weibo'
instance = Weibo(code=code, weiboid=media_id, alias=alias,
image=f, status=1, organization=o, attention=attention, remark=remark)
image=f, status=status, organization=o, attention=attention, remark=remark)
elif category == 'toutiao':
model_name = 'Toutiao'
instance = Toutiao(code=code, toutiaoid=media_id, alias=alias,
image=f, status=1, organization=o, attention=attention, remark=remark)
image=f, status=status, organization=o, attention=attention, remark=remark)
elif category == 'douyin':
model_name = 'Douyin'
instance = Douyin(code=code, douyinid=media_id, alias=alias,
image=f, status=1, organization=o, attention=attention, remark=remark)
image=f, status=status, organization=o, attention=attention, remark=remark)
else:
model_name = 'Qita'
type = request.POST.get('type')
instance = Qita(code=code, qitaid=media_id, alias=alias,
image=f, status=1, organization=o, attention=attention, remark=remark)
image=f, status=status, organization=o, attention=attention, remark=remark)
instance.save()
admins = Userprofile.level2_admin(instance.organization.cities)
for a in admins:
content = '用户%s创建了新媒体,请审核' % (profile.name,)
Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '2', '0')
if o.directly == '省直部门':
admins = Userprofile.level1_admin()
for a in admins:
content = '用户%s创建了新媒体,请审核' % (profile.name,)
Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '3', '0')
else:
admins = Userprofile.level2_admin(instance.organization.cities)
for a in admins:
content = '用户%s创建了新媒体,请审核' % (profile.name,)
Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '2', '0')
return JsonResponse({'status': 'success'})
@ -212,13 +221,23 @@ def delete_media(request):
model_name = 'Qita'
instance = Qita.objects.get(pk=media_id)
result['media_id'] = instance.qitaid
instance.status = 4
instance.save()
admins = Userprofile.level2_admin(instance.organization.cities)
for a in admins:
content = '用户%s申请注销新媒体,请审核' % (profile.name,)
Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '5', '3')
if o.directly == '省直部门':
instance.status = 5
instance.save()
managers = Userprofile.level1_admin()
for a in managers:
content = '用户%s申请注销新媒体,请审核' % (profile.name,)
Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '0', '3')
else:
instance.status = 4
instance.save()
managers = Userprofile.level2_admin(instance.organization.cities)
for a in managers:
content = '用户%s申请注销新媒体,请审核' % (profile.name,)
Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '5', '3')
admins = []
for admin in instance.organization.userprofile_set.all():

View File

@ -1,4 +1,6 @@
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from dashboard.models import Douyin, NewMedia, Qita, Toutiao, Weibo, Weixin
from django.db.models import Count, Sum
@ -22,6 +24,7 @@ COMPARTMENTS = {
}
@csrf_exempt
def monitor_statistics(request):
wbc = Weibo.objects.count()
wxc = Weixin.objects.count()
@ -109,5 +112,15 @@ def monitor_statistics(request):
return render(request, 'polls/monitor_statistics.html', {'chart1_data': chart1_data, 'total': total, 'chart2_data': chart2_data, 'chart3_data': chart3_data})
@csrf_exempt
def media_statistics(request):
return render(request, 'polls/media_statistics.html')
@csrf_exempt
def city_ranking(request):
return render(request, 'polls/city_ranking.html')
def monitor_result(request):
return render(request, 'polls/monitor_result.html')
return render(request, 'polls/monitor_result.html')