diff --git a/dashboard/models.py b/dashboard/models.py index b3eb3f0..2082d5d 100644 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -227,34 +227,39 @@ class NewMedia(models.Model): @classmethod def category_one_count(cls): t1 = Weixin.objects.exclude( + status=0, organization__province='' ).filter( organization__cities='', - organization__district='' + organization__district='', ).count() t2 = Weibo.objects.exclude( + status=0, organization__province='' ).filter( organization__cities='', - organization__district='' + organization__district='', ).count() t3 = Toutiao.objects.exclude( + status=0, organization__province='' ).filter( organization__cities='', - organization__district='' + organization__district='', ).count() t4 = Douyin.objects.exclude( + status=0, organization__province='' ).filter( organization__cities='', - organization__district='' + organization__district='', ).count() t5 = Qita.objects.exclude( + status=0, organization__province='' ).filter( organization__cities='', - organization__district='' + organization__district='', ).count() return t1 + t2 + t3 + t4 + t5 @@ -262,59 +267,69 @@ class NewMedia(models.Model): def category_two_count(cls): t1 = Weixin.objects.exclude( organization__province='', - organization__cities='' + organization__cities='', + status=0 ).filter( - organization__district='' + organization__district='', ).count() t2 = Weibo.objects.exclude( organization__province='', - organization__cities='' + organization__cities='', + status=0 ).filter( - organization__district='' + organization__district='', ).count() t3 = Toutiao.objects.exclude( organization__province='', - organization__cities='' + organization__cities='', + status=0 ).filter( - organization__district='' + organization__district='', ).count() t4 = Douyin.objects.exclude( organization__province='', - organization__cities='' + organization__cities='', + status=0 ).filter( - organization__district='' + organization__district='', ).count() t5 = Qita.objects.exclude( organization__province='', - organization__cities='' + organization__cities='', + status=0 ).filter( - organization__district='' + organization__district='', ).count() return t1 + t2 + t3 + t4 + t5 @classmethod def category_three_count(cls): t1 = Weixin.objects.exclude( + status=0, organization__province='', organization__cities='', organization__district='' ).count() t2 = Weibo.objects.exclude( + status=0, organization__province='', organization__cities='', organization__district='' ).count() t3 = Toutiao.objects.exclude( + status=0, organization__province='', organization__cities='', organization__district='' ).count() t4 = Douyin.objects.exclude( + status=0, organization__province='', organization__cities='', organization__district='' ).count() t5 = Qita.objects.exclude( + status=0, organization__province='', organization__cities='', organization__district='' diff --git a/polls/urls.py b/polls/urls.py index 4445520..c5939bb 100644 --- a/polls/urls.py +++ b/polls/urls.py @@ -45,6 +45,7 @@ urlpatterns = [ path('tasks/create_test/', views.create_test_task, name='polls_tasks_create_test'), path('groups/list/', views.groups, name='polls_groups_list'), + path('groups/pick/', views.pick_groups, name='polls_groups_pick'), path('groups/level/', views.is_level1_or_leve2, name='polls_groups_level'), path('groups/test-room/', views.room, name='polls_group_test_room'), path('groups/manager/', views.group_manager, name='polls_groups_manager'), diff --git a/polls/views/__init__.py b/polls/views/__init__.py index 03f69ff..9876443 100644 --- a/polls/views/__init__.py +++ b/polls/views/__init__.py @@ -4,7 +4,7 @@ from .media import medias, my_medias, create_media, update_media, media_detail, from .news import news_list, news_top, news_detail from .monitor import monitor_statistics, monitor_result, media_statistics, city_ranking from .task import tasks, create_task, create_test_task, get_task -from .group import groups, room, is_level1_or_leve2, group_member, group_manager, group_enter, group_leave +from .group import groups, room, is_level1_or_leve2, group_member, group_manager, group_enter, group_leave, pick_groups from .compartment import compartments from .organizations import organizations, organization_level from .message import last_messages, send_text_message, is_read_message, read_message diff --git a/polls/views/__pycache__/__init__.cpython-38.pyc b/polls/views/__pycache__/__init__.cpython-38.pyc index 9d0c3f0..7872445 100644 Binary files a/polls/views/__pycache__/__init__.cpython-38.pyc and b/polls/views/__pycache__/__init__.cpython-38.pyc differ diff --git a/polls/views/__pycache__/group.cpython-38.pyc b/polls/views/__pycache__/group.cpython-38.pyc index eedf5a1..abf3e42 100644 Binary files a/polls/views/__pycache__/group.cpython-38.pyc and b/polls/views/__pycache__/group.cpython-38.pyc differ diff --git a/polls/views/__pycache__/monitor.cpython-38.pyc b/polls/views/__pycache__/monitor.cpython-38.pyc index 77aeed7..6e4996d 100644 Binary files a/polls/views/__pycache__/monitor.cpython-38.pyc and b/polls/views/__pycache__/monitor.cpython-38.pyc differ diff --git a/polls/views/group.py b/polls/views/group.py index 28b8bb1..0bd4bdd 100644 --- a/polls/views/group.py +++ b/polls/views/group.py @@ -47,6 +47,25 @@ def groups(request): return JsonResponse({'status': 'success', 'message': results}, safe=False) +@csrf_exempt +@polls_login_required +def pick_groups(request): + if request.method == 'POST': + return HttpResponse(status=405) + user_id = request.user.id + category = request.GET.get('category') + q = Group.objects.filter(status=1, group_admin__user__id=user_id).distinct() + groups = q.filter(classify=category) if category else q + results = [] + for o in groups: + result = dict() + result['id'] = str(o.id) + print(o.id, o.name) + result['name'] = o.name + result['image'] = request.build_absolute_uri(o.image.url) + results.append(result) + return JsonResponse({'status': 'success', 'message': results}, safe=False) + @csrf_exempt @polls_login_required def group_manager(request): diff --git a/polls/views/monitor.py b/polls/views/monitor.py index 6840cb3..6c3350b 100644 --- a/polls/views/monitor.py +++ b/polls/views/monitor.py @@ -26,11 +26,11 @@ COMPARTMENTS = { @csrf_exempt def monitor_statistics(request): - wbc = Weibo.objects.count() - wxc = Weixin.objects.count() - ttc = Toutiao.objects.count() - qtc = Qita.objects.count() - dyc = Douyin.objects.count() + wbc = Weibo.objects.exclude(status=0).count() + wxc = Weixin.objects.exclude(status=0).count() + ttc = Toutiao.objects.exclude(status=0).count() + qtc = Qita.objects.exclude(status=0).count() + dyc = Douyin.objects.exclude(status=0).count() total = wbc+wxc+ttc+qtc+dyc chart1_data = [] @@ -41,10 +41,12 @@ def monitor_statistics(request): chart1_data.append({'name': '其它', 'value': qtc}) results = dict() - q = Weixin.objects.exclude(organization__cities='').values('organization__cities').order_by( + q = Weixin.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by( 'organization__cities').annotate(num_media=Count('organization__cities')) for row in q: code = row['organization__cities'] + if not code: + continue compartment = COMPARTMENTS[code] if code in results: nums = results[compartment] @@ -52,10 +54,12 @@ def monitor_statistics(request): else: results[compartment] = [row['num_media']] - q = Weibo.objects.exclude(organization__cities='').values('organization__cities').order_by( + q = Weibo.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by( 'organization__cities').annotate(num_media=Count('organization__cities')) for row in q: code = row['organization__cities'] + if not code: + continue compartment = COMPARTMENTS[code] if compartment in results: nums = results[compartment] @@ -63,10 +67,12 @@ def monitor_statistics(request): else: results[compartment] = [row['num_media']] - q = Toutiao.objects.exclude(organization__cities='').values('organization__cities').order_by( + q = Toutiao.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by( 'organization__cities').annotate(num_media=Count('organization__cities')) for row in q: code = row['organization__cities'] + if not code: + continue compartment = COMPARTMENTS[code] if compartment in results: nums = results[compartment] @@ -74,10 +80,12 @@ def monitor_statistics(request): else: results[compartment] = [row['num_media']] - q = Douyin.objects.exclude(organization__cities='').values('organization__cities').order_by( + q = Douyin.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by( 'organization__cities').annotate(num_media=Count('organization__cities')) for row in q: code = row['organization__cities'] + if not code: + continue compartment = COMPARTMENTS[code] if compartment in results: nums = results[compartment] @@ -85,17 +93,18 @@ def monitor_statistics(request): else: results[compartment] = [row['num_media']] - q = Qita.objects.exclude(organization__cities='').values('organization__cities').order_by( + q = Qita.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by( 'organization__cities').annotate(num_media=Count('organization__cities')) for row in q: code = row['organization__cities'] + if not code: + continue compartment = COMPARTMENTS[code] if compartment in results: nums = results[compartment] nums.append(row['num_media']) else: results[compartment] = [row['num_media']] - chart2_data = [] for k in results: