From 7a73917e1c242f6b65df9a45631fe553c060db89 Mon Sep 17 00:00:00 2001
From: raiots <raiot.lee@hotmail.com>
Date: Tue, 9 Mar 2021 17:08:31 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8F=AF=E8=87=AA=E5=AE=9A?=
 =?UTF-8?q?=E4=B9=89=E7=9A=84=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .gitignore                 |  1 +
 TasksManager/settings.py   | 26 +++++++++++++++++++++-----
 apps/tasks/views.py        |  5 ++++-
 apps/users/models.py       |  4 +++-
 templates/tasks/index.html |  4 ++++
 5 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore
index 0650171..9abb38b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
 /packagesdir/
 /db.sqlite3
 /identifier.sqlite
+migrations/
diff --git a/TasksManager/settings.py b/TasksManager/settings.py
index ca49cdc..addbf36 100644
--- a/TasksManager/settings.py
+++ b/TasksManager/settings.py
@@ -156,8 +156,8 @@ SIMPLEUI_HOME_ICON = 'el el-icon-platform-eleme'
 SIMPLEUI_DEFAULT_THEME = 'ant.design.css'
 
 SIMPLEUI_CONFIG = {
-    'system_keep': True,
-    'menu_display': ['任务管理', '系统配置', '多级菜单测试', '动态菜单测试'],      # 开启排序和过滤功能, 不填此字段为默认排序和全部显示, 空列表[] 为全部不显示.
+    'system_keep': False,
+    'menu_display': ['任务管理', '系统配置', '关于'],      # 开启排序和过滤功能, 不填此字段为默认排序和全部显示, 空列表[] 为全部不显示.
     'dynamic': True,    # 设置是否开启动态菜单, 默认为False. 如果开启, 则会在每次用户登陆时动态展示菜单内容
     'menus': [{
         'name': '任务管理',
@@ -177,9 +177,22 @@ SIMPLEUI_CONFIG = {
         'models': [{
             'name': '用户',
             'icon': 'fa fa-user',
-            'url': 'users/user'
+            'url': 'users/user',
         }, {
-            'name': '部门'
+            'name': '部门',
+            'url': 'users/department'
+        }, {
+            'name': '任务属性',
+            'url': 'users/taskproperty',
+        }, {
+            'name': '权限组',
+            'url': 'users/mygroup',
+        }, {
+            'name': '评价等级定义',
+            'url': 'users/qualitymark',
+        }, {
+            'name': '评价等级考核系数',
+            'url': 'users/markvalue'
         }]
     }, {
         # 自2021.02.01+ 支持多级菜单,models 为子菜单名
@@ -207,12 +220,15 @@ SIMPLEUI_CONFIG = {
             'icon': 'fab fa-github'
         }]
     }, {
-        'name': '动态菜单测试' ,
+        'name': '动态菜单测试',
         'icon': 'fa fa-desktop',
         'models': [{
             'name': time.time(),
             'url': 'http://baidu.com',
             'icon': 'far fa-surprise'
         }]
+    }, {
+        'name': '关于',
+        'url': '/about'
     }]
 }
diff --git a/apps/tasks/views.py b/apps/tasks/views.py
index 206d73b..78b46d3 100644
--- a/apps/tasks/views.py
+++ b/apps/tasks/views.py
@@ -1,6 +1,7 @@
 from django.contrib import auth, messages
 from django.contrib.auth import logout
 from django.contrib.auth.decorators import login_required
+from django.db.models import Sum, F
 from django.shortcuts import render, redirect
 from django.utils.decorators import method_decorator
 import django.utils.timezone as timezone
@@ -12,9 +13,11 @@ from apps.users.models import User
 
 
 class IndexView(View):
+    @method_decorator(login_required)
     def get(self, request):
         users = User.objects.all()
-        context = {'users': users}
+        points = User.objects.annotate(a=Sum(F('main_executor__predict_work') * F('main_executor__evaluate_factor') + F('sub_executor__predict_work') * F('sub_executor__evaluate_factor')))
+        context = {'users': users, 'points': points}
         return render(request, 'tasks/index.html', context)
 
 
diff --git a/apps/users/models.py b/apps/users/models.py
index f905bdb..b508e8b 100644
--- a/apps/users/models.py
+++ b/apps/users/models.py
@@ -20,7 +20,9 @@ class User(AbstractUser):
 
     @classmethod
     def get_total_point(cls):
-        return cls.objects.aggregate(total=Sum(F('main_executor__predict_work') * F('main_executor__evaluate_factor') + F('sub_executor__predict_work') * F('sub_executor__evaluate_factor')))['total']
+        return cls.objects.annotate(total=Sum('main_executor__predict_work'))
+    # def get_total_point(cls):
+    #     return cls.objects.aggregate(total=Sum(F('main_executor__predict_work') * F('main_executor__evaluate_factor') + F('sub_executor__predict_work') * F('sub_executor__evaluate_factor')))['total']
 
     @classmethod
     def get_predict_work_count(cls):
diff --git a/templates/tasks/index.html b/templates/tasks/index.html
index 102606b..936969f 100644
--- a/templates/tasks/index.html
+++ b/templates/tasks/index.html
@@ -125,6 +125,10 @@
         <!-- /.content -->
     </div>
         <div class="content-wrapper">
+        {% for point in points %}
+          {{ point }}
+          {{ point.a }}
+          {% endfor %}
 {#            {% for user in users %}#}
 {#                {{ user }}#}
 {#                {{ user.get_predict_work_count.total_predict_work }}#}