diff --git a/dashboard/models.py b/dashboard/models.py index 4aeb3f7..b3c83f6 100644 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -101,7 +101,6 @@ class Group_user(models.Model): # 单位类型 - class Organizationtype(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) organizationtype = models.CharField( diff --git a/dashboard/urls.py b/dashboard/urls.py index 53574db..77a10c0 100644 --- a/dashboard/urls.py +++ b/dashboard/urls.py @@ -30,7 +30,10 @@ urlpatterns = [ 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('organization/search/by/keyword',views.organization_search_by_keyword,name='organization-search-by-keyword'), + #微信搜索 + path('weixin/search/by/keyword',views.weixin_search_by_keyword,name='weixin-search-by-keyword'), #导入用户数据用的 path('import/user',views.import_user) diff --git a/dashboard/views.py b/dashboard/views.py index 5e2303b..c4b715e 100644 --- a/dashboard/views.py +++ b/dashboard/views.py @@ -435,30 +435,30 @@ def user_search_by_keyword(request): userpaginator = None if level == 1: if keytype == '1': - userpaginator = Userprofile.objects.filter(name__contains=keyword,userprofile__organization__province=province)[:30] + userpaginator = Userprofile.objects.filter(name__contains=keyword,userprofile__organization__province=province) elif keytype == '2': - userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,userprofile__organization__province=province)[:30] + userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,userprofile__organization__province=province) elif level == 2: if keytype == '1': userpaginator = Userprofile.objects.filter(name__contains=keyword,userprofile__organization__province=province, - userprofile__organization__cities=cities)[:30] + userprofile__organization__cities=cities) elif keytype == '2': userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,userprofile__organization__province=province, - userprofile__organization__cities=cities)[:30] + userprofile__organization__cities=cities) 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] + userprofile__organization__district=district) elif keytype == '2': userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,userprofile__organization__province=province, userprofile__organization__cities=cities, - userprofile__organization__district=district)[:30] + userprofile__organization__district=district) elif level == 9: if keytype == '1': - userpaginator = Userprofile.objects.filter(name__contains=keyword)[:30] + userpaginator = Userprofile.objects.filter(name__contains=keyword) elif keytype == '2': - userpaginator = Userprofile.objects.filter(organization__name__contains=keyword)[:30] + userpaginator = Userprofile.objects.filter(organization__name__contains=keyword) # paginator = Paginator(userpaginator, 6) # page = int(request.GET.get('page', 1)) @@ -468,8 +468,9 @@ def user_search_by_keyword(request): # userpaginator = paginator.page(1) # except EmptyPage: # userpaginator = paginator.page(paginator.num_pages) + user_count = userpaginator.count() userallinfo = [] - for u in userpaginator: + for u in userpaginator[:30]: o = dict() o['id'] = str(u.id) if u.image: @@ -519,7 +520,7 @@ def user_search_by_keyword(request): userallinfo.append(o) print(userallinfo) return render(request, 'management/user-management.html', - {'userallinfo': userallinfo, 'userpaginator': userpaginator}) + {'userallinfo': userallinfo, 'userpaginator': userpaginator,'user_count':user_count}) @login_required def news_search_by_keyword(request): @@ -528,22 +529,22 @@ def news_search_by_keyword(request): print(keytype, keyword) news = None if keytype == '1': - news = News.objects.filter(type='0',title__contains=keyword)[:30] + news = News.objects.filter(type='0',title__contains=keyword) elif keytype == '2': - news = News.objects.filter(type='1',title__contains=keyword)[:30] + news = News.objects.filter(type='1',title__contains=keyword) elif keytype == '3': - news = News.objects.filter(type='2',title__contains=keyword)[:30] + news = News.objects.filter(type='2',title__contains=keyword) elif keytype == '4': - news = News.objects.filter(type='3',title__contains=keyword)[:30] + news = News.objects.filter(type='3',title__contains=keyword) elif keytype == '5': - news = News.objects.filter(type='4',title__contains=keyword)[:30] + news = News.objects.filter(type='4',title__contains=keyword) elif keytype == '6': - news = News.objects.filter(type='5',title__contains=keyword)[:30] + news = News.objects.filter(type='5',title__contains=keyword) elif keytype == '7': - news = News.objects.filter(type='6',title__contains=keyword)[:30] + news = News.objects.filter(type='6',title__contains=keyword) news_list = [] news_count = news.count() - for n in news: + for n in news[:30]: o = dict() o['id'] = str(n.id) o['title'] = n.title @@ -571,3 +572,164 @@ def news_search_by_keyword(request): def organization_search_by_keyword(request): keytype = request.POST.get('keytype') keyword = request.POST.get('keyword') + user = request.user + o = Organization.objects.get(userprofile__user_id=user.id) + print(o) + level = o.level.level + province = o.province + cities = o.cities + district = o.district + print(level, province, cities, district) + organization = None + res = [] + if level == 1: + if keytype == '1': + organization = Organization.objects.filter(province=province,name__contains=keyword).order_by('-created') + elif level == 2: + if keytype == '1': + organization = Organization.objects.filter(province=province, cities=cities,name__contains=keyword).order_by('-created') + elif level == 3: + if keytype == '1': + organization = Organization.objects.filter(province=province, cities=cities, district=district,name__contains=keyword).order_by( + '-created') + elif level == 9: + if keytype == '1': + organization = Organization.objects.filter(name__contains=keyword).order_by('-created') + organization_count = organization.count() + for i in organization[:30]: + print(i) + o = dict() + o['id'] = str(i.id) + o['name'] = i.name + o['image'] = i.image.url + if i.province and i.cities and i.district and i.town and i.village: + o['administrativedivision'] = str(Area_code_2020.objects.get(code=i.province).name) + '-' + str( + Area_code_2020.objects.get(code=i.cities).name) + '-' + str( + Area_code_2020.objects.get(code=i.district).name) + '-' + str( + Area_code_2020.objects.get(code=i.town).name) + '-' + str( + Area_code_2020.objects.get(code=i.village).name) + elif i.province and i.cities and i.district and i.town: + o['administrativedivision'] = str(Area_code_2020.objects.get(code=i.province).name) + '-' + str( + Area_code_2020.objects.get(code=i.cities).name) + '-' + str( + Area_code_2020.objects.get(code=i.district).name) + '-' + str( + Area_code_2020.objects.get(code=i.town).name) + elif i.province and i.cities and i.district: + o['administrativedivision'] = str(Area_code_2020.objects.get(code=i.province).name) + '-' + str( + Area_code_2020.objects.get(code=i.cities).name) + '-' + str( + Area_code_2020.objects.get(code=i.district).name) + elif i.province and i.cities: + o['administrativedivision'] = str(Area_code_2020.objects.get(code=i.province).name) + '-' + str( + Area_code_2020.objects.get(code=i.cities).name) + elif i.province: + o['administrativedivision'] = str(Area_code_2020.objects.get(code=i.province).name) + o['usercount'] = Userprofile.objects.filter(organization_id=i.id).count() + o['mediacount'] = Weixin.objects.filter(organization_id=i.id).count() + Weibo.objects.filter( + organization_id=i.id).count() + Toutiao.objects.filter( + organization_id=i.id).count() + Qita.objects.filter( + organization_id=i.id).count() + res.append(o) + + return render(request, 'management/organization-management.html', {"organization": organization, 'res': res,'organization_count':organization_count}) + +@login_required +def weixin_search_by_keyword(request): + keytype = request.POST.get('keytype') + keyword = request.POST.get('keyword') + 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 + weixin = None + res = [] + if level == 1: + if keytype == '1': + weixin = Weixin.objects.filter(organization__province=province,code__contains=keyword).order_by('-created') + elif keytype == '2': + weixin = Weixin.objects.filter(organization__province=province, organization__name__contains=keyword).order_by('-created') + elif level == 2: + if keytype == '1': + weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities,code__contains=keyword).order_by( + '-created') + elif keytype == '2': + weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities, organization__name__contains=keyword).order_by( + '-created') + elif level == 3: + if keytype == '1': + weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities, + organization__district=district,code__contains=keyword).order_by( + '-created') + elif keytype == '2': + weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities, + organization__district=district, organization__name__contains=keyword).order_by( + '-created') + elif level == 9: + if keytype == '1': + weixin = Weixin.objects.filter(code__contains=keyword).order_by('-created') + elif keytype == '2': + weixin = Weixin.objects.filter(organization__name__contains=keyword).order_by('-created') + weixin_count = weixin.count() + for w in weixin[:30]: + o = dict() + o['id'] = str(w.id) + if w.image: + o['image'] = w.image + o['code'] = w.code + o['weixinid'] = w.weixinid + o['organization'] = w.organization.name + # o['organization_type'] = w.organization.organizationtype.organizationtype + if len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len( + w.organization.district) > 0 and len(w.organization.town) > 0 and len(w.organization.village) > 0: + o['administrativedivision'] = str( + Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str( + Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str( + Area_code_2020.objects.get(code=w.organization.district).name) + '-' + str( + Area_code_2020.objects.get(code=w.organization.town).name) + '-' + str( + Area_code_2020.objects.get(code=w.organization.village).name) + elif len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len( + w.organization.district) > 0 and len(w.organization.town) > 0: + o['administrativedivision'] = str( + Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str( + Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str( + Area_code_2020.objects.get(code=w.organization.district).name) + '-' + str( + Area_code_2020.objects.get(code=w.organization.town).name) + elif len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len( + w.organization.district) > 0: + o['administrativedivision'] = str( + Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str( + Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str( + Area_code_2020.objects.get(code=w.organization.district).name) + elif len(w.organization.province) > 0 and len(w.organization.cities) > 0: + o['administrativedivision'] = str( + Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str( + Area_code_2020.objects.get(code=w.organization.cities).name) + elif len(w.organization.province) > 0: + o['administrativedivision'] = str(Area_code_2020.objects.get(code=w.organization.province).name) + o['status'] = w.status + res.append(o) + return render(request, 'management/newmedia-management-edit-weixin.html', {'weixin': weixin, 'res': res,'weixin_count':weixin_count}) +@login_required +def weibo_search_by_keyword(request): + keytype = request.POST.get('keytype') + keyword = request.POST.get('keyword') + 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 + weibo = None + res = [] + if level == 1: + if keytype == '1': + weibo = Weibo.objects.filter(organization__province=province,code__contains=keyword).order_by('-created') + elif keytype == '2': + weibo = Weibo.objects.filter(organization__province=province, organization__name__contains=keyword).order_by('-created') + elif level == 2: + weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities).order_by('-created') + elif level == 3: + weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities, + organization__district=district).order_by('-created') + elif level == 9: + weibo = Weibo.objects.all().order_by('-created') diff --git a/management/templates/management/newmedia-management-edit-weixin.html b/management/templates/management/newmedia-management-edit-weixin.html index c6f83b9..a156793 100644 --- a/management/templates/management/newmedia-management-edit-weixin.html +++ b/management/templates/management/newmedia-management-edit-weixin.html @@ -1,103 +1,103 @@ -{% extends 'dashboard/base/base.html' %} -{% load static %} -{% block css %} - - -{% endblock %} -{% block content %} - -
-
- {% include 'dashboard/base/left.html' %} -
-
-
-
-
-
-

