#更改数据库

This commit is contained in:
Bob 2020-10-19 09:12:33 +08:00
parent 66a0d92483
commit 310a8a7024
3 changed files with 232 additions and 142 deletions

View File

@ -121,7 +121,7 @@
<option value="{{ group.classify }}">行业</option> <option value="{{ group.classify }}">行业</option>
{% endif %} {% endif %}
{% for g in g_c_c_res %} {% for g in g_c_c_res %}
<option value="{{ g }}">{{ g }}</option> <option value="{{ g.0 }}">{{ g.1 }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>

View File

@ -1,119 +1,162 @@
{% extends 'dashboard/base/base.html' %} {% extends 'dashboard/base/base.html' %}
{% load static %} {% load static %}
{% block content %} {% block content %}
<body class=" "> <body class=" ">
<!-- START TOPBAR --> <!-- START TOPBAR -->
<!-- START CONTAINER --> <!-- START CONTAINER -->
<div class="page-container row-fluid"> <div class="page-container row-fluid">
<div class="page-sidebar "> <div class="page-sidebar ">
{% include 'dashboard/base/left.html' %} {% include 'dashboard/base/left.html' %}
</div> </div>
<section id="main-content" class=" "> <section id="main-content" class=" ">
<section class="wrapper" style='margin-top:60px;display:inline-block;width:100%;padding:15px 0 0 15px;'> <section class="wrapper" style='margin-top:60px;display:inline-block;width:100%;padding:15px 0 0 15px;'>
{% if messages %} {% if messages %}
<div class="alert alert-success alert-dismissible" role="alert"> <div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert"> <button type="button" class="close" data-dismiss="alert">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
<span class="sr-only">Close</span> <span class="sr-only">Close</span>
</button> </button>
{% for message in messages %} {% for message in messages %}
{{ message }}.<br/> {{ message }}.<br/>
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}
<div class='col-lg-12 col-md-12 col-sm-12 col-xs-12'> <div class='col-lg-12 col-md-12 col-sm-12 col-xs-12'>
<div class="page-title"> <div class="page-title">
<div class="pull-left"> <div class="pull-left">
<h1 class="title">系统设置</h1></div> <h1 class="title">系统设置</h1></div>
</div> </div>
</div> </div>
<div class="clearfix"></div> <div class="clearfix"></div>
<div class="col-lg-12 col-md-12 col-xs-12 col-sm-12"> <div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
<section class="box "> <section class="box ">
<header class="panel_header"> <header class="panel_header">
<h2 class="title pull-left">用户信息</h2> <h2 class="title pull-left">用户信息</h2>
</header> </header>
<div class="content-body"> <div class="content-body">
<div class="row"> <div class="row">
<div class="col-md-8 col-sm-9 col-xs-10"> <div class="col-md-8 col-sm-9 col-xs-10">
<form method="post" <form method="post"
action="{% url 'user-management-update' usee.id %}" action="{% url 'user-management-update' usee.id %}"
enctype="multipart/form-data">{% csrf_token %} enctype="multipart/form-data">{% csrf_token %}
<div class="form-group"> <div class="form-group">
<label class="form-label" for="organization">单位</label> <label class="form-label" for="organization">单位</label>
<div class="controls"> {# <div class="controls">#}
<select class="form-control" name="organization"> {# <select class="form-control" name="organization">#}
<option value="{{ userprofile.organization.id }}">{{ userprofile.organization.name }}</option> {# <option value="{{ userprofile.organization.id }}">{{ userprofile.organization.name }}</option>#}
{% for o in organization %} {# {% for o in organization %}#}
<option value="{{ o.id }}">{{ o.name }}</option> {# <option value="{{ o.id }}">{{ o.name }}</option>#}
{% endfor %} {# {% endfor %}#}
</select> {# </select>#}
</div>
</div> {# </div>#}
<div class="form-group"> <div class="input-group main-search">
<label class="form-label" for="name">姓名</label> <input type="text" class="form-control" placeholder="请输入关键字"
<div class="controls"> style="height: 40px;width: 985px;opacity: .9 "
<input type="text" class="form-control" name="name" name="organization" value="{{ userprofile.organization.name }}">
value="{{ userprofile.name }}"> <div class="input-group-btn" style="display: none">
</div> <button class="btn btn-default" type="button">
</div> <span class="glyphicon glyphicon-search"></span>
<div class="form-group"> </button>
<label class="form-label" for="email">邮箱</label> </div>
<div class="controls"> </div>
<input type="text" class="form-control" name="email" <div class="autocomplete-panel" style="z-index: 9999">
value="{{ usee.email }}"> </div>
</div> </div>
</div> <div class="form-group">
<div class="form-group"> <label class="form-label" for="name">姓名</label>
<label class="form-label" for="username">电话</label> <div class="controls">
<div class="controls"> <input type="text" class="form-control" name="name"
<input type="text" class="form-control" name="username" value="{{ userprofile.name }}">
value="{{ usee.username }}"> </div>
</div> </div>
</div> <div class="form-group">
<label class="form-label" for="email">邮箱</label>
<div class="form-group"> <div class="controls">
<label class="form-label" for="image">图标 <input type="text" class="form-control" name="email"
<div class="controls"> value="{{ usee.email }}">
<input type="file" name="image"><img </div>
src="{{ userprofile.image.url }}" </div>
style="width: 80px;height: 80px;" <div class="form-group">
class="img-circle"> <label class="form-label" for="username">电话</label>
</div> <div class="controls">
</label> <input type="text" class="form-control" name="username"
</div> value="{{ usee.username }}">
<div class="form-group"> </div>
<label for="passwordold">旧密码<br/> </div>
<input type="password" name="passwordold" id="user_pass" class="input"
value="" size="20"/></label> <div class="form-group">
</div> <label class="form-label" for="image">图标
<div class="form-group"> <div class="controls">
<label for="passwordnew">新密码<br/> <input type="file" name="image"><img
<input type="password" name="passwordnew" id="user_pass" class="input" src="{{ userprofile.image.url }}"
value="" size="20"/></label> style="width: 80px;height: 80px;"
</div> class="img-circle">
<div class="form-group"> </div>
<label for="confirm_password">确认密码<br/> </label>
<input type="password" name="confirm_password" id="user_pass1" </div>
class="input" value="" <div class="form-group">
size="20"/></label> <label for="passwordold">旧密码<br/>
</div> <input type="password" name="passwordold" id="user_pass" class="input"
<button type="submit" class="btn btn-primary" style="margin-top: 50px">提交修改 value="" size="20"/></label>
</button> </div>
</form> <div class="form-group">
</div> <label for="passwordnew">新密码<br/>
</div> <input type="password" name="passwordnew" id="user_pass" class="input"
</div> value="" size="20"/></label>
</section> </div>
</div> <div class="form-group">
</section> <label for="confirm_password">确认密码<br/>
</section> <input type="password" name="confirm_password" id="user_pass1"
<div class="chatapi-windows "></div> class="input" value=""
</div> size="20"/></label>
</body> </div>
{% endblock %} <button type="submit" class="btn btn-primary" style="margin-top: 50px">提交修改
</button>
</form>
</div>
</div>
</div>
</section>
</div>
</section>
</section>
<div class="chatapi-windows "></div>
</div>
</body>
{% endblock %}
{% block add_js %}
<script>
$(function () {
$('.main-search input').focus(function (e) {
e.preventDefault();
$("#history_query").hide()
var width = $(this).width();
var position = $(this).position();
var val = $(this).val();
var params = {keyword: val}
if (val) {
$('.autocomplete-panel').load('/get/organization/' + '?' + $.param(params));
}
$('.autocomplete-panel').css({
width: width + 12,
top: position.top + 34,
left: position.left + 5
}).show();
}).blur(function (e) {
e.preventDefault();
}).on('input', function (e) {
var val = $(this).val();
var params = {keyword: val}
$('.autocomplete-panel').load('/get/organization/' + '?' + $.param(params))
});
})
</script>
{% endblock %}

View File

@ -52,8 +52,8 @@ def user_management(request):
print(organization_id) print(organization_id)
if Organization.objects.get(id=organization_id).province and Organization.objects.get( if Organization.objects.get(id=organization_id).province and Organization.objects.get(
id=organization_id).cities and Organization.objects.get( id=organization_id).cities and Organization.objects.get(
id=organization_id).district and Organization.objects.get( id=organization_id).district and Organization.objects.get(
id=organization_id).town and Organization.objects.get(id=organization_id).village: id=organization_id).town and Organization.objects.get(id=organization_id).village:
o['administrativedivision'] = str(str( 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).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).cities)) + '-' + str(
@ -63,7 +63,7 @@ def user_management(request):
'None', '') 'None', '')
elif Organization.objects.get(id=organization_id).province and Organization.objects.get( elif Organization.objects.get(id=organization_id).province and Organization.objects.get(
id=organization_id).cities and Organization.objects.get( id=organization_id).cities and Organization.objects.get(
id=organization_id).district and Organization.objects.get(id=organization_id).town: id=organization_id).district and Organization.objects.get(id=organization_id).town:
o['administrativedivision'] = str(str( 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).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).cities)) + '-' + str(
@ -106,7 +106,8 @@ def user_update(request, pk):
userprofile = Userprofile.objects.get(user_id=user.id) userprofile = Userprofile.objects.get(user_id=user.id)
organization = Organization.objects.filter(status='1') organization = Organization.objects.filter(status='1')
if request.method == 'POST': if request.method == 'POST':
organization_id = request.POST.get('organization') o = request.POST.get('organization')
o_id = Organization.objects.get(name=o).id
name = request.POST.get('name') name = request.POST.get('name')
email = request.POST.get('email') email = request.POST.get('email')
username = request.POST.get('username') username = request.POST.get('username')
@ -120,7 +121,7 @@ def user_update(request, pk):
user.email = email user.email = email
user.username = username user.username = username
user.password = make_password(passwordnew) user.password = make_password(passwordnew)
userprofile.organization_id = organization_id userprofile.organization_id = o_id
userprofile.name = name userprofile.name = name
if image is not None: if image is not None:
userprofile.image = image userprofile.image = image
@ -134,7 +135,7 @@ def user_update(request, pk):
else: else:
user.email = email user.email = email
user.username = username user.username = username
userprofile.organization_id = organization_id userprofile.organization_id = o_id
userprofile.name = name userprofile.name = name
if image is not None: if image is not None:
userprofile.image = image userprofile.image = image
@ -259,7 +260,7 @@ def group_update(request, pk):
GROUP_CLASSIFY_CHOICES = Group.GROUP_CLASSIFY_CHOICES GROUP_CLASSIFY_CHOICES = Group.GROUP_CLASSIFY_CHOICES
g_c_c_res = [] g_c_c_res = []
for g_c_c in GROUP_CLASSIFY_CHOICES: for g_c_c in GROUP_CLASSIFY_CHOICES:
g_c_c_res.append(list(g_c_c)[1]) g_c_c_res.append([list(g_c_c)[0], list(g_c_c)[1]])
group_type = Group_type.objects.all() group_type = Group_type.objects.all()
group_admin = Group_admin.objects.filter(group_id=pk) group_admin = Group_admin.objects.filter(group_id=pk)
print(pk) print(pk)
@ -271,8 +272,26 @@ def group_update(request, pk):
o['username'] = g_a.user.username o['username'] = g_a.user.username
o['name'] = Userprofile.objects.get(user_id=g_a.user.id).name o['name'] = Userprofile.objects.get(user_id=g_a.user.id).name
o['organization'] = Userprofile.objects.get(user_id=g_a.user.id).organization.name o['organization'] = Userprofile.objects.get(user_id=g_a.user.id).organization.name
o['administrativedivision'] = str(g_a.group.province) + '-' + str(g_a.group.cities) + '-' + str( if g_a.group.province and g_a.group.cities and g_a.group.district and g_a.group.town and g_a.group.village:
g_a.group.district) + '-' + str(g_a.group.town) + '-' + str(g_a.group.village) o['administrativedivision'] = str(Area_code_2020.objects.get(code=g_a.group.province).name) + '-' + str(
Area_code_2020.objects.get(code=g_a.group.cities).name) + '-' + str(
Area_code_2020.objects.get(code=g_a.group.district).name) + '-' + str(
Area_code_2020.objects.get(code=g_a.group.town).name) + '-' + str(
Area_code_2020.objects.get(code=g_a.group.village).name)
elif g_a.group.province and g_a.group.cities and g_a.group.district and g_a.group.town:
o['administrativedivision'] = str(Area_code_2020.objects.get(code=g_a.group.province).name) + '-' + str(
Area_code_2020.objects.get(code=g_a.group.cities).name) + '-' + str(
Area_code_2020.objects.get(code=g_a.group.district).name) + '-' + str(
Area_code_2020.objects.get(code=g_a.group.town).name)
elif g_a.group.province and g_a.group.cities and g_a.group.district:
o['administrativedivision'] = str(Area_code_2020.objects.get(code=g_a.group.province).name) + '-' + str(
Area_code_2020.objects.get(code=g_a.group.cities).name) + '-' + str(
Area_code_2020.objects.get(code=g_a.group.district).name)
elif g_a.group.province and g_a.group.cities:
o['administrativedivision'] = str(Area_code_2020.objects.get(code=g_a.group.province).name) + '-' + str(
Area_code_2020.objects.get(code=g_a.group.cities).name)
elif g_a.group.province:
o['administrativedivision'] = str(Area_code_2020.objects.get(code=g_a.group.province).name)
g_a_list.append(o) g_a_list.append(o)
group_user = Group_user.objects.filter(group_id=pk) group_user = Group_user.objects.filter(group_id=pk)
g_u_list = [] g_u_list = []
@ -283,8 +302,26 @@ def group_update(request, pk):
i['username'] = g_u.user.username i['username'] = g_u.user.username
i['name'] = Userprofile.objects.get(user_id=g_u.user.id).name i['name'] = Userprofile.objects.get(user_id=g_u.user.id).name
i['organization'] = Userprofile.objects.get(user_id=g_u.user.id).organization.name i['organization'] = Userprofile.objects.get(user_id=g_u.user.id).organization.name
i['administrativedivision'] = str(g_u.group.province) + '-' + str(g_u.group.cities) + '-' + str( if g_u.group.province and g_u.group.cities and g_u.group.district and g_u.group.town and g_u.group.village:
g_u.group.district) + '-' + str(g_u.group.town) + '-' + str(g_u.group.village) i['administrativedivision'] = str(Area_code_2020.objects.get(code=g_u.group.province).name) + '-' + str(
Area_code_2020.objects.get(code=g_u.group.cities).name) + '-' + str(
Area_code_2020.objects.get(code=g_u.group.district).name) + '-' + str(
Area_code_2020.objects.get(code=g_u.group.town).name) + '-' + str(
Area_code_2020.objects.get(code=g_u.group.village).name)
elif g_u.group.province and g_u.group.cities and g_u.group.district and g_u.group.town:
i['administrativedivision'] = str(Area_code_2020.objects.get(code=g_u.group.province).name) + '-' + str(
Area_code_2020.objects.get(code=g_u.group.cities).name) + '-' + str(
Area_code_2020.objects.get(code=g_u.group.district).name) + '-' + str(
Area_code_2020.objects.get(code=g_u.group.town).name)
elif g_u.group.province and g_u.group.cities and g_u.group.district:
i['administrativedivision'] = str(Area_code_2020.objects.get(code=g_u.group.province).name) + '-' + str(
Area_code_2020.objects.get(code=g_u.group.cities).name) + '-' + str(
Area_code_2020.objects.get(code=g_u.group.district).name)
elif g_u.group.province and g_u.group.cities:
i['administrativedivision'] = str(Area_code_2020.objects.get(code=g_u.group.province).name) + '-' + str(
Area_code_2020.objects.get(code=g_u.group.cities).name)
elif g_u.group.province:
i['administrativedivision'] = str(Area_code_2020.objects.get(code=g_u.group.province).name)
g_u_list.append(i) g_u_list.append(i)
if request.method == 'POST': if request.method == 'POST':
name = request.POST.get('name') name = request.POST.get('name')
@ -613,8 +650,18 @@ def organization_update(request, pk):
def organization_create(request): def organization_create(request):
organizationtype = Organizationtype.objects.all() user = request.user
level = Level.objects.all() l = Userprofile.objects.get(user_id=user.id).organization.level.level
if user.is_superuser:
level = Level.objects.filter(level__in=[1, 2, 3, 5, 0])
elif l == '1':
level = Level.objects.filter(level__in=[2, 3, 5, 0])
elif l == '2':
level = Level.objects.filter(level__in=[3, 5, 0])
elif l == '3':
level = Level.objects.filter(level__in=[5, 0])
else:
level = Level.objects.filter(level__in=[0])
if request.method == 'POST': if request.method == 'POST':
name = request.POST.get('name') name = request.POST.get('name')
image = None image = None
@ -650,7 +697,7 @@ def organization_create(request):
messages.error(request, '单位名不能为空') messages.error(request, '单位名不能为空')
return HttpResponseRedirect('/management/organization/create/') return HttpResponseRedirect('/management/organization/create/')
return render(request, 'management/organization-management-create.html', return render(request, 'management/organization-management-create.html',
{'organizationtype': organizationtype, 'level': level}) {'level': level})
@login_required @login_required
@ -1408,8 +1455,8 @@ def newmedia_management_update_douyin(request, pk):
if image is not None: if image is not None:
Douyin.objects.filter(id=pk).update(code=code, douyinid=douyinid, alias=alias, Douyin.objects.filter(id=pk).update(code=code, douyinid=douyinid, alias=alias,
organization_id=o_id, status=status, organization_id=o_id, status=status,
identificationcode=identificationcode, function=function, identificationcode=identificationcode, function=function,
articleurl=articleurl) articleurl=articleurl)
douyin.image = image douyin.image = image
douyin.save() douyin.save()
messages.success(request, '修改成功') messages.success(request, '修改成功')
@ -1417,8 +1464,8 @@ def newmedia_management_update_douyin(request, pk):
else: else:
Douyin.objects.filter(id=pk).update(code=code, douyinid=douyinid, alias=alias, Douyin.objects.filter(id=pk).update(code=code, douyinid=douyinid, alias=alias,
organization_id=o_id, status=status, organization_id=o_id, status=status,
identificationcode=identificationcode, function=function, identificationcode=identificationcode, function=function,
articleurl=articleurl) articleurl=articleurl)
messages.success(request, '修改成功') messages.success(request, '修改成功')
return HttpResponseRedirect('/management/newmedia/management/edit/douyin/') return HttpResponseRedirect('/management/newmedia/management/edit/douyin/')
else: else:
@ -1460,8 +1507,8 @@ def newmedia_management_update_qita(request, pk):
if image is not None: if image is not None:
Qita.objects.filter(id=pk).update(type=type, code=name, qitaid=qitaid, alias=alias, Qita.objects.filter(id=pk).update(type=type, code=name, qitaid=qitaid, alias=alias,
organization_id=o_id, status=status, organization_id=o_id, status=status,
identificationcode=identificationcode, function=function, identificationcode=identificationcode, function=function,
articleurl=articleurl) articleurl=articleurl)
qita.image = image qita.image = image
qita.save() qita.save()
messages.success(request, '修改成功') messages.success(request, '修改成功')
@ -1469,8 +1516,8 @@ def newmedia_management_update_qita(request, pk):
else: else:
Qita.objects.filter(id=pk).update(type=type, code=name, qitaid=qitaid, alias=alias, Qita.objects.filter(id=pk).update(type=type, code=name, qitaid=qitaid, alias=alias,
organization_id=o_id, status=status, organization_id=o_id, status=status,
identificationcode=identificationcode, function=function, identificationcode=identificationcode, function=function,
articleurl=articleurl) articleurl=articleurl)
messages.success(request, '修改成功') messages.success(request, '修改成功')
return HttpResponseRedirect('/management/newmedia/management/edit/qita/') return HttpResponseRedirect('/management/newmedia/management/edit/qita/')
else: else: