#更改数据库

This commit is contained in:
Bob 2020-10-27 21:04:28 +08:00
parent 7360d61a8e
commit ee1ba062b3
6 changed files with 254 additions and 120 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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')

View File

@ -42,7 +42,7 @@
<section class="box ">
<header class="panel_header">
<h2 class="title pull-left">新闻列表</h2>
<form>
<form method="post" action="{% url 'news-search-by-keyword' %}">{% csrf_token %}
<div class="btn-group col-md-2 title" style="display: inline-block;margin-left: 5%">
<select class="form-control" name="keytype">
<option value="1">政策依据</option>
@ -58,7 +58,7 @@
<div class="input-group">
<input type="text" class="form-control" placeholder="输入搜索关键字" name="keyword">
<span class="input-group-btn">
<button class="btn btn-default" type="button">搜索</button>
<button class="btn btn-default" type="submit">搜索</button>
</span>
</div>
</div>

View File

@ -23,7 +23,7 @@
<section class="box ">
<header class="panel_header">
<h2 class="title pull-left">成员列表</h2>
<form>
<form action="{% url 'user-search-by-keyword' %}" method="post">{% csrf_token %}
<div class="btn-group col-md-2 title" style="display: inline-block;margin-left: 5%">
<select class="form-control" name="keytype">
<option value="1">姓名</option>
@ -33,9 +33,9 @@
</div>
<div class="col-lg-6 title">
<div class="input-group">
<input type="text" class="form-control" placeholder="输入搜索关键字" name="keyword">
<input type="text" class="form-control" placeholder="输入搜索关键字" name="ketword">
<span class="input-group-btn">
<button class="btn btn-default" type="button">搜索</button>
<button class="btn btn-default" type="submit">搜索</button>
</span>
</div>
</div>

View File

@ -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