From ee1ba062b3fafae2873f31ad421b0a5f9c5cf0f3 Mon Sep 17 00:00:00 2001 From: Bob <1397910458@qq.com> Date: Tue, 27 Oct 2020 21:04:28 +0800 Subject: [PATCH] =?UTF-8?q?#=E6=9B=B4=E6=94=B9=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/models.py | 1 - dashboard/urls.py | 7 + dashboard/views.py | 157 ++++++++++++-- .../templates/management/news-management.html | 4 +- .../templates/management/user-management.html | 202 +++++++++--------- management/views.py | 3 +- 6 files changed, 254 insertions(+), 120 deletions(-) diff --git a/dashboard/models.py b/dashboard/models.py index 66df770..4aeb3f7 100644 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -112,7 +112,6 @@ class Organizationtype(models.Model): def __str__(self): return self.organizationtype - # 单位 class Organization(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) diff --git a/dashboard/urls.py b/dashboard/urls.py index f288e24..53574db 100644 --- a/dashboard/urls.py +++ b/dashboard/urls.py @@ -25,6 +25,13 @@ urlpatterns = [ #单位搜索 path('get/organization/',views.get_organization,name='get-organization'), path('tencent13722515905013783955.txt', views.wechat_verify, name='wechat-verify'), + + #用户搜索 + path('user/search/by/keyword/',views.user_search_by_keyword,name='user-search-by-keyword'), + #新闻搜索 + path('news/search/by/keyword/',views.news_search_by_keyword,name='news-search-by-keyword'), + + #导入用户数据用的 path('import/user',views.import_user) diff --git a/dashboard/views.py b/dashboard/views.py index ca93d07..5e2303b 100644 --- a/dashboard/views.py +++ b/dashboard/views.py @@ -423,24 +423,151 @@ def import_user(request): return HttpResponse('ok') @login_required def user_search_by_keyword(request): + user = request.user + o = Organization.objects.get(userprofile__user_id=user.id) + level = o.level.level + province = o.province + cities = o.cities + district = o.district keytype = request.POST.get('keytype') keyword = request.POST.get('ketword') - userprofile = None - if keytype == '1': - userprofile = Userprofile.objects.filter(name__contains=keyword) - elif keytype == '2': - userprofile = Userprofile.objects.filter(organization__name__contains=keyword) - paginator = Paginator(userprofile, 6) - page = int(request.GET.get('page', 1)) - try: - userprofile = paginator.page(page) - except PageNotAnInteger: - userprofile = paginator.page(1) - except EmptyPage: - userprofile = paginator.page(paginator.num_pages) - for u in userprofile: + print(keytype,keyword) + userpaginator = None + if level == 1: + if keytype == '1': + userpaginator = Userprofile.objects.filter(name__contains=keyword,userprofile__organization__province=province)[:30] + elif keytype == '2': + userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,userprofile__organization__province=province)[:30] + elif level == 2: + if keytype == '1': + userpaginator = Userprofile.objects.filter(name__contains=keyword,userprofile__organization__province=province, + userprofile__organization__cities=cities)[:30] + elif keytype == '2': + userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,userprofile__organization__province=province, + userprofile__organization__cities=cities)[:30] + elif level == 3: + if keytype == '1': + userpaginator = Userprofile.objects.filter(name__contains=keyword,userprofile__organization__province=province, + userprofile__organization__cities=cities, + userprofile__organization__district=district)[:30] + elif keytype == '2': + userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,userprofile__organization__province=province, + userprofile__organization__cities=cities, + userprofile__organization__district=district)[:30] + elif level == 9: + if keytype == '1': + userpaginator = Userprofile.objects.filter(name__contains=keyword)[:30] + elif keytype == '2': + userpaginator = Userprofile.objects.filter(organization__name__contains=keyword)[:30] + + # paginator = Paginator(userpaginator, 6) + # page = int(request.GET.get('page', 1)) + # try: + # userpaginator = paginator.page(page) + # except PageNotAnInteger: + # userpaginator = paginator.page(1) + # except EmptyPage: + # userpaginator = paginator.page(paginator.num_pages) + userallinfo = [] + for u in userpaginator: o = dict() o['id'] = str(u.id) + if u.image: + o['image'] = u.image o['name'] = u.name - o['image'] = u.image.url + o['phone'] = User.objects.get(id=u.user_id).username + o['organization'] = u.organization.name + organization_id = u.organization_id + print(organization_id) + if Organization.objects.get(id=organization_id).province and Organization.objects.get( + id=organization_id).cities and Organization.objects.get( + id=organization_id).district and Organization.objects.get( + id=organization_id).town and Organization.objects.get(id=organization_id).village: + o['administrativedivision'] = str(str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).province)) + '-' + str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).cities)) + '-' + str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).district)) + '-' + str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).town)) + '-' + str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).village))).replace( + 'None', '') + elif Organization.objects.get(id=organization_id).province and Organization.objects.get( + id=organization_id).cities and Organization.objects.get( + id=organization_id).district and Organization.objects.get(id=organization_id).town: + o['administrativedivision'] = str(str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).province)) + '-' + str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).cities)) + '-' + str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).district)) + '-' + str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).town))).replace('None', + '') + elif Organization.objects.get(id=organization_id).province and Organization.objects.get( + id=organization_id).cities and Organization.objects.get(id=organization_id).district: + o['administrativedivision'] = str(str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).province)) + '-' + str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).cities)) + '-' + str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).district))).replace( + 'None', '') + elif Organization.objects.get(id=organization_id).province and Organization.objects.get( + id=organization_id).cities: + o['administrativedivision'] = str(str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).province)) + '-' + str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).cities))).replace( + 'None', '') + elif Organization.objects.get(id=organization_id).province: + o['administrativedivision'] = str(str( + Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).province))).replace( + 'None', '') + userallinfo.append(o) + print(userallinfo) + return render(request, 'management/user-management.html', + {'userallinfo': userallinfo, 'userpaginator': userpaginator}) +@login_required +def news_search_by_keyword(request): + keytype = request.POST.get('keytype') + keyword = request.POST.get('keyword') + print(keytype, keyword) + news = None + if keytype == '1': + news = News.objects.filter(type='0',title__contains=keyword)[:30] + elif keytype == '2': + news = News.objects.filter(type='1',title__contains=keyword)[:30] + elif keytype == '3': + news = News.objects.filter(type='2',title__contains=keyword)[:30] + elif keytype == '4': + news = News.objects.filter(type='3',title__contains=keyword)[:30] + elif keytype == '5': + news = News.objects.filter(type='4',title__contains=keyword)[:30] + elif keytype == '6': + news = News.objects.filter(type='5',title__contains=keyword)[:30] + elif keytype == '7': + news = News.objects.filter(type='6',title__contains=keyword)[:30] + news_list = [] + news_count = news.count() + for n in news: + o = dict() + o['id'] = str(n.id) + o['title'] = n.title + o['date'] = n.date + o['author'] = n.author + if n.type == '0': + o['type'] = '政策依据' + elif n.type == '1': + o['type'] = '基层动态' + elif n.type == '2': + o['type'] = '外省动态' + elif n.type == '3': + o['type'] = '监测通报' + elif n.type == '4': + o['type'] = '舆情热点' + elif n.type == '5': + o['type'] = '通知' + elif n.type == '6': + o['type'] = '重点新闻' + news_list.append(o) + return render(request, 'management/news-management.html', + {'news': news_list, 'new': news, 'news_count': news_count}) + +@login_required +def organization_search_by_keyword(request): + keytype = request.POST.get('keytype') + keyword = request.POST.get('keyword') diff --git a/management/templates/management/news-management.html b/management/templates/management/news-management.html index c47e6aa..0a63af3 100644 --- a/management/templates/management/news-management.html +++ b/management/templates/management/news-management.html @@ -42,7 +42,7 @@

