#用户注册修改

This commit is contained in:
xieshen 2020-10-13 10:56:12 +08:00
parent e28948c3bd
commit 5084800861
4 changed files with 74 additions and 21 deletions

View File

@ -59,16 +59,24 @@
<form name="loginform" id="loginform" action="{% url 'dashboard-register' %}" method="post" <form name="loginform" id="loginform" action="{% url 'dashboard-register' %}" method="post"
enctype="multipart/form-data">{% csrf_token %} enctype="multipart/form-data">{% csrf_token %}
{# <p style="display: inline-block">#}
{# <label for="name">单位<br/>#}
{# <select class="form-control" name="organization">#}
{# {% for o in organization %}#}
{# <option value="{{ o.id }}">{{ o.name }}</option>#}
{# {% endfor %}#}
{# </select>#}
{# </label>#}
{# </p>#}
<p style="display: inline-block"> <p style="display: inline-block">
<label for="name">单位<br/> <label for="name">单位<br/>
<select class="form-control" name="organization"> <input type="text" id="search-text" name="organization">
{% for o in organization %} <p><span id='search-result'></span></p>
<option value="{{ o.id }}">{{ o.name }}</option> </label>
{% endfor %}
</select>
</label>
</p> </p>
<a href="{% url 'organization-management-create' %}"><span class="glyphicon glyphicon-plus" aria-hidden="true" style="margin-left: 40px"></span></a> <a href="{% url 'organization-management-create' %}"><span class="glyphicon glyphicon-plus"
aria-hidden="true"
style="margin-left: 40px"></span></a>
<p> <p>
<label for="name">姓名<br/> <label for="name">姓名<br/>
<input type="text" name="name" id="user_login" class="input" value="" size="20"/></label> <input type="text" name="name" id="user_login" class="input" value="" size="20"/></label>
@ -88,12 +96,13 @@
</p> </p>
<p> <p>
<label for="phone">电话<br/> <label for="phone">电话<br/>
<input type="text" name="username" id="user_login" class="input" value="" size="20"/></label> <input type="text" name="username" id="user_login" class="input" value="" size="20"/>
</label>
</p> </p>
{# <p>#} {# <p>#}
{# <label for="username">用户名<br/>#} {# <label for="username">用户名<br/>#}
{# <input type="text" name="username" id="user_login" class="input" value="" size="20"/></label>#} {# <input type="text" name="username" id="user_login" class="input" value="" size="20"/></label>#}
{# </p>#} {# </p>#}
<p> <p>
<label for="password">密码<br/> <label for="password">密码<br/>
<input type="password" name="password" id="user_pass" class="input" value="" size="20"/></label> <input type="password" name="password" id="user_pass" class="input" value="" size="20"/></label>
@ -183,6 +192,22 @@
}); });
}); });
$("#search-text").keyup(function () {
var q = $("#search-text").val();
$.getJSON("/get/organization/", {'q': q}, function (data) {
console.log(data[0].name)
for (var i = 0; i < data.length; i++) {
$('#search-result').append(data[i].name + '<br/>')
}
;
})
});
$('#search-text').keydown(function () {
$('#search-result').empty();
})
$('#search-text').blur(function () {
$('#search-result').empty();
})
}) })
</script> </script>
{% endblock %} {% endblock %}

View File

@ -17,5 +17,7 @@ urlpatterns = [
path('get/district/',views.get_district), path('get/district/',views.get_district),
path('get/town/',views.get_town), path('get/town/',views.get_town),
path('get/village/',views.get_village), path('get/village/',views.get_village),
#单位搜索
path('get/organization/',views.get_organization)
] ]

View File

@ -1,3 +1,5 @@
import json
from captcha.helpers import captcha_image_url from captcha.helpers import captcha_image_url
from captcha.models import CaptchaStore from captcha.models import CaptchaStore
from dateutil import relativedelta from dateutil import relativedelta
@ -5,7 +7,7 @@ from django.contrib import messages
from django.contrib.auth import logout, authenticate, login from django.contrib.auth import logout, authenticate, login
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db.models import Q from django.db.models import Q
from django.http import HttpResponseRedirect, JsonResponse from django.http import HttpResponseRedirect, JsonResponse, HttpResponse
from django.shortcuts import render from django.shortcuts import render
import datetime import datetime
@ -109,10 +111,6 @@ def register(request):
messages.error(request, '请输入邮箱') messages.error(request, '请输入邮箱')
else: else:
email = request.POST.get('email') email = request.POST.get('email')
# if not request.POST.get('phone'):
# messages.error(request, '请输入电话')
# else:
# phone = request.POST.get('phone')
if not request.POST.get('username'): if not request.POST.get('username'):
messages.error(request, '请输入用户名') messages.error(request, '请输入用户名')
else: else:
@ -172,7 +170,7 @@ def register(request):
def get_province(request): def get_province(request):
# 省 # 省
province = Area_code_2020.objects.filter(level=1,name='甘肃省') province = Area_code_2020.objects.filter(level=1, name='甘肃省')
res = [] res = []
for i in province: for i in province:
res.append([i.code, i.name, i.level, i.pcode]) res.append([i.code, i.name, i.level, i.pcode])
@ -220,4 +218,22 @@ def get_village(request):
return JsonResponse({"village": res}) return JsonResponse({"village": res})
def get_organization(request):
q = request.GET.get('q')
organization = Organization.objects.filter(name__contains=q)[:20]
res = []
for o in organization:
d = dict()
d['name'] = o.name
d['province'] = Area_code_2020.objects.get(code=o.province).name
if o.cities:
d['cities'] = Area_code_2020.objects.get(code=o.cities).name
else:
d['cities'] = ''
if o.district:
d['district'] = Area_code_2020.objects.get(code=o.district).name
else:
d['district'] = ''
res.append(d)
print(res)
return HttpResponse(json.dumps(res))

View File

@ -582,7 +582,12 @@ def organization_create(request):
level = Level.objects.all() level = Level.objects.all()
if request.method == 'POST': if request.method == 'POST':
name = request.POST.get('name') name = request.POST.get('name')
image = request.FILES.get('image') image = None
if request.FILES.get('image'):
image = request.FILES.get('image')
else:
image = 'danweimoren.jpg'
organizationtype = request.POST.get('organizationtype') organizationtype = request.POST.get('organizationtype')
level_id = request.POST.get('level_id') level_id = request.POST.get('level_id')
province = request.POST.get('province') province = request.POST.get('province')
@ -595,15 +600,20 @@ def organization_create(request):
district = request.POST.get('district') district = request.POST.get('district')
town = request.POST.get('town') town = request.POST.get('town')
village = request.POST.get('village') village = request.POST.get('village')
results = Organization.objects.filter(name=name).count()
if results > 0:
messages.error(request, '您注册的主体已经存在')
return HttpResponseRedirect('/management/organization/create/')
if name is not None: if name is not None:
organization = Organization(name=name, image=image, organizationtype_id=organizationtype, organization = Organization(name=name, image=image, organizationtype_id=organizationtype,
province=province, cities=city, district=district, town=town, province=province, cities=city, district=district, town=town,
village=village, level_id=level_id, status='0') village=village, level_id=level_id, status='0')
organization.save() organization.save()
messages.success(request, '添加成功') messages.success(request, '添加成功')
return HttpResponseRedirect('/management/organization/management/')
else: else:
messages.error(request, '单位名不能为空') messages.error(request, '单位名不能为空')
# return HttpResponseRedirect('/management/organization/management/') 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}) {'organizationtype': organizationtype, 'level': level})