新媒体编辑

-
-
-
-
-
-
-

微信公众号列表

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

微信总计:{{ weixin_count }}

-
-
-
-
- - - - - - - - - - - - - - - {% for w in res %} - - - - - - - - - - - {% endfor %} - -
序号图标新媒体名称新媒体ID责任主体行政区划状态操作
{{ forloop.counter }}{{ w.code }}{{ w.weixinid }}{{ w.organization }}{{ w.administrativedivision }}{{ w.status }} - 编辑 - 删除 -
- -
-
-
-
-
-
-
-
-
-
- -{% endblock %} -{% block add_js %} - - - -{% endblock %} +{% extends 'dashboard/base/base.html' %} +{% load static %} +{% block css %} + + +{% endblock %} +{% block content %} + +
+
+ {% include 'dashboard/base/left.html' %} +
+
+
+
+
+
+

新媒体编辑

+
+
+
+
+
+
+

微信公众号列表

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

微信总计:{{ weixin_count }}

+
+
+
+
+ + + + + + + + + + + + + + + {% for w in res %} + + + + + + + + + + + {% endfor %} + +
序号图标新媒体名称新媒体ID责任主体行政区划状态操作
{{ forloop.counter }}{{ w.code }}{{ w.weixinid }}{{ w.organization }}{{ w.administrativedivision }}{{ w.status }} + 编辑 + 删除 +
+ +
+
+
+
+
+
+
+
+
+
+ +{% endblock %} +{% block add_js %} + + + +{% endblock %} diff --git a/management/templates/management/organization-management.html b/management/templates/management/organization-management.html index d9768f4..140638e 100644 --- a/management/templates/management/organization-management.html +++ b/management/templates/management/organization-management.html @@ -42,18 +42,18 @@

单位列表

-
+ {% csrf_token %}
- +