新闻列表

-
+ {% csrf_token %}
- +
diff --git a/management/templates/management/user-management.html b/management/templates/management/user-management.html index afbb8a4..09a6bd6 100644 --- a/management/templates/management/user-management.html +++ b/management/templates/management/user-management.html @@ -1,101 +1,101 @@ -{% extends 'dashboard/base/base.html' %} -{% load static %} -{% block css %} - - -{% endblock %} -{% block content %} - -
-
- {% include 'dashboard/base/left.html' %} -
-
-
-
-
-
-

用户管理

-
-
-
-
-
-
-

成员列表

- -
- -
-
-
- - - - -
-
- -

成员总计:{{ user_count }}

-
-
-
-
- - - - - - - - - {# #} - - - - - - {% for u in userallinfo %} - - - - - - - {# #} - - - - {% endfor %} - -
序号头像姓名电话单位名称单位类型行政区划操作
{{ forloop.counter }}{{ u.name }}{{ u.phone }}{{ u.organization }}{{ u.type }}{{ u.administrativedivision }} - 删除 -
- -
-
-
-
-
-
-
-
-
-
- -{% endblock %} -{% block add_js %} - - - -{% endblock %} +{% extends 'dashboard/base/base.html' %} +{% load static %} +{% block css %} + + +{% endblock %} +{% block content %} + +
+
+ {% include 'dashboard/base/left.html' %} +
+
+
+
+
+
+

用户管理

+
+
+
+
+
+
+

成员列表

+
{% csrf_token %} +
+ +
+
+
+ + + + +
+
+
+

成员总计:{{ user_count }}

+
+
+
+
+ + + + + + + + + {# #} + + + + + + {% for u in userallinfo %} + + + + + + + {# #} + + + + {% endfor %} + +
序号头像姓名电话单位名称单位类型行政区划操作
{{ forloop.counter }}{{ u.name }}{{ u.phone }}{{ u.organization }}{{ u.type }}{{ u.administrativedivision }} + 删除 +
+ +
+
+
+
+
+
+
+
+
+
+ +{% endblock %} +{% block add_js %} + + + +{% endblock %} diff --git a/management/views.py b/management/views.py index 33d7d3d..0a3bc26 100644 --- a/management/views.py +++ b/management/views.py @@ -47,7 +47,8 @@ def user_management(request): for u in userpaginator: o = dict() o['id'] = str(u.id) - o['image'] = u.userprofile_set.get(user_id=u.id).image + if u.userprofile_set.get(user_id=u.id).image: + o['image'] = u.userprofile_set.get(user_id=u.id).image o['name'] = u.userprofile_set.get(user_id=u.id).name o['phone'] = u.username o['organization'] = u.userprofile_set.get(user_id=u.id).organization.name