From 5084800861cb8705dd0d82c41d671f6d244a7263 Mon Sep 17 00:00:00 2001 From: xieshen <1397910458@qq.com> Date: Tue, 13 Oct 2020 10:56:12 +0800 Subject: [PATCH] =?UTF-8?q?#=E7=94=A8=E6=88=B7=E6=B3=A8=E5=86=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/templates/dashboard/register.html | 49 ++++++++++++++++----- dashboard/urls.py | 2 + dashboard/views.py | 30 ++++++++++--- management/views.py | 14 +++++- 4 files changed, 74 insertions(+), 21 deletions(-) diff --git a/dashboard/templates/dashboard/register.html b/dashboard/templates/dashboard/register.html index fa68c40..8610b58 100644 --- a/dashboard/templates/dashboard/register.html +++ b/dashboard/templates/dashboard/register.html @@ -59,16 +59,24 @@
{% csrf_token %} + {#

#} + {# #} + {#

#}

+ +

+

- +

@@ -88,12 +96,13 @@

+ +

-{#

#} -{# #} -{#

#} + {#

#} + {# #} + {#

#}

@@ -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 + '
') + } + ; + }) + }); + $('#search-text').keydown(function () { + $('#search-result').empty(); + }) + $('#search-text').blur(function () { + $('#search-result').empty(); + }) }) {% endblock %} diff --git a/dashboard/urls.py b/dashboard/urls.py index cdca9f0..348931f 100644 --- a/dashboard/urls.py +++ b/dashboard/urls.py @@ -17,5 +17,7 @@ urlpatterns = [ path('get/district/',views.get_district), path('get/town/',views.get_town), path('get/village/',views.get_village), + #单位搜索 + path('get/organization/',views.get_organization) ] diff --git a/dashboard/views.py b/dashboard/views.py index 95804da..1ba1d63 100644 --- a/dashboard/views.py +++ b/dashboard/views.py @@ -1,3 +1,5 @@ +import json + from captcha.helpers import captcha_image_url from captcha.models import CaptchaStore 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.models import User from django.db.models import Q -from django.http import HttpResponseRedirect, JsonResponse +from django.http import HttpResponseRedirect, JsonResponse, HttpResponse from django.shortcuts import render import datetime @@ -109,10 +111,6 @@ def register(request): messages.error(request, '请输入邮箱') else: 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'): messages.error(request, '请输入用户名') else: @@ -172,7 +170,7 @@ def register(request): def get_province(request): # 省 - province = Area_code_2020.objects.filter(level=1,name='甘肃省') + province = Area_code_2020.objects.filter(level=1, name='甘肃省') res = [] for i in province: res.append([i.code, i.name, i.level, i.pcode]) @@ -220,4 +218,22 @@ def get_village(request): 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)) diff --git a/management/views.py b/management/views.py index e41e782..a9943ca 100644 --- a/management/views.py +++ b/management/views.py @@ -582,7 +582,12 @@ def organization_create(request): level = Level.objects.all() if request.method == 'POST': 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') level_id = request.POST.get('level_id') province = request.POST.get('province') @@ -595,15 +600,20 @@ def organization_create(request): district = request.POST.get('district') town = request.POST.get('town') 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: organization = Organization(name=name, image=image, organizationtype_id=organizationtype, province=province, cities=city, district=district, town=town, village=village, level_id=level_id, status='0') organization.save() messages.success(request, '添加成功') + return HttpResponseRedirect('/management/organization/management/') else: messages.error(request, '单位名不能为空') - # return HttpResponseRedirect('/management/organization/management/') + return HttpResponseRedirect('/management/organization/create/') return render(request, 'management/organization-management-create.html', {'organizationtype': organizationtype, 'level': level})