# -*- coding: utf-8 -*- import csv import datetime import json import random import math from django.contrib.auth import authenticate, login, logout from django.contrib.auth.models import User from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage from django.db.models import Q from django.http import JsonResponse, HttpResponse, FileResponse, StreamingHttpResponse from django.shortcuts import render from django.core.mail import send_mail # Create your views here. from django.views.decorators.csrf import csrf_exempt from dashboard.models import Task, Investigators, Findings, Sampletrees, Samplebush, Sampleherbal, \ Sampleinterlayerplants, Simplebiomass, Simplesoil, Barcodes, Landuse, Weather, Community, UserProfile, Jurisdiction, \ Verificationcode, Area_code_2020, Sampletreesalways, Samplebushalways, Sampleherbalalways, Special, Specieslibrary, \ Sampletreesplantimages, Samplebushplantimages, Sampleherbalplantimages, Dronephotos, Scenephoto, Accessory, \ Sampletreessampling, Samplebushsampling, Sampleherbalsampling, Vegetationcommunity, Simplesoilimage, Landusetype def index(request): return HttpResponse("OK") @csrf_exempt def user_login(request): obj = json.loads(request.body.decode('utf-8')) if request.method == 'POST': if not obj['username']: return HttpResponse('{"status":"0","message":"请输入用户名"}') else: username = obj['username'] if not obj['password']: return HttpResponse('{"status":"0","message":"请输入密码"}') else: password = obj['password'] if username is not None and password is not None: user = authenticate(username=username, password=password) if user is not None: if user.is_staff and user.is_active: login(request, user) return HttpResponse('{"status":"1","message":"登录成功"}') elif user.is_active is False: return HttpResponse('{"status":"0","message":"账户尚未激活,请到邮箱点击链接激活"}') else: return HttpResponse('{"status":"0","message":"用户名或密码错误"}') else: return HttpResponse('用户名或密码错误,请您确认用户名和密码 ') return HttpResponse('{"status":"0","message":"请用post请求"}') @csrf_exempt def user_register(request): flag = False if request.method == 'POST': obj = json.loads(request.body.decode('utf-8')) if not obj['username']: return HttpResponse('{"status":"0","message":"请输入用户名"}') else: username = obj['username'] if not obj['email']: return HttpResponse('{"status":"0","message":"请输入邮箱"}') else: email = obj['email'] if not obj['password']: return HttpResponse('{"status":"0","message":"请输入密码"}') else: password = obj['password'] if not obj['confirm_password']: return HttpResponse('{"status":"0","message":"请再次输入密码"}') else: confirm_password = obj['confirm_password'] if not obj['task']: return HttpResponse('{"status":"0","message":"请选择课题组"}') else: task = obj['task'] if not obj['special']: return HttpResponse('{"status":"0","message":"请选择专题组"}') else: special = obj['special'] phone = obj['phone'] name = obj['name'] organization = obj['organization'] if password is not None and confirm_password is not None: if password == confirm_password: flag = True else: return HttpResponse('{"status":"0","message":"两次输入的密码不一致,请重新输入"}') filter_result = User.objects.filter(email=email) filter_result_username = User.objects.filter(username=username) if len(filter_result) > 0 or len(filter_result_username) > 0: return HttpResponse('{"status":"0","message":"用户已存在"}') if username is not None and password is not None and confirm_password is not None and email is not None and flag: user = User.objects.create_user(username, email, password) user.first_name = phone user.last_name = organization user.is_active = False user.is_staff = True user.save() jurisdiction_id = Jurisdiction.objects.get(jurisdiction=4).id if special == '0': return HttpResponse('{"status":"0","message":"专题组不能为空"}') userprofile = UserProfile(user_id=user.id, task_id=task, jurisdiction_id=jurisdiction_id, name=name, special_id=special) userprofile.save() verificationcode = Verificationcode(user_id=user.id, verificationcode='0000') verificationcode.save() email = user.email form = [email, ] url = 'http://210.77.68.250:8081/user/activate/' + email send_mail('账号激活', '您已注册成功,请点击此链接激活账号:' + str(url), '1397910458qq@sina.com', form, fail_silently=False) return HttpResponse('{"status":"1","message":"注册成功,激活链接已发送至您的邮箱,请到邮箱激活后登录"}') else: task = Task.objects.all() results = [] for t in task: o = dict() o['id'] = str(t.id) o['organization'] = t.organization o['taskname'] = t.taskname o['taskcode'] = t.taskcode o['remark'] = t.remark results.append(o) return HttpResponse(json.dumps({ "task": results })) return HttpResponse('{"status":"0","message":"请使用post请求"}') # 用户注册邮箱激活 def email_activate(request, email): user = User.objects.get(email=email) user.is_active = True user.save() return render(request, 'dashboard/email_activate.html', {'email': email}) def user_logout(request): logout(request) return HttpResponse('{"status":"1","message":"登出成功"}') def user_info(request): username = request.GET.get('username') user = User.objects.get(username=username) if user.is_superuser is True: jurisdiction = '系统管理员' else: jurisdiction_id = UserProfile.objects.get(user_id=user.id).jurisdiction_id jurisdiction = Jurisdiction.objects.get(id=jurisdiction_id).explain results = [] o = dict() o['id'] = str(user.id) o['username'] = user.username o['organization'] = user.last_name o['phone'] = user.first_name o['email'] = user.email o['jurisdiction'] = jurisdiction o['data_joined'] = str(user.date_joined).split(' ')[0] results.append(o) return HttpResponse(json.dumps({ "status": "1", "user": results })) @csrf_exempt def reset_password(request): if request.method == 'POST': obj = json.loads(request.body.decode('utf-8')) user_id = obj['id'] password = obj['password'] verificationcode = obj['verification_code'] v = Verificationcode.objects.get(user_id=user_id).verificationcode if v == verificationcode: u = User.objects.get(id=user_id) u.set_password(password) u.save() return HttpResponse(json.dumps({ "status": "1", "message": "重置成功" })) else: return HttpResponse(json.dumps({ "status": "0", "message": "验证码错误" })) id = request.GET.get('id') user = User.objects.get(id=id) email = user.email form = [email, ] number = random.randint(1000, 9999) Verificationcode.objects.filter(user_id=user.id).update(verificationcode=number) send_mail('验证码', '您本次重置密码验证码为:' + str(number), '1397910458qq@sina.com', form, fail_silently=False) return HttpResponse('ok') # 忘记密码 @csrf_exempt def forget_password(request): if request.method == 'POST': obj = json.loads(request.body.decode('utf-8')) e = obj['email'] u = User.objects.get(email=e) password = obj['password'] verificationcode = obj['verification_code'] v = Verificationcode.objects.get(user_id=u.id).verificationcode if v == verificationcode: u = User.objects.get(id=u.id) u.set_password(password) u.save() return HttpResponse(json.dumps({ "status": "1", "message": "重置成功" })) else: return HttpResponse(json.dumps({ "status": "0", "message": "验证码错误" })) email = request.GET.get('email') results = User.objects.filter(email=email) if len(results) == 0: return HttpResponse(json.dumps({ "status": "0", "message": "该邮箱尚未注册,请输入正确的邮箱" })) form = [email, ] number = random.randint(1000, 9999) user = User.objects.get(email=email) Verificationcode.objects.filter(user_id=user.id).update(verificationcode=number) send_mail('验证码', '您本次重置密码验证码为:' + str(number), '1397910458qq@sina.com', form, fail_silently=False) return HttpResponse(json.dumps({ "status": "1", "message": "验证码已发送至您的邮箱,请查收" })) # 课题组 @csrf_exempt def task_add(request): obj = json.loads(request.body.decode('utf-8')) if request.method == 'POST': principal = obj['principal'] linkman = obj['linkman'] taskname = obj['taskname'] taskcode = obj['taskcode'] remark = obj['remark'] task = Task(principal=principal, linkman=linkman, taskname=taskname, taskcode=taskcode, remark=remark) task.save() return HttpResponse('{"status":"1","message":"添加成功"}') return HttpResponse('{"status":"0","message":"请发送post请求"}') def task_delete(request, pk): if pk: task = Task.objects.get(id=pk) task.delete() return HttpResponse('{"status":"1","message":"删除成功"}') else: return HttpResponse('{"status":"0","message":"请传入正确的id"}') @csrf_exempt def task_update(request, pk): task = Task.objects.get(id=pk) if request.method == 'POST': obj = json.loads(request.body.decode('utf-8')) principal = obj['principal'] linkman = obj['linkman'] taskname = obj['taskname'] taskcode = obj['taskcode'] remark = obj['remark'] Task.objects.filter(id=pk).update(principal=principal, linkman=linkman, taskname=taskname, taskcode=taskcode, remark=remark) return HttpResponse('{"status":"1","message":"修改成功"}') else: return HttpResponse(json.dumps({ "status": "1", "id": str(task.id), "taskcode": task.taskcode, "taskname": task.taskname, "principal": task.principal, "linkman": task.linkman, "remark": task.remark, })) def task_search(request): task = Task.objects.all().order_by('-created') results = [] for t in task: o = dict() o['id'] = str(t.id) o['principal'] = t.principal o['organization'] = t.organization o['taskname'] = t.taskname o['taskcode'] = t.taskcode o['remark'] = t.remark results.append(o) return HttpResponse(json.dumps({ "status": "1", "task": results })) # 调查者信息 @csrf_exempt def investigators_add(request): if request.method == 'POST': obj = json.loads(request.body.decode('utf-8')) form = obj['form'] if form is not None: investigators = Investigators(name=form['name'], phone=form['phone'], email=form['email'], organization=form['organization'], remark=form['remark']) investigators.save() return HttpResponse(json.dumps({ "status": "1", "message": "添加成功", })) else: return HttpResponse(json.dumps({ "status": "0", "message": "请输入完整信息", })) # username = request.GET.get('username') # user = User.objects.get(username=username) # print(username) # userProfile = UserProfile.objects.get(user_id=user.id) # if user.is_superuser is True or userProfile.jurisdiction == 0: # # task = Task.objects.all() # else: # task = Task.objects.filter(id=userProfile.task_id) # results = [] # print(task) # for t in task: # o = dict() # o['id'] = str(t.id) # o['organization'] = t.organization # o['taskname'] = t.taskname # o['taskcode'] = t.taskcode # o['remark'] = t.remark # results.append(o) return HttpResponse(json.dumps({ "status": "0" })) def investigators_delete(request, pk): if pk: investigators = Investigators.objects.get(id=pk) investigators.delete() return HttpResponse('{"status":"1","message":"删除成功"}') else: return HttpResponse('{"status":"0","message":"请传入正确的id"}') @csrf_exempt def investigators_update(request, pk): investigators = Investigators.objects.get(id=pk) if request.method == 'POST': obj = json.loads(request.body.decode('utf-8')) form = obj['form'] Investigators.objects.filter(id=pk).update(name=form['name'], phone=form['phone'], email=form['email'], organization=form['organization'], remark=form['remark']) return HttpResponse(json.dumps({ "status": "1", "message": "修改成功", })) else: # username = request.GET.get('username') # print(str(username) + "999999999999999999999999999999999999999999") # user = User.objects.get(username=username) # # userProfile = UserProfile.objects.get(user_id=user.id) # if user.is_superuser is True or userProfile.jurisdiction == 0: # # task = Task.objects.all() # else: # task = Task.objects.filter(id=userProfile.task_id) # resultstask = [] # for t in task: # o = dict() # o['id'] = str(t.id) # o['principal'] = str(t.principal) # o['organization'] = t.organization # o['taskname'] = t.taskname # o['taskcode'] = t.taskcode # o['remark'] = t.remark # resultstask.append(o) return HttpResponse(json.dumps({ "id": str(investigators.id), "name": investigators.name, "phone": investigators.phone, "email": investigators.email, "organization": investigators.organization, "remark": investigators.remark, })) def investigators_search(request): # username = request.GET.get('username') # task = Task.objects.get(userprofile__user__username=username) investigators = Investigators.objects.all().order_by('-created') results = [] paginator = Paginator(investigators, 10) page = int(request.GET.get('page', 1)) try: investigators_p = paginator.page(page) except PageNotAnInteger: investigators_p = paginator.page(1) except EmptyPage: investigators_p = paginator.page(paginator.num_pages) for i in investigators_p: o = dict() o['id'] = str(i.id) o['name'] = i.name o['phone'] = i.phone o['email'] = i.email o['organization'] = i.organization o['remark'] = i.remark results.append(o) return HttpResponse(json.dumps({ "status": "1", "investigators": results, "count": len(investigators), "page_count": math.ceil(len(investigators) / 10) })) def findings_search(request): findings = Findings.objects.all().order_by('-created') results = [] for f in findings: o = dict() o['findingscode'] = f.findingscode o['date'] = f.date o['id'] = str(f.id) o['investigators_id'] = str(f.investigators_id) results.append(o) return HttpResponse(json.dumps({ "status": "1", "findings": results })) # 样地 # @csrf_exempt # def quadrat_add(request): # if request.method == 'POST': # obj = json.loads(request.body.decode('utf-8')) # code = obj['code'] # type = obj['type'] # length = obj['length'] # wide = obj['wide'] # task = obj['task_taskname'] # task_id = Task.objects.get(taskname=task).id # findings = obj['findings_findingscode'] # findings_id = Findings.objects.get(findingscode=findings).id # print(str(task), str(findings)) # if code is not None: # quadrat = Quadrat(code=code, type=type, length=length, wide=wide, task_id=task_id, findings_id=findings_id) # quadrat.save() # # return HttpResponse(json.dumps({ # "status": "1", # "message": "添加成功", # })) # else: # return HttpResponse(json.dumps({ # "status": "", # "message": "请输入完整信息", # })) # findingscode = request.GET.get('findingscode') # findings = Findings.objects.get(findingscode=findingscode) # task = Task.objects.get(investigators__findings__id=findings.id) # print(str(task) + "66666666666666666666666666666") # return HttpResponse(json.dumps({ # "task_taskname": str(task.taskname), # "findings_findingscode": str(findings.findingscode), # })) # # # def quadrat_delete(request, pk): # if request.user.is_authenticated: # if pk: # quadrat = Quadrat.objects.get(id=pk) # quadrat.delete() # return HttpResponse('{"status":"1","message":"删除成功"}') # else: # return HttpResponse('{"status":"0","message":"请传入正确的id"}') # else: # return HttpResponse('{"status":"0","message":"请您登录后操作"}') # # # @csrf_exempt # def quadrat_update(request, pk): # if request.user.is_authenticated: # if pk: # quadrat = Quadrat.objects.get(id=pk) # if request.method == 'POST': # obj = json.loads(request.body.decode('utf-8')) # code = obj['code'] # type = obj['type'] # length = obj['length'] # wide = obj['wide'] # task = obj['task'] # findings = obj['findings'] # Quadrat.objects.filter(id=pk).update(code=code, type=type, length=length, wide=wide, task=task, # findings_id=findings) # return HttpResponse(json.dumps({ # "status": "1", # "message": "修改成功", # })) # task = Task.objects.all() # findings = Findings.objects.all() # taskresults = [] # findingsresults = [] # for t in task: # o = dict() # o['id'] = str(t.id) # o['principalid'] = str(t.principalid) # o['principalname'] = t.principalname # o['principalphone'] = t.principalphone # o['principalemail'] = t.principalemail # o['linkmanid'] = str(t.linkmanid) # o['linkmanname'] = t.linkmanname # o['linkmanphone'] = t.linkmanphone # o['linkmanemail'] = t.linkmanemail # o['organization'] = t.organization # o['taskname'] = t.taskname # o['taskcode'] = t.taskcode # o['remark'] = t.remark # taskresults.append(o) # for f in findings: # o = dict() # o['findingscode'] = f.findingscode # o['date'] = f.date # o['id'] = str(f.id) # o['investigators_id'] = str(f.investigators_id) # findingsresults.append(o) # return HttpResponse(json.dumps({ # "task": taskresults, # "findings": findingsresults, # "id": str(quadrat.id), # "code": quadrat.code, # "type": quadrat.type, # "length": quadrat.length, # "wide": quadrat.wide, # "task_id": str(quadrat.task_id), # "findings_id": str(quadrat.findings_id) # })) # else: # return HttpResponse('{"status":"0","message":"请传入正确的id"}') # else: # return HttpResponse('{"status":"0","message":"请您登录后操作"}') # # # def quadrat_search(request): # quadrat = Quadrat.objects.all() # results = [] # for q in quadrat: # o = dict() # o['id'] = str(q.id) # o['code'] = q.code # o['type'] = q.type # o['length'] = q.length # o['wide'] = q.wide # o['task_id'] = str(q.task_id) # o['findings_id'] = str(q.findings_id) # results.append(o) # return HttpResponse(json.dumps({ # "status": "1", # "quadrat": results # })) # 乔木样本 @csrf_exempt def sampletrees_add(request): name_choices = Sampletrees.NAME_CHOICES life_choices = Sampletrees.LIFE_CHOICES wuhou_choices = Sampletrees.WUHOU_CHOICES name_choices_results = [] life_choices_results = [] wuhou_choices_results = [] for n in name_choices: o = dict() o['name_choices'] = list(n)[0] name_choices_results.append(o) for l in life_choices: o = dict() o['life_choices'] = list(l)[0] life_choices_results.append(o) for w in wuhou_choices: o = dict() o['wuhou_choices'] = list(w)[0] wuhou_choices_results.append(o) enforcement = None economic = None smallkindarea = None dbh1 = None if request.method == 'POST': findingscode = request.POST.get('findingscode') findings = Findings.objects.get(findingscode=findingscode) username = request.POST.get('username') user = User.objects.get(username=username).username chinesename = request.POST.get('chinesename') latinname = request.POST.get('latinname') if len(chinesename) == 0 or len(latinname) == 0: return HttpResponse(json.dumps({ "status": "0", "message": "物种名不能为空" })) name = Specieslibrary.objects.filter(scientificchinesename=chinesename, latinname=latinname).count() if name == 0: specieslibrary = Specieslibrary(scientificchinesename=chinesename, latinname=latinname, status='0') specieslibrary.save() id = specieslibrary.id else: name = Specieslibrary.objects.get(scientificchinesename=chinesename, latinname=latinname) id = name.id # results = Sampletrees.objects.filter(name_id=id,findingscode=findingscode) # if len(results) != 0: # return HttpResponse(json.dumps({ # "status": "0", # "message": "该物种已经存在" # })) phenophase = request.POST.get('phenophase') biotype = request.POST.get('biotype') totalfreshweight = request.POST.get('totalfreshweight') freshweightofsample = request.POST.get('freshweightofsample') totaldryweight = request.POST.get('totaldryweight') dryweightofsample = request.POST.get('dryweightofsample') abundance = request.POST.get('abundance') if abundance == '': return HttpResponse(json.dumps({ "status": "0", "message": "请填写多度" })) radio1 = request.POST.get('radio1') radio2 = request.POST.get('radio2') radio3 = request.POST.get('radio3') sampletreerichness = request.POST.get('sampletreerichness') sampletreedensity = request.POST.get('sampletreedensity') sampletreesalways = Sampletreesalways(sampletreerichness=sampletreerichness, sampletreedensity=sampletreedensity) sampletreesalways.save() if radio1 == '1': enforcement = '是' elif radio1 == '2': enforcement = '否' else: return HttpResponse(json.dumps({ "status": "0", "message": "请选择是否为珍稀濒危物种" })) if radio2 == '1': economic = '是' elif radio2 == '2': economic = '否' else: return HttpResponse(json.dumps({ "status": "0", "message": "请选择是否为经济植物" })) if radio3 == '1': smallkindarea = '100m*100m' elif radio3 == '2': smallkindarea = '100m*20m' sampletrees = Sampletrees(findings_id=findings.id, smallkindarea=smallkindarea, name_id=id, phenophase=phenophase, biotype=biotype, totalfreshweight=totalfreshweight, freshweightofsample=freshweightofsample, totaldryweight=totaldryweight, dryweightofsample=dryweightofsample, abundance=abundance, enforcement=enforcement, publisher=user, sampletreesalways_id=sampletreesalways.id, economic=economic) sampletrees.save() i = 0 while request.POST.get("arrit[%s][dbh]" % (i)) is not None or request.POST.get( "arrit[%s][hight]" % (i)) is not None or request.POST.get("arrit[%s][canopy1]" % (i)) is not None: hight = request.POST.get("arrit[%s][hight]" % (i)) dbh = request.POST.get("arrit[%s][dbh]" % (i)) canopy1 = request.POST.get("arrit[%s][canopy1]" % (i)) canopy2 = request.POST.get("arrit[%s][canopy2]" % (i)) radio4 = request.POST.get("arrit[%s][radio4]" % (i)) if radio4 == '1': dbh1 = dbh elif radio4 == '2': dbh1 = float(dbh) / math.pi sampletreessampling = Sampletreessampling(hight=hight, dbh=dbh1, canopy1=canopy1, canopy2=canopy2, sampletrees_id=sampletrees.id) sampletreessampling.save() i += 1 j = 0 while request.POST.get("upload[%s][u]" % (j)) is not None: u = request.POST.get("upload[%s][u]" % (j)) im = request.FILES.get("inputtypefiles[%s][im]" % (j)) sampletreesplantimages = Sampletreesplantimages(type=u, file=im, sampletrees_id=sampletrees.id) sampletreesplantimages.save() j += 1 sampletrees_for_add_list = [] sampletreessampling_for_add_list = [] sampletrees_for_add = Sampletrees.objects.get(id=sampletrees.id) sampletreessampling_for_add = Sampletreessampling.objects.filter(sampletrees_id=sampletrees.id) for s_g in sampletreessampling_for_add: o = dict() o['id'] = str(s_g.id) o['hight'] = s_g.hight o['dbh'] = s_g.dbh o['canopy1'] = s_g.canopy1 o['canopy2'] = s_g.canopy2 sampletreessampling_for_add_list.append(o) o = dict() o['id'] = str(sampletrees_for_add.id) o['smallkindarea'] = sampletrees_for_add.smallkindarea o['chinesename'] = Specieslibrary.objects.get(id=sampletrees_for_add.name_id).scientificchinesename o['latinname'] = Specieslibrary.objects.get(id=sampletrees_for_add.name_id).latinname o['phenophase'] = sampletrees_for_add.phenophase o['biotype'] = sampletrees_for_add.biotype o['totalfreshweight'] = sampletrees_for_add.totalfreshweight o['freshweightofsample'] = sampletrees_for_add.freshweightofsample o['totaldryweight'] = sampletrees_for_add.totaldryweight o['dryweightofsample'] = sampletrees_for_add.dryweightofsample o['abundance'] = sampletrees_for_add.abundance o['enforcement'] = sampletrees_for_add.enforcement o['economic'] = sampletrees_for_add.economic o['sampletreerichness'] = Sampletreesalways.objects.get( sampletrees__id=sampletrees_for_add.id).sampletreerichness o['sampletreedensity'] = Sampletreesalways.objects.get(sampletrees__id=sampletrees_for_add.id).sampletreedensity sampletrees_for_add_list.append(o) return HttpResponse(json.dumps({ "status": "1", "message": "添加成功", "sampletrees_for_add_list": sampletrees_for_add_list, "sampletreessampling_for_add_list": sampletreessampling_for_add_list, "name_choices": name_choices_results, "life_choices": life_choices_results, "wuhou_choices": wuhou_choices_results, })) return HttpResponse(json.dumps({ "status": "1", "name_choices": name_choices_results, "life_choices": life_choices_results, "wuhou_choices": wuhou_choices_results, })) def sampletrees_delete(request, pk): if pk: sampletrees = Sampletrees.objects.get(id=pk) sampletrees.delete() return HttpResponse('{"status":"1","message":"删除成功"}') else: return HttpResponse('{"status":"0","message":"请传入正确的id"}') @csrf_exempt def sampletrees_update(request, pk): name_choices = Sampletrees.NAME_CHOICES life_choices = Sampletrees.LIFE_CHOICES wuhou_choices = Sampletrees.WUHOU_CHOICES name_choices_results = [] life_choices_results = [] wuhou_choices_results = [] for n in name_choices: o = dict() o['name_choices'] = list(n)[0] name_choices_results.append(o) for l in life_choices: o = dict() o['life_choices'] = list(l)[0] life_choices_results.append(o) for w in wuhou_choices: o = dict() o['wuhou_choices'] = list(w)[0] wuhou_choices_results.append(o) enforcement = None economic = None smallkindarea = None dbh1 = None sampletrees = Sampletrees.objects.get(id=pk) sampletreesalways = Sampletreesalways.objects.get(id=sampletrees.sampletreesalways_id) if request.method == 'POST': username = request.POST.get('username') chinesename = request.POST.get('chinesename') latinname = request.POST.get('latinname') name = Specieslibrary.objects.filter(scientificchinesename=chinesename, latinname=latinname).count() if len(chinesename) == 0 or len(latinname) == 0: return HttpResponse(json.dumps({ "status": "0", "message": "物种名不能为空" })) if name == 0: specieslibrary = Specieslibrary(scientificchinesename=chinesename, latinname=latinname, status='0') specieslibrary.save() id = specieslibrary.id else: name = Specieslibrary.objects.get(scientificchinesename=chinesename, latinname=latinname) id = name.id phenophase = request.POST.get('phenophase') biotype = request.POST.get('biotype') totalfreshweight = request.POST.get('totalfreshweight') freshweightofsample = request.POST.get('freshweightofsample') totaldryweight = request.POST.get('totaldryweight') dryweightofsample = request.POST.get('dryweightofsample') abundance = request.POST.get('abundance') radio1 = request.POST.get('radio1') radio2 = request.POST.get('radio2') radio3 = request.POST.get('radio3') if radio1 == '1': enforcement = '是' elif radio1 == '2': enforcement = '否' if radio2 == '1': economic = '是' elif radio2 == '2': economic = '否' if radio3 == '1': smallkindarea = '100m*100m' elif radio3 == '2': smallkindarea = '100m*20m' sampletreerichness = request.POST.get('sampletreerichness') sampletreedensity = request.POST.get('sampletreedensity') Sampletreesalways.objects.filter(id=sampletreesalways.id).update(sampletreerichness=sampletreerichness, sampletreedensity=sampletreedensity) Sampletrees.objects.filter(id=pk).update( smallkindarea=smallkindarea, name_id=id, phenophase=phenophase, biotype=biotype, totalfreshweight=totalfreshweight, freshweightofsample=freshweightofsample, totaldryweight=totaldryweight, dryweightofsample=dryweightofsample, abundance=abundance, enforcement=enforcement, publisher=username, sampletreesalways_id=sampletreesalways.id, economic=economic) i = 0 while request.POST.get("arrit[%s][dbh]" % (i)) is not None or request.POST.get( "arrit[%s][hight]" % (i)) is not None or request.POST.get("arrit[%s][canopy1]" % (i)) is not None: id = request.POST.get("arrit[%s][id]" % (i)) hight = request.POST.get("arrit[%s][hight]" % (i)) dbh = request.POST.get("arrit[%s][dbh]" % (i)) canopy1 = request.POST.get("arrit[%s][canopy1]" % (i)) canopy2 = request.POST.get("arrit[%s][canopy2]" % (i)) radio4 = request.POST.get("arrit[%s][radio4]" % (i)) if radio4 == '1': dbh1 = dbh elif radio4 == '2': dbh1 = float(dbh) / math.pi if id is not None: Sampletreessampling.objects.filter(id=id).update(hight=hight, dbh=dbh1, canopy1=canopy1, canopy2=canopy2) else: sampletreessampling = Sampletreessampling(hight=hight, dbh=dbh1, canopy1=canopy1, canopy2=canopy2, sampletrees_id=pk) sampletreessampling.save() i += 1 j = 0 while request.POST.get("upload[%s][u]" % (j)) is not None: u = request.POST.get("upload[%s][u]" % (j)) im = request.FILES.get("inputtypefiles[%s][im]" % (j)) sampletreesplantimages = Sampletreesplantimages(type=u, file=im, sampletrees_id=sampletrees.id) sampletreesplantimages.save() j += 1 return HttpResponse(json.dumps({ "status": "1", "message": "修改成功", "name_choices": name_choices_results, "life_choices": life_choices_results, "wuhou_choices": wuhou_choices_results, })) file_list = [] sampletreessampling_list = [] sampletreesplantimages = Sampletreesplantimages.objects.filter(sampletrees__id=pk) sampletreessampling = Sampletreessampling.objects.filter(sampletrees__id=pk) for s_g in sampletreessampling: o = dict() o['id'] = str(s_g.id) o['hight'] = s_g.hight o['dbh'] = s_g.dbh o['canopy1'] = s_g.canopy1 o['canopy2'] = s_g.canopy2 o['radio4'] = '1' sampletreessampling_list.append(o) for s in sampletreesplantimages: file = dict() file['file'] = s.file.url file['type'] = s.type file['id'] = str(s.id) file_list.append(file) e = None if sampletrees.enforcement == '是': e = '1' elif sampletrees.enforcement == '否': e = '2' c = None if sampletrees.economic == '是': c = '1' elif sampletrees.economic == '否': c = '2' return HttpResponse(json.dumps({ "id": str(sampletrees.id), "smallkindarea": sampletrees.smallkindarea, "chinesename": Specieslibrary.objects.get(id=sampletrees.name_id).scientificchinesename, "latinname": Specieslibrary.objects.get(id=sampletrees.name_id).latinname, "phenophase": sampletrees.phenophase, "biotype": sampletrees.biotype, "totalfreshweight": sampletrees.totalfreshweight, "freshweightofsample": sampletrees.freshweightofsample, "totaldryweight": sampletrees.totaldryweight, "dryweightofsample": sampletrees.dryweightofsample, "abundance": sampletrees.abundance, "enforcement": e, "economic": c, "name_choices": name_choices_results, "life_choices": life_choices_results, "wuhou_choices": wuhou_choices_results, "sampletreerichness": sampletreesalways.sampletreerichness, "sampletreedensity": sampletreesalways.sampletreedensity, "sampletreessampling_list": sampletreessampling_list, "file_list": list(file_list) })) def sampletrees_search(request): findingscode = request.GET.get('findingscode') sampletrees = Sampletrees.objects.filter(findings__findingscode=findingscode).order_by('-created') results = [] paginator = Paginator(sampletrees, 10) page = int(request.GET.get('page', 1)) try: sampletrees_p = paginator.page(page) except PageNotAnInteger: sampletrees_p = paginator.page(1) except EmptyPage: sampletrees_p = paginator.page(paginator.num_pages) for s in sampletrees_p: o = dict() o['id'] = str(s.id) o['chinesename'] = Specieslibrary.objects.get(id=s.name_id).scientificchinesename o['latinname'] = Specieslibrary.objects.get(id=s.name_id).latinname # o['hight'] = s.hight # o['dbh'] = s.dbh # o['canopy1'] = s.canopy1 # o['canopy2'] = s.canopy2 o['phenophase'] = s.phenophase o['biotype'] = s.biotype o['totalfreshweight'] = s.totalfreshweight o['freshweightofsample'] = s.freshweightofsample o['totaldryweight'] = s.totaldryweight o['dryweightofsample'] = s.dryweightofsample o['findings'] = findingscode results.append(o) return HttpResponse(json.dumps({ "status": "1", "sampletrees": results, "count": len(sampletrees), "page_count": math.ceil(len(sampletrees) / 10) })) # 灌木样本 @csrf_exempt def samplebush_add(request): name_choices = Samplebush.NAME_CHOICES name_choices_results = [] for n in name_choices: o = dict() o['name_choices'] = list(n)[0] name_choices_results.append(o) if request.method == 'POST': enforcement = None typical = None economic = None findingscode = request.POST.get('findingscode') findings = Findings.objects.get(findingscode=findingscode) username = request.POST.get('username') chinesename = request.POST.get('chinesename') latinname = request.POST.get('latinname') if len(chinesename) == 0 or len(latinname) == 0: return HttpResponse(json.dumps({ "status": "0", "message": "物种名不能为空" })) smallkindside = request.POST.get('smallkindside') if len(smallkindside) == 0: return HttpResponse(json.dumps({ "status": "0", "message": "小样方号不能为空" })) name = Specieslibrary.objects.filter(scientificchinesename=chinesename, latinname=latinname).count() if name == 0: specieslibrary = Specieslibrary(scientificchinesename=chinesename, latinname=latinname, status='0') specieslibrary.save() id = specieslibrary.id else: name = Specieslibrary.objects.get(scientificchinesename=chinesename, latinname=latinname) id = name.id results = Samplebush.objects.filter(name_id=id, smallkindside=smallkindside, findings__findingscode=findingscode) if len(results) != 0: return HttpResponse(json.dumps({ "status": "0", "message": "该物种已经存在" })) coverdegree = request.POST.get('coverdegree') frequency = request.POST.get('frequency') totalfreshweight = request.POST.get('totalfreshweight') freshweightofsample = request.POST.get('freshweightofsample') totaldryweight = request.POST.get('totaldryweight') dryweightofsample = request.POST.get('dryweightofsample') abundance = request.POST.get('abundance') samplebushrichness = request.POST.get('samplebushrichness') samplebushdensity = request.POST.get('samplebushdensity') radio1 = request.POST.get('radio1') radio2 = request.POST.get('radio2') radio3 = request.POST.get('radio3') number = request.POST.get('number') if radio1 == '1': enforcement = '是' elif radio1 == '2': enforcement = '否' else: return HttpResponse(json.dumps({ "status": "0", "message": "请选择是否为珍稀濒危物种" })) if radio2 == '1': economic = '是' elif radio2 == '2': economic = '否' else: return HttpResponse(json.dumps({ "status": "0", "message": "请选择是否为经济植物" })) if radio3 == '1': typical = '是' elif radio3 == '2': typical = '否' else: return HttpResponse(json.dumps({ "status": "0", "message": "请选择是否为优势灌木" })) samplebushalways = Samplebushalways(samplebushrichness=samplebushrichness, samplebushdensity=samplebushdensity) samplebushalways.save() if findingscode is not None: samplebush = Samplebush(findings_id=findings.id, smallkindside=smallkindside, smallkindarea='10m*10m', name_id=id, coverdegree=coverdegree, totalfreshweight=totalfreshweight, totaldryweight=totaldryweight, abundance=abundance, enforcement=enforcement, publisher=username, samplebushalways_id=samplebushalways.id, typical=typical, economic=economic, frequency=frequency, number=number) samplebush.save() i = 0 while request.POST.get("arrit[%s][hight]" % (i)) is not None: hight = request.POST.get("arrit[%s][hight]" % (i)) canopy1 = request.POST.get("arrit[%s][canopy1]" % (i)) canopy2 = request.POST.get("arrit[%s][canopy2]" % (i)) dryweightofsample = request.POST.get("arrit[%s][dryweightofsample]" % (i)) freshweightofsample = request.POST.get("arrit[%s][freshweightofsample]" % (i)) samplebushsampling = Samplebushsampling(hight=hight, canopy1=canopy1, canopy2=canopy2, dryweightofsample=dryweightofsample, freshweightofsample=freshweightofsample, samplebush_id=samplebush.id) samplebushsampling.save() i += 1 j = 0 while request.POST.get("upload[%s][u]" % (j)) is not None: u = request.POST.get("upload[%s][u]" % (j)) im = request.FILES.get("inputtypefiles[%s][im]" % (j)) sampletreesplantimages = Samplebushplantimages(type=u, file=im, samplebush_id=samplebush.id) sampletreesplantimages.save() j += 1 samplebush_for_add_list = [] samplebushsampling_for_add_list = [] samplebush_for_add = Samplebush.objects.filter(id=samplebush.id) samplebushsampling_for_add = Samplebushsampling.objects.filter(samplebush_id=samplebush.id) for s_g in samplebushsampling_for_add: i = dict() i['id'] = str(s_g.id) i['canopy1'] = s_g.canopy1 i['canopy2'] = s_g.canopy2 i['hight'] = s_g.hight i['dryweightofsample'] = s_g.dryweightofsample i['freshweightofsample'] = s_g.freshweightofsample samplebushsampling_for_add_list.append(i) for s_t in samplebush_for_add: o = dict() o['id'] = str(s_t.id) o['smallkindarea'] = s_t.smallkindarea o['smallkindside'] = s_t.smallkindside o['chinesename'] = Specieslibrary.objects.get(id=s_t.name_id).scientificchinesename o['latinname'] = Specieslibrary.objects.get(id=s_t.name_id).latinname o['totalfreshweight'] = s_t.totalfreshweight o['totaldryweight'] = s_t.totaldryweight o['abundance'] = s_t.abundance o['enforcement'] = s_t.enforcement o['typical'] = s_t.typical o['economic'] = s_t.economic o['frequency'] = s_t.frequency o['number'] = s_t.number o['samplebushrichness'] = Samplebushalways.objects.get(samplebush__id=s_t.id).samplebushrichness o['samplebushdensity'] = Samplebushalways.objects.get(samplebush__id=s_t.id).samplebushdensity samplebush_for_add_list.append(o) return HttpResponse(json.dumps({ "status": "1", "message": "添加成功", "samplebush_for_add_list": samplebush_for_add_list, "samplebushsampling_for_add_list": samplebushsampling_for_add_list, "name_choices": name_choices_results, })) return HttpResponse(json.dumps({ "status": "1", "name_choices": name_choices_results, })) def samplebush_delete(request, pk): if pk: samplebush = Samplebush.objects.get(id=pk) samplebush.delete() return HttpResponse('{"status":"1","message":"删除成功"}') else: return HttpResponse('{"status":"0","message":"请传入正确的id"}') @csrf_exempt def samplebush_update(request, pk): name_choices = Samplebush.NAME_CHOICES name_choices_results = [] file_list = [] for n in name_choices: o = dict() o['name_choices'] = list(n)[0] name_choices_results.append(o) samplebush = Samplebush.objects.get(id=pk) samplebushalways = Samplebushalways.objects.get(id=samplebush.samplebushalways_id) if request.method == 'POST': username = request.POST.get('username') smallkindside = request.POST.get('smallkindside') chinesename = request.POST.get('chinesename') latinname = request.POST.get('latinname') if len(chinesename) == 0 or len(latinname) == 0: return HttpResponse(json.dumps({ "status": "0", "message": "物种名不能为空" })) name = Specieslibrary.objects.filter(scientificchinesename=chinesename, latinname=latinname).count() if name == 0: specieslibrary = Specieslibrary(scientificchinesename=chinesename, latinname=latinname, status='0') specieslibrary.save() id = specieslibrary.id else: name = Specieslibrary.objects.get(scientificchinesename=chinesename, latinname=latinname) id = name.id coverdegree = request.POST.get('coverdegree') frequency = request.POST.get('frequency') totalfreshweight = request.POST.get('totalfreshweight') totaldryweight = request.POST.get('totaldryweight') abundance = request.POST.get('abundance') number = request.POST.get('number') radio1 = request.POST.get('radio1') radio2 = request.POST.get('radio2') radio3 = request.POST.get('radio3') enforcement = None typical = None economic = None if radio1 == '1': enforcement = '是' elif radio1 == '2': enforcement = '否' if radio2 == '1': economic = '是' elif radio2 == '2': economic = '否' if radio3 == '1': typical = '是' elif radio3 == '2': typical = '否' samplebushrichness = request.POST.get('samplebushrichness') samplebushdensity = request.POST.get('samplebushdensity') Samplebushalways.objects.filter(id=samplebush.samplebushalways_id).update( samplebushrichness=samplebushrichness, samplebushdensity=samplebushdensity) Samplebush.objects.filter(id=pk).update(smallkindside=smallkindside, smallkindarea='10m*10m', name_id=id, coverdegree=coverdegree, totalfreshweight=totalfreshweight, totaldryweight=totaldryweight, abundance=abundance, enforcement=enforcement, publisher=username, samplebushalways_id=samplebushalways.id, typical=typical, economic=economic, frequency=frequency, number=number) i = 0 while request.POST.get("arrit[%s][hight]" % (i)) is not None or request.POST.get( "arrit[%s][canopy1]" % (i)) is not None or request.POST.get( "arrit[%s][canopy2]" % (i)) is not None or request.POST.get( "arrit[%s][dryweightofsample]" % (i)) is not None or request.POST.get( "arrit[%s][freshweightofsample]" % (i)) is not None or request.POST.get( "arrit[%s][id]" % (i)) is not None: id = request.POST.get("arrit[%s][id]" % (i)) hight = request.POST.get("arrit[%s][hight]" % (i)) canopy1 = request.POST.get("arrit[%s][canopy1]" % (i)) canopy2 = request.POST.get("arrit[%s][canopy2]" % (i)) dryweightofsample = request.POST.get("arrit[%s][dryweightofsample]" % (i)) freshweightofsample = request.POST.get("arrit[%s][freshweightofsample]" % (i)) if id is not None: Samplebushsampling.objects.filter(id=id).update(hight=hight, canopy1=canopy1, canopy2=canopy2, dryweightofsample=dryweightofsample, freshweightofsample=freshweightofsample, ) else: samplebushsampling = Samplebushsampling(hight=hight, canopy1=canopy1, canopy2=canopy2, dryweightofsample=dryweightofsample, freshweightofsample=freshweightofsample, samplebush_id=samplebush.id) samplebushsampling.save() i += 1 j = 0 while request.POST.get("upload[%s][u]" % (j)) is not None: u = request.POST.get("upload[%s][u]" % (j)) im = request.FILES.get("inputtypefiles[%s][im]" % (j)) sampletreesplantimages = Samplebushplantimages(type=u, file=im, samplebush_id=samplebush.id) sampletreesplantimages.save() j += 1 return HttpResponse(json.dumps({ "status": "1", "message": "修改成功", "name_choices": name_choices_results, })) samplebushplantimages = Samplebushplantimages.objects.filter(samplebush__id=pk) samplebushsampling = Samplebushsampling.objects.filter(samplebush_id=pk) samplebushsampling_list = [] for s_g in samplebushsampling: o = dict() o['id'] = str(s_g.id) o['canopy1'] = s_g.canopy1 o['canopy2'] = s_g.canopy2 o['radio4'] = '1' o['hight'] = s_g.hight o['dryweightofsample'] = s_g.dryweightofsample o['freshweightofsample'] = s_g.freshweightofsample samplebushsampling_list.append(o) for s in samplebushplantimages: file = dict() file['file'] = s.file.url file['type'] = s.type file['id'] = str(s.id) file_list.append(file) e = None if samplebush.enforcement == '是': e = '1' elif samplebush.enforcement == '否': e = '2' t = None if samplebush.typical == '是': t = '1' elif samplebush.typical == '否': t = '2' c = None if samplebush.economic == '是': c = '1' elif samplebush.economic == '否': c = '2' return HttpResponse(json.dumps({ "id": str(samplebush.id), "samplebushrichness": samplebushalways.samplebushrichness, "samplebushdensity": samplebushalways.samplebushdensity, "smallkindside": samplebush.smallkindside, "smallkindarea": samplebush.smallkindarea, "chinesename": Specieslibrary.objects.get(id=samplebush.name_id).scientificchinesename, "latinname": Specieslibrary.objects.get(id=samplebush.name_id).latinname, "coverdegree": samplebush.coverdegree, "totalfreshweight": samplebush.totalfreshweight, "totaldryweight": samplebush.totaldryweight, "abundance": samplebush.abundance, "number": samplebush.number, "enforcement": e, "typical": t, "economic": c, "frequency": samplebush.frequency, "name_choices": name_choices_results, "file_list": file_list, "samplebushsampling_list": samplebushsampling_list, })) def samplebush_search(request): findingscode = request.GET.get('findingscode') samplebush = Samplebush.objects.filter(findings__findingscode=findingscode).order_by('-created') results = [] paginator = Paginator(samplebush, 10) page = int(request.GET.get('page', 1)) try: samplebush_p = paginator.page(page) except PageNotAnInteger: samplebush_p = paginator.page(1) except EmptyPage: samplebush_p = paginator.page(paginator.num_pages) for s in samplebush_p: o = dict() o['id'] = str(s.id) o['findings'] = findingscode o['smallkindside'] = s.smallkindside o['smallkindarea'] = s.smallkindarea o['chinesename'] = Specieslibrary.objects.get(id=s.name_id).scientificchinesename o['latinname'] = Specieslibrary.objects.get(id=s.name_id).latinname o['coverdegree'] = s.coverdegree o['totalfreshweight'] = s.totalfreshweight o['totaldryweight'] = s.totaldryweight o['abundance'] = s.abundance o['enforcement'] = s.enforcement o['economic'] = s.economic o['typical'] = s.typical o['frequency'] = s.frequency results.append(o) return HttpResponse(json.dumps({ "status": "1", "samplebush": results, "count": len(samplebush), "page_count": math.ceil(len(samplebush) / 10), })) # 草本样本 @csrf_exempt def sampleherbal_add(request): image_chiose = Samplebushplantimages.NAME_CHOICES image_choices_results = [] for i in image_chiose: o = dict() o['image_choices'] = list(i)[0] image_choices_results.append(o) if request.method == 'POST': enforcement = None typical = None economic = None findingscode = request.POST.get('findingscode') findings = Findings.objects.get(findingscode=findingscode) username = request.POST.get('username') smallkindside = request.POST.get('smallkindside') if len(smallkindside) == 0: return HttpResponse(json.dumps({ "status": "0", "message": "小样方号不能为空" })) chinesename = request.POST.get('chinesename') latinname = request.POST.get('latinname') name = Specieslibrary.objects.filter(scientificchinesename=chinesename, latinname=latinname).count() if len(chinesename) == 0 or len(latinname) == 0: return HttpResponse(json.dumps({ "status": "0", "message": "物种名不能为空" })) if name == 0: specieslibrary = Specieslibrary(scientificchinesename=chinesename, latinname=latinname, status='0') specieslibrary.save() id = specieslibrary.id else: name = Specieslibrary.objects.get(scientificchinesename=chinesename, latinname=latinname) id = name.id results = Sampleherbal.objects.filter(name_id=id, smallkindside=smallkindside, findings__findingscode=findingscode) if len(results) != 0: return HttpResponse(json.dumps({ "status": "0", "message": "该物种已经存在" })) ontotalfreshweight = request.POST.get('ontotalfreshweight') ontotaldryweight = request.POST.get('ontotaldryweight') abundance = request.POST.get('abundance') pointscoverage = request.POST.get('pointscoverage') speciesontotalfreshweight = request.POST.get('speciesontotalfreshweight') speciesontotaldryweight = request.POST.get('speciesontotaldryweight') sampleherbalrichness = request.POST.get('sampleherbalrichness') sampleherbaldensity = request.POST.get('sampleherbaldensity') sampleherbalcoverdegree = request.POST.get('sampleherbalcoverdegree') radio1 = request.POST.get('radio1') radio2 = request.POST.get('radio2') radio3 = request.POST.get('radio3') if radio1 == '1': enforcement = '是' elif radio1 == '2': enforcement = '否' if radio2 == '1': economic = '是' elif radio2 == '2': economic = '否' if radio3 == '1': typical = '是' elif radio3 == '2': typical = '否' sampleherbalalways = Sampleherbalalways(sampleherbalrichness=sampleherbalrichness, sampleherbaldensity=sampleherbaldensity, sampleherbalcoverdegree=sampleherbalcoverdegree) sampleherbalalways.save() sampleherbal = Sampleherbal(findings_id=findings.id, smallkindside=smallkindside, smallkindarea='1m*1m', speciesontotalfreshweight=speciesontotalfreshweight, name_id=id, ontotaldryweight=ontotaldryweight, abundance=abundance, ontotalfreshweight=ontotalfreshweight, speciesontotaldryweight=speciesontotaldryweight, pointscoverage=pointscoverage, enforcement=enforcement, publisher=username, sampleherbalalways_id=sampleherbalalways.id, economic=economic, ) sampleherbal.save() i = 0 while request.POST.get("arrit[%s][hight]" % (i)) is not None: hight = request.POST.get("arrit[%s][hight]" % (i)) sampleherbalsampling = Sampleherbalsampling(hight=hight, sampleherbal_id=sampleherbal.id) sampleherbalsampling.save() i += 1 j = 0 while request.POST.get("upload[%s][u]" % (j)) is not None: u = request.POST.get("upload[%s][u]" % (j)) im = request.FILES.get("inputtypefiles[%s][im]" % (j)) sampletreesplantimages = Sampleherbalplantimages(type=u, file=im, sampleherbal_id=sampleherbal.id) sampletreesplantimages.save() j += 1 sampleherbal_for_add_list = [] sampleherbalsampling_for_add_list = [] sampleherbal_for_add = Sampleherbal.objects.filter(id=sampleherbal.id) sampleherbalsampling_for_add = Sampleherbalsampling.objects.filter(sampleherbal_id=sampleherbal.id) for s_g in sampleherbalsampling_for_add: i = dict() i['id'] = str(s_g.id) i['hight'] = s_g.hight sampleherbalsampling_for_add_list.append(i) for s_t in sampleherbal_for_add: o = dict() o['id'] = str(s_t.id) o['smallkindside'] = s_t.smallkindside o['smallkindarea'] = s_t.smallkindarea o['chinesename'] = Specieslibrary.objects.get(id=s_t.name_id).scientificchinesename o['latinname'] = Specieslibrary.objects.get(id=s_t.name_id).latinname o['abundance'] = s_t.abundance o['pointscoverage'] = s_t.pointscoverage o['enforcement'] = s_t.enforcement o['economic'] = s_t.economic o['ontotalfreshweight'] = s_t.ontotalfreshweight o['ontotaldryweight'] = s_t.ontotaldryweight o['speciesontotalfreshweight'] = s_t.speciesontotalfreshweight o['speciesontotaldryweight'] = s_t.speciesontotaldryweight o['sampleherbalrichness'] = Sampleherbalalways.objects.get(sampleherbal__id=s_t.id).sampleherbalrichness o['sampleherbaldensity'] = Sampleherbalalways.objects.get(sampleherbal__id=s_t.id).sampleherbaldensity o['sampleherbalcoverdegree'] = Sampleherbalalways.objects.get( sampleherbal__id=s_t.id).sampleherbalcoverdegree sampleherbal_for_add_list.append(o) return HttpResponse(json.dumps({ "status": "1", "message": "添加成功", "sampleherbal_for_add_list": sampleherbal_for_add_list, "sampleherbalsampling_for_add_list": sampleherbalsampling_for_add_list, "image_choices": image_choices_results, })) return HttpResponse(json.dumps({ "status": "1", "image_choices": image_choices_results, })) def sampleherbal_delete(request, pk): if pk: sampleherbal = Sampleherbal.objects.get(id=pk) sampleherbal.delete() return HttpResponse('{"status":"1","message":"删除成功"}') else: return HttpResponse('{"status":"0","message":"请传入正确的id"}') @csrf_exempt def sampleherbal_update(request, pk): name_choices = Sampleherbal.NAME_CHOICES name_choices_results = [] for n in name_choices: o = dict() o['name_choices'] = list(n)[0] name_choices_results.append(o) sampleherbal = Sampleherbal.objects.get(id=pk) sampleherbalalways = Sampleherbalalways.objects.get(id=sampleherbal.sampleherbalalways_id) if request.method == 'POST': enforcement = None typical = None economic = None username = request.POST.get('username') smallkindside = request.POST.get('smallkindside') chinesename = request.POST.get('chinesename') latinname = request.POST.get('latinname') if len(chinesename) == 0 or len(latinname) == 0: return HttpResponse(json.dumps({ "status": "0", "message": "物种名不能为空" })) name = Specieslibrary.objects.filter(scientificchinesename=chinesename, latinname=latinname).count() if name == 0: specieslibrary = Specieslibrary(scientificchinesename=chinesename, latinname=latinname, status='0') specieslibrary.save() id = specieslibrary.id else: name = Specieslibrary.objects.get(scientificchinesename=chinesename, latinname=latinname) id = name.id ontotalfreshweight = request.POST.get('ontotalfreshweight') ontotaldryweight = request.POST.get('ontotaldryweight') abundance = request.POST.get('abundance') pointscoverage = request.POST.get('pointscoverage') speciesontotalfreshweight = request.POST.get('speciesontotalfreshweight') speciesontotaldryweight = request.POST.get('speciesontotaldryweight') sampleherbalrichness = request.POST.get('sampleherbalrichness') sampleherbaldensity = request.POST.get('sampleherbaldensity') sampleherbalcoverdegree = request.POST.get('sampleherbalcoverdegree') radio1 = request.POST.get('radio1') radio2 = request.POST.get('radio2') radio3 = request.POST.get('radio3') if radio1 == '1': enforcement = '是' elif radio1 == '2': enforcement = '否' if radio2 == '1': economic = '是' elif radio2 == '2': economic = '否' if radio3 == '1': typical = '是' elif radio3 == '2': typical = '否' Sampleherbalalways.objects.filter(id=sampleherbal.sampleherbalalways_id).update( sampleherbalrichness=sampleherbalrichness, sampleherbaldensity=sampleherbaldensity, sampleherbalcoverdegree=sampleherbalcoverdegree) Sampleherbal.objects.filter(id=pk).update(smallkindside=smallkindside, smallkindarea='1m*1m', speciesontotalfreshweight=speciesontotalfreshweight, name_id=id, ontotaldryweight=ontotaldryweight, abundance=abundance, ontotalfreshweight=ontotalfreshweight, speciesontotaldryweight=speciesontotaldryweight, pointscoverage=pointscoverage, enforcement=enforcement, publisher=username, sampleherbalalways_id=sampleherbalalways.id, economic=economic, ) i = 0 while request.POST.get("arrit[%s][hight]" % (i)) is not None: id = request.POST.get("arrit[%s][id]" % (i)) hight = request.POST.get("arrit[%s][hight]" % (i)) if id is not None: Sampleherbalsampling.objects.filter(id=id).update(hight=hight) else: sampleherbalsampling = Sampleherbalsampling(hight=hight, sampleherbal_id=sampleherbal.id) sampleherbalsampling.save() i += 1 j = 0 while request.POST.get("upload[%s][u]" % (j)) is not None: u = request.POST.get("upload[%s][u]" % (j)) im = request.FILES.get("inputtypefiles[%s][im]" % (j)) sampletreesplantimages = Sampleherbalplantimages(type=u, file=im, sampleherbal_id=sampleherbal.id) sampletreesplantimages.save() j += 1 return HttpResponse(json.dumps({ "status": "1", "message": "修改成功", "name_choices": name_choices_results, })) file_list = [] sampleherbalsampling_list = [] sampleherbalplantimages = Sampleherbalplantimages.objects.filter(sampleherbal__id=pk) sampleherbalsampling = Sampleherbalsampling.objects.filter(sampleherbal_id=pk) for s_g in sampleherbalsampling: o = dict() o['id'] = str(s_g.id) o['hight'] = s_g.hight sampleherbalsampling_list.append(o) for s in sampleherbalplantimages: file = dict() file['file'] = s.file.url file['type'] = s.type file['id'] = str(s.id) file_list.append(file) e = None if sampleherbal.enforcement == '是': e = '1' elif sampleherbal.enforcement == '否': e = '2' c = None if sampleherbal.economic == '是': c = '1' elif sampleherbal.economic == '否': c = '2' return HttpResponse(json.dumps({ "id": str(sampleherbal.id), "findings": str(sampleherbal.findings_id), "sampleherbalrichness": sampleherbalalways.sampleherbalrichness, "sampleherbaldensity": sampleherbalalways.sampleherbaldensity, "sampleherbalcoverdegree": sampleherbalalways.sampleherbalcoverdegree, "smallkindside": sampleherbal.smallkindside, "smallkindarea": sampleherbal.smallkindarea, "chinesename": Specieslibrary.objects.get(id=sampleherbal.name_id).scientificchinesename, "latinname": Specieslibrary.objects.get(id=sampleherbal.name_id).latinname, "abundance": sampleherbal.abundance, "pointscoverage": sampleherbal.pointscoverage, "ontotalfreshweight": sampleherbal.ontotalfreshweight, "ontotaldryweight": sampleherbal.ontotaldryweight, "speciesontotalfreshweight": sampleherbal.speciesontotalfreshweight, "speciesontotaldryweight": sampleherbal.speciesontotaldryweight, "enforcement": e, "economic": c, "file_list": file_list, "sampleherbalsampling_list": sampleherbalsampling_list, "name_choices": name_choices_results, })) def sampleherbal_search(request): findingscode = request.GET.get('findingscode') sampleherbal = Sampleherbal.objects.filter(findings__findingscode=findingscode).order_by('-created') results = [] paginator = Paginator(sampleherbal, 10) page = int(request.GET.get('page', 1)) try: sampleherbal_p = paginator.page(page) except PageNotAnInteger: sampleherbal_p = paginator.page(1) except EmptyPage: sampleherbal_p = paginator.page(paginator.num_pages) for s in sampleherbal_p: o = dict() o['id'] = str(s.id) o['findings'] = findingscode o['smallkindside'] = s.smallkindside o['smallkindarea'] = s.smallkindarea o['chinesename'] = Specieslibrary.objects.get(id=s.name_id).scientificchinesename o['latinname'] = Specieslibrary.objects.get(id=s.name_id).latinname o['abundance'] = s.abundance o['pointscoverage'] = s.pointscoverage o['ontotalfreshweight'] = s.ontotalfreshweight o['ontotaldryweight'] = s.ontotaldryweight o['speciesontotalfreshweight'] = s.speciesontotalfreshweight o['speciesontotaldryweight'] = s.speciesontotaldryweight o['enforcement'] = s.enforcement o['economic'] = s.economic results.append(o) return HttpResponse(json.dumps({ "status": "1", "sampleherbal": results, "count": len(sampleherbal), "page_count": math.ceil(len(sampleherbal) / 10), })) # 上传土壤图片 @csrf_exempt def simplesoil_add_image(request): file = request.FILES.get("image") size = request.FILES.get("image").size s = round(float(size / 1024), 2) if file is not None: simplesoilimage = Simplesoilimage(file=file, size=s) simplesoilimage.save() return HttpResponse(json.dumps({ "status": "1", "message": "上传成功", "id": str(simplesoilimage.id) })) return HttpResponse(json.dumps({ "status": "0", "message": "上传文件为空" })) # 土壤样本 @csrf_exempt def simplesoil_add(request): if request.method == 'POST': obj = json.loads(request.body.decode('utf-8')) form = obj['form'] if len(form['image_id']) > 0: image_id = form['image_id'] else: return HttpResponse(json.dumps({ "status": "0", "message": "请上传图片" })) findings = None findingscode = form['findingscode'] if findingscode is not None: findings = Findings.objects.get(findingscode=findingscode) username = form['username'] matrix = form['matrix'] color = form['color'] agrotype = form['agrotype'] thickness = form['thickness'] rootbiomassarea = form['rootbiomassarea'] undertotaldryweight11 = form['undertotaldryweight11'] undertotaldryweight12 = form['undertotaldryweight12'] undertotaldryweight13 = form['undertotaldryweight13'] undertotaldryweight21 = form['undertotaldryweight21'] undertotaldryweight22 = form['undertotaldryweight22'] undertotaldryweight23 = form['undertotaldryweight23'] undertotaldryweight31 = form['undertotaldryweight31'] undertotaldryweight32 = form['undertotaldryweight32'] undertotaldryweight33 = form['undertotaldryweight33'] smallkindside = form['smallkindside'] soildepth1 = form['soildepth1'] ph1 = form['ph1'] organiccontent1 = form['organiccontent1'] nitrogen1 = form['nitrogen1'] phosphor1 = form['phosphor1'] kalium1 = form['kalium1'] gravel1 = form['gravel1'] mediumCoarseSand1 = form['mediumCoarseSand1'] fineSand1 = form['fineSand1'] veryFineSand1 = form['veryFineSand1'] mucilage1 = form['mucilage1'] soildepth2 = form['soildepth2'] ph2 = form['ph2'] organiccontent2 = form['organiccontent2'] nitrogen2 = form['nitrogen2'] phosphor2 = form['phosphor2'] kalium2 = form['kalium2'] gravel2 = form['gravel2'] mediumCoarseSand2 = form['mediumCoarseSand2'] fineSand2 = form['fineSand2'] veryFineSand2 = form['veryFineSand2'] mucilage2 = form['mucilage2'] soildepth3 = form['soildepth3'] ph3 = form['ph3'] organiccontent3 = form['organiccontent3'] nitrogen3 = form['nitrogen3'] phosphor3 = form['phosphor3'] kalium3 = form['kalium3'] gravel3 = form['gravel3'] mediumCoarseSand3 = form['mediumCoarseSand3'] fineSand3 = form['fineSand3'] veryFineSand3 = form['veryFineSand3'] mucilage3 = form['mucilage3'] soildepth4 = form['soildepth4'] ph4 = form['ph4'] organiccontent4 = form['organiccontent4'] nitrogen4 = form['nitrogen4'] phosphor4 = form['phosphor4'] kalium4 = form['kalium4'] gravel4 = form['gravel4'] mediumCoarseSand4 = form['mediumCoarseSand4'] fineSand4 = form['fineSand4'] veryFineSand4 = form['veryFineSand4'] mucilage4 = form['mucilage4'] soildepth5 = form['soildepth5'] ph5 = form['ph5'] organiccontent5 = form['organiccontent5'] nitrogen5 = form['nitrogen5'] phosphor5 = form['phosphor5'] kalium5 = form['kalium5'] gravel5 = form['gravel5'] mediumCoarseSand5 = form['mediumCoarseSand5'] fineSand5 = form['fineSand5'] veryFineSand5 = form['veryFineSand5'] mucilage5 = form['mucilage5'] soildepth6 = form['soildepth6'] ph6 = form['ph6'] organiccontent6 = form['organiccontent6'] nitrogen6 = form['nitrogen6'] phosphor6 = form['phosphor6'] kalium6 = form['kalium6'] gravel6 = form['gravel6'] mediumCoarseSand6 = form['mediumCoarseSand6'] fineSand6 = form['fineSand6'] veryFineSand6 = form['veryFineSand6'] mucilage6 = form['mucilage6'] if soildepth1 is not None or ph1 is not None or organiccontent1 is not None or nitrogen1 is not None or phosphor1 is not None or kalium1 is not None or gravel1 is not None: simplesoil1 = Simplesoil(findings_id=findings.id, publisher=username, matrix=matrix, color=color, agrotype=agrotype, thickness=thickness, soildepth=soildepth1, ph=ph1, organiccontent=organiccontent1, nitrogen=nitrogen1, phosphor=phosphor1, kalium=kalium1, gravel=gravel1, mediumCoarseSand=mediumCoarseSand1, fineSand=fineSand1, veryFineSand=veryFineSand1, mucilage=mucilage1, undertotaldryweight11=undertotaldryweight11, undertotaldryweight12=undertotaldryweight12, undertotaldryweight13=undertotaldryweight13, undertotaldryweight21=undertotaldryweight21, undertotaldryweight22=undertotaldryweight22, undertotaldryweight23=undertotaldryweight23, undertotaldryweight31=undertotaldryweight31, undertotaldryweight32=undertotaldryweight32, undertotaldryweight33=undertotaldryweight33, rootbiomassarea=rootbiomassarea, smallkindside=smallkindside, image_id=image_id) simplesoil1.save() if soildepth2 is not None or ph2 is not None or organiccontent2 is not None or nitrogen2 is not None or phosphor2 is not None or kalium2 is not None or gravel2 is not None: simplesoil2 = Simplesoil(findings_id=findings.id, publisher=username, matrix=matrix, color=color, agrotype=agrotype, thickness=thickness, soildepth=soildepth2, ph=ph2, organiccontent=organiccontent2, nitrogen=nitrogen2, phosphor=phosphor2, kalium=kalium2, gravel=gravel2, mediumCoarseSand=mediumCoarseSand2, fineSand=fineSand2, veryFineSand=veryFineSand2, mucilage=mucilage2, undertotaldryweight11=undertotaldryweight11, undertotaldryweight12=undertotaldryweight12, undertotaldryweight13=undertotaldryweight13, undertotaldryweight21=undertotaldryweight21, undertotaldryweight22=undertotaldryweight22, undertotaldryweight23=undertotaldryweight23, undertotaldryweight31=undertotaldryweight31, undertotaldryweight32=undertotaldryweight32, undertotaldryweight33=undertotaldryweight33, rootbiomassarea=rootbiomassarea, smallkindside=smallkindside, image_id=image_id) simplesoil2.save() if soildepth3 is not None or ph3 is not None or organiccontent3 is not None or nitrogen3 is not None or phosphor3 is not None or kalium3 is not None or gravel3 is not None: simplesoil3 = Simplesoil(findings_id=findings.id, publisher=username, matrix=matrix, color=color, agrotype=agrotype, thickness=thickness, soildepth=soildepth3, ph=ph3, organiccontent=organiccontent3, nitrogen=nitrogen3, phosphor=phosphor3, kalium=kalium3, gravel=gravel3, mediumCoarseSand=mediumCoarseSand3, fineSand=fineSand3, veryFineSand=veryFineSand3, mucilage=mucilage3, undertotaldryweight11=undertotaldryweight11, undertotaldryweight12=undertotaldryweight12, undertotaldryweight13=undertotaldryweight13, undertotaldryweight21=undertotaldryweight21, undertotaldryweight22=undertotaldryweight22, undertotaldryweight23=undertotaldryweight23, undertotaldryweight31=undertotaldryweight31, undertotaldryweight32=undertotaldryweight32, undertotaldryweight33=undertotaldryweight33, rootbiomassarea=rootbiomassarea, smallkindside=smallkindside, image_id=image_id) simplesoil3.save() if soildepth4 is not None or ph4 is not None or organiccontent4 is not None or nitrogen4 is not None or phosphor4 is not None or kalium4 is not None or gravel4 is not None: simplesoil4 = Simplesoil(findings_id=findings.id, publisher=username, matrix=matrix, color=color, agrotype=agrotype, thickness=thickness, soildepth=soildepth4, ph=ph4, organiccontent=organiccontent4, nitrogen=nitrogen4, phosphor=phosphor4, kalium=kalium4, gravel=gravel4, mediumCoarseSand=mediumCoarseSand4, fineSand=fineSand4, veryFineSand=veryFineSand4, mucilage=mucilage4, undertotaldryweight11=undertotaldryweight11, undertotaldryweight12=undertotaldryweight12, undertotaldryweight13=undertotaldryweight13, undertotaldryweight21=undertotaldryweight21, undertotaldryweight22=undertotaldryweight22, undertotaldryweight23=undertotaldryweight23, undertotaldryweight31=undertotaldryweight31, undertotaldryweight32=undertotaldryweight32, undertotaldryweight33=undertotaldryweight33, rootbiomassarea=rootbiomassarea, smallkindside=smallkindside, image_id=image_id) simplesoil4.save() if soildepth5 is not None or ph5 is not None or organiccontent5 is not None or nitrogen5 is not None or phosphor5 is not None or kalium5 is not None or gravel5 is not None: simplesoil5 = Simplesoil(findings_id=findings.id, publisher=username, matrix=matrix, color=color, agrotype=agrotype, thickness=thickness, soildepth=soildepth5, ph=ph5, organiccontent=organiccontent5, nitrogen=nitrogen5, phosphor=phosphor5, kalium=kalium5, gravel=gravel5, mediumCoarseSand=mediumCoarseSand5, fineSand=fineSand5, veryFineSand=veryFineSand5, mucilage=mucilage5, undertotaldryweight11=undertotaldryweight11, undertotaldryweight12=undertotaldryweight12, undertotaldryweight13=undertotaldryweight13, undertotaldryweight21=undertotaldryweight21, undertotaldryweight22=undertotaldryweight22, undertotaldryweight23=undertotaldryweight23, undertotaldryweight31=undertotaldryweight31, undertotaldryweight32=undertotaldryweight32, undertotaldryweight33=undertotaldryweight33, rootbiomassarea=rootbiomassarea, smallkindside=smallkindside, image_id=image_id) simplesoil5.save() if soildepth6 is not None or ph6 is not None or organiccontent6 is not None or nitrogen6 is not None or phosphor6 is not None or kalium6 is not None or gravel6 is not None: simplesoil6 = Simplesoil(findings_id=findings.id, publisher=username, matrix=matrix, color=color, agrotype=agrotype, thickness=thickness, soildepth=soildepth6, ph=ph6, organiccontent=organiccontent6, nitrogen=nitrogen6, phosphor=phosphor6, kalium=kalium6, gravel=gravel6, mediumCoarseSand=mediumCoarseSand6, fineSand=fineSand6, veryFineSand=veryFineSand6, mucilage=mucilage6, undertotaldryweight11=undertotaldryweight11, undertotaldryweight12=undertotaldryweight12, undertotaldryweight13=undertotaldryweight13, undertotaldryweight21=undertotaldryweight21, undertotaldryweight22=undertotaldryweight22, undertotaldryweight23=undertotaldryweight23, undertotaldryweight31=undertotaldryweight31, undertotaldryweight32=undertotaldryweight32, undertotaldryweight33=undertotaldryweight33, rootbiomassarea=rootbiomassarea, smallkindside=smallkindside, image_id=image_id) simplesoil6.save() return HttpResponse(json.dumps({ "status": "1", "message": "添加成功", })) else: return HttpResponse(json.dumps({ "status": "0", "message": "添加失败", })) def simplesoil_delete(request, pk): if pk: simplesoil = Simplesoil.objects.get(id=pk) simplesoil.delete() return HttpResponse('{"status":"1","message":"删除成功"}') else: return HttpResponse('{"status":"0","message":"请传入正确的id"}') @csrf_exempt def simplesoil_update(request, pk): if pk: simplesoil = Simplesoil.objects.get(id=pk) if request.method == 'POST': obj = json.loads(request.body.decode('utf-8')) form = obj['form'] image_id = form['image_id'] if image_id is not None: print(str(len(image_id)) + ",1111111111111111111111111111") else: print(str(image_id) + "777777777777777777777777777777777777777777777777777") username = request.POST.get('username') matrix = form['matrix'] color = form['color'] agrotype = form['agrotype'] thickness = form['thickness'] rootbiomassarea = form['rootbiomassarea'] undertotaldryweight11 = form['undertotaldryweight11'] undertotaldryweight12 = form['undertotaldryweight12'] undertotaldryweight13 = form['undertotaldryweight13'] undertotaldryweight21 = form['undertotaldryweight21'] undertotaldryweight22 = form['undertotaldryweight22'] undertotaldryweight23 = form['undertotaldryweight23'] undertotaldryweight31 = form['undertotaldryweight31'] undertotaldryweight32 = form['undertotaldryweight32'] undertotaldryweight33 = form['undertotaldryweight33'] smallkindside = form['smallkindside'] soildepth = form['soildepth'] ph = form['ph'] organiccontent = form['organiccontent'] nitrogen = form['nitrogen'] phosphor = form['phosphor'] kalium = form['kalium'] gravel = form['gravel'] mediumCoarseSand = form['mediumCoarseSand'] fineSand = form['fineSand'] veryFineSand = form['veryFineSand'] mucilage = form['mucilage'] if len(image_id) == 0: Simplesoil.objects.filter(id=pk).update(publisher=username, matrix=matrix, color=color, agrotype=agrotype, thickness=thickness, soildepth=soildepth, ph=ph, organiccontent=organiccontent, nitrogen=nitrogen, phosphor=phosphor, kalium=kalium, gravel=gravel, mediumCoarseSand=mediumCoarseSand, fineSand=fineSand, veryFineSand=veryFineSand, mucilage=mucilage, undertotaldryweight11=undertotaldryweight11, undertotaldryweight12=undertotaldryweight12, undertotaldryweight13=undertotaldryweight13, undertotaldryweight21=undertotaldryweight21, undertotaldryweight22=undertotaldryweight22, undertotaldryweight23=undertotaldryweight23, undertotaldryweight31=undertotaldryweight31, undertotaldryweight32=undertotaldryweight32, undertotaldryweight33=undertotaldryweight33, rootbiomassarea=rootbiomassarea, smallkindside=smallkindside) else: Simplesoil.objects.filter(id=pk).update(publisher=username, matrix=matrix, color=color, agrotype=agrotype, thickness=thickness, soildepth=soildepth, ph=ph, organiccontent=organiccontent, nitrogen=nitrogen, phosphor=phosphor, kalium=kalium, gravel=gravel, mediumCoarseSand=mediumCoarseSand, fineSand=fineSand, veryFineSand=veryFineSand, mucilage=mucilage, undertotaldryweight11=undertotaldryweight11, undertotaldryweight12=undertotaldryweight12, undertotaldryweight13=undertotaldryweight13, undertotaldryweight21=undertotaldryweight21, undertotaldryweight22=undertotaldryweight22, undertotaldryweight23=undertotaldryweight23, undertotaldryweight31=undertotaldryweight31, undertotaldryweight32=undertotaldryweight32, undertotaldryweight33=undertotaldryweight33, rootbiomassarea=rootbiomassarea, smallkindside=smallkindside) s = Simplesoil.objects.get(id=pk) s.image_id = image_id s.save() return HttpResponse(json.dumps({ "status": "1", "message": "修改成功", })) return HttpResponse(json.dumps({ "id": str(simplesoil.id), "soildepth": simplesoil.soildepth, "agrotype": simplesoil.agrotype, "matrix": simplesoil.matrix, "ph": simplesoil.ph, "color": simplesoil.color, "organiccontent": simplesoil.organiccontent, "nitrogen": simplesoil.nitrogen, "phosphor": simplesoil.phosphor, "kalium": simplesoil.kalium, "gravel": simplesoil.gravel, "mediumCoarseSand": simplesoil.mediumCoarseSand, "fineSand": simplesoil.fineSand, "veryFineSand": simplesoil.veryFineSand, "mucilage": simplesoil.mucilage, "rootbiomassarea": simplesoil.rootbiomassarea, # "file": simplesoil.file.url, "file": Simplesoilimage.objects.get(id=simplesoil.image_id).file.url, "undertotaldryweight11": simplesoil.undertotaldryweight11, "undertotaldryweight12": simplesoil.undertotaldryweight12, "undertotaldryweight13": simplesoil.undertotaldryweight13, "undertotaldryweight21": simplesoil.undertotaldryweight21, "undertotaldryweight22": simplesoil.undertotaldryweight22, "undertotaldryweight23": simplesoil.undertotaldryweight23, "undertotaldryweight31": simplesoil.undertotaldryweight31, "undertotaldryweight32": simplesoil.undertotaldryweight32, "undertotaldryweight33": simplesoil.undertotaldryweight33, "smallkindside": simplesoil.smallkindside, "thickness": simplesoil.thickness })) else: return HttpResponse('{"status":"0","message":"请传入正确的id"}') def simplesoil_search(request): findingscode = request.GET.get('findingscode') simplesoil = Simplesoil.objects.filter(findings__findingscode=findingscode).order_by('-created') paginator = Paginator(simplesoil, 10) page = int(request.GET.get('page', 1)) try: simplesoil_p = paginator.page(page) except PageNotAnInteger: simplesoil_p = paginator.page(1) except EmptyPage: simplesoil_p = paginator.page(paginator.num_pages) results = [] for s in simplesoil_p: o = dict() o['id'] = str(s.id) o['findings'] = findingscode o['soildepth'] = s.soildepth o['agrotype'] = s.agrotype o['matrix'] = s.matrix o['ph'] = s.ph o['color'] = s.color o['organiccontent'] = s.organiccontent o['nitrogen'] = s.nitrogen o['phosphor'] = s.phosphor o['kalium'] = s.kalium o['gravel'] = s.gravel o['mediumCoarseSand'] = s.mediumCoarseSand o['fineSand'] = s.fineSand o['veryFineSand'] = s.veryFineSand o['mucilage'] = s.mucilage o['thickness'] = s.thickness results.append(o) return HttpResponse(json.dumps({ "status": "1", "simplesoil": results, "count": len(simplesoil), "page_count": math.ceil(len(simplesoil) / 10), })) # 条形码 @csrf_exempt def barcodes_upload(request): if request.method == 'POST': j = 0 file = request.FILES.get("files[%s][fi]" % (j)) user = request.POST.get('user') code = request.POST.get('code') date = request.POST.get('date') lon = request.POST.get('lon') lat = request.POST.get('lat') locationdescription = request.POST.get('locationdescription') elevation = request.POST.get('elevation') provincs = request.POST.get('provincs') citis = request.POST.get('citis') districts = request.POST.get('districts') countries = request.POST.get('countries') villages = request.POST.get('villages') if len(provincs) == 0: return HttpResponse(json.dumps({ "status": "0", "message": "请选择省" })) if len(citis) == 0: return HttpResponse(json.dumps({ "status": "0", "message": "请选择市" })) province = Area_code_2020.objects.get(code=provincs).name cities = Area_code_2020.objects.get(code=citis).name if len(districts) == 0: district = '' else: district = Area_code_2020.objects.get(code=districts).name if len(countries) == 0: town = '' else: town = Area_code_2020.objects.get(code=countries).name if len(villages) == 0: village = '' else: village = Area_code_2020.objects.get(code=villages).name findingscode = request.POST.get('findingscode') storagecode = request.POST.get('storagecode') chinesename = request.POST.get('chinesename') latinname = request.POST.get('latinname') if chinesename is None or latinname is None: return HttpResponse(json.dumps({ "status": "0", "message": "物种名不能为空" })) name = Specieslibrary.objects.filter(scientificchinesename=chinesename, latinname=latinname).count() if name == 0: specieslibrary = Specieslibrary(scientificchinesename=chinesename, latinname=latinname, status='0') specieslibrary.save() id = specieslibrary.id else: name = Specieslibrary.objects.get(scientificchinesename=chinesename, latinname=latinname) id = name.id family = request.POST.get('family') category = request.POST.get('category') rbcl = request.POST.get('rbcl') matk = request.POST.get('matk') psba = request.POST.get('psba') trnl = request.POST.get('trnl') value = request.POST.get('value') itsdata = request.POST.get('itsdata') username = request.POST.get('username') publisher = User.objects.get(username=username).username if value == '0' or value == 'ITS': barcodes = Barcodes(user=user, name_id=id, code=code, lon=lon, lat=lat, locationdescription=locationdescription, date=date, publisher=publisher, elevation=elevation, province=province, cities=cities, district=district, town=town, village=village, findingscode=findingscode, storagecode=storagecode, family=family, category=category, file=file, rbcl=rbcl, matk=matk, psba=psba, trnl=trnl, its=itsdata) barcodes.save() elif value == '1' or value == 'ITS2': barcodes = Barcodes(user=user, name_id=id, code=code, lon=lon, lat=lat, locationdescription=locationdescription, date=date, publisher=publisher, elevation=elevation, province=province, cities=cities, district=district, town=town, village=village, findingscode=findingscode, storagecode=storagecode, family=family, category=category, file=file, rbcl=rbcl, matk=matk, psba=psba, trnl=trnl, its2=itsdata) barcodes.save() return HttpResponse(json.dumps({ "status": "1", "message": "添加成功" })) def barcodes_delete(request, pk): if pk: barcodes = Barcodes.objects.get(id=pk) barcodes.delete() return HttpResponse('{"status":"1","message":"删除成功"}') else: return HttpResponse('{"status":"0","message":"请传入正确的id"}') @csrf_exempt def barcodes_update(request, pk): barcodes = Barcodes.objects.get(id=pk) if request.method == 'POST': j = 0 file = request.FILES.get("files[%s][fi]" % (j)) user = request.POST.get('user') code = request.POST.get('code') date = request.POST.get('date') lon = request.POST.get('lon') lat = request.POST.get('lat') locationdescription = request.POST.get('locationdescription') elevation = request.POST.get('elevation') provincs = request.POST.get('provincs') citis = request.POST.get('citis') districts = request.POST.get('districts') countries = request.POST.get('countries') villages = request.POST.get('villages') if provincs != '' and provincs.isdigit(): province = Area_code_2020.objects.get(code=provincs).name else: province = provincs if citis != '' and citis.isdigit(): cities = Area_code_2020.objects.get(code=citis).name else: cities = citis if districts != '' and districts.isdigit(): district = Area_code_2020.objects.get(code=districts).name else: district = districts if countries != '' and countries.isdigit(): town = Area_code_2020.objects.get(code=countries).name else: town = countries if villages != '' and villages.isdigit(): village = Area_code_2020.objects.get(code=villages).name else: village = villages findingscode = request.POST.get('findingscode') storagecode = request.POST.get('storagecode') chinesename = request.POST.get('chinesename') latinname = request.POST.get('latinname') if chinesename is None or latinname is None: return HttpResponse(json.dumps({ "status": "0", "message": "物种名不能为空" })) name = Specieslibrary.objects.filter(scientificchinesename=chinesename, latinname=latinname).count() if name == 0: specieslibrary = Specieslibrary(scientificchinesename=chinesename, latinname=latinname, status='0') specieslibrary.save() id = specieslibrary.id else: name = Specieslibrary.objects.get(scientificchinesename=chinesename, latinname=latinname) id = name.id family = request.POST.get('family') category = request.POST.get('category') rbcl = request.POST.get('rbcl') matk = request.POST.get('matk') psba = request.POST.get('psba') trnl = request.POST.get('trnl') value = request.POST.get('value') itsdata = request.POST.get('itsdata') username = request.POST.get('username') publisher = User.objects.get(username=username).username if value == '0' or value == 'ITS': if file is not None: Barcodes.objects.filter(id=pk).update(user=user, name_id=id, code=code, lon=lon, lat=lat, locationdescription=locationdescription, date=date, publisher=publisher, elevation=elevation, province=province, cities=cities, district=district, town=town, village=village, findingscode=findingscode, storagecode=storagecode, family=family, category=category, rbcl=rbcl, matk=matk, psba=psba, trnl=trnl, its=itsdata) b = Barcodes.objects.get(id=pk) b.file = file b.save() else: Barcodes.objects.filter(id=pk).update(user=user, name_id=id, code=code, lon=lon, lat=lat, locationdescription=locationdescription, date=date, publisher=publisher, elevation=elevation, province=province, cities=cities, district=district, town=town, village=village, findingscode=findingscode, storagecode=storagecode, family=family, category=category, rbcl=rbcl, matk=matk, psba=psba, trnl=trnl, its=itsdata) elif value == '1' or value == 'ITS2': if file is not None: Barcodes.objects.filter(id=pk).update(user=user, name_id=id, code=code, lon=lon, lat=lat, locationdescription=locationdescription, date=date, publisher=publisher, elevation=elevation, province=province, cities=cities, district=district, town=town, village=village, findingscode=findingscode, storagecode=storagecode, family=family, category=category, rbcl=rbcl, matk=matk, psba=psba, trnl=trnl, its2=itsdata) b = Barcodes.objects.get(id=pk) b.file = file b.save() else: Barcodes.objects.filter(id=pk).update(user=user, name_id=id, code=code, lon=lon, lat=lat, locationdescription=locationdescription, date=date, publisher=publisher, elevation=elevation, province=province, cities=cities, district=district, town=town, village=village, findingscode=findingscode, storagecode=storagecode, family=family, category=category, rbcl=rbcl, matk=matk, psba=psba, trnl=trnl, its2=itsdata) return HttpResponse(json.dumps({ "status": "1", "message": "添加成功" })) itsdata = None value = None if barcodes.its == '': itsdata = barcodes.its2 value = 'ITS2' else: itsdata = barcodes.its value = 'ITS' file = None if barcodes.file: file = barcodes.file.url else: file = '' return HttpResponse(json.dumps({ "id": str(barcodes.id), "chinesename": Specieslibrary.objects.get(id=barcodes.name_id).scientificchinesename, "latinname": Specieslibrary.objects.get(id=barcodes.name_id).latinname, "user": barcodes.user, "code": barcodes.code, "lon": barcodes.lon, "lat": barcodes.lat, "locationdescription": barcodes.locationdescription, "date": barcodes.date, "elevation": barcodes.elevation, "province": barcodes.province, "cities": barcodes.cities, "district": barcodes.district, "town": barcodes.town, "village": barcodes.village, "findingscode": barcodes.findingscode, "storagecode": barcodes.storagecode, "family": barcodes.family, "category": barcodes.category, "file": file, "rbcl": barcodes.rbcl, "matk": barcodes.matk, "psba": barcodes.psba, "trnl": barcodes.trnl, "itsdata": itsdata, "value": value, })) def barcodes_search(request): barcodes = Barcodes.objects.all().order_by('-created') results = [] paginator = Paginator(barcodes, 10) page = int(request.GET.get('page', 1)) try: barcodes_p = paginator.page(page) except PageNotAnInteger: barcodes_p = paginator.page(1) except EmptyPage: barcodes_p = paginator.page(paginator.num_pages) for b in barcodes_p: o = dict() o['id'] = str(b.id) o['chinesename'] = Specieslibrary.objects.get(id=b.name_id).scientificchinesename o['latinname'] = Specieslibrary.objects.get(id=b.name_id).latinname o['user'] = b.user o['code'] = b.code o['date'] = b.date o['elevation'] = b.elevation o['findingscode'] = b.findingscode o['storagecode'] = b.storagecode o['family'] = b.family o['category'] = b.category results.append(o) return HttpResponse(json.dumps({ "status": "1", "barcodes": results, "count": len(barcodes), "page_count": math.ceil(len(barcodes) / 10), })) # 土地利用 @csrf_exempt def landuse_add(request): if request.method == 'POST': obj = json.loads(request.body.decode('utf-8')) findingscode = obj['findingscode'] findings = Findings.objects.get(findingscode=findingscode) typelanduse = obj['typelanduse'] # arealanduse = obj['arealanduse'] # typelandcover = obj['typelandcover'] # arealandcover = obj['arealandcover'] # ph = obj['ph'] if findingscode is not None: landuse = Landuse(findings_id=findings.id, typelanduse=typelanduse, ) landuse.save() return HttpResponse(json.dumps({ "status": "1", "message": "添加成功", })) else: return HttpResponse(json.dumps({ "status": "", "message": "请输入完整信息", })) else: typelanduse = Landusetype.objects.all() res = [] for t in typelanduse: o = dict() o['id'] = str(t.id) o['type'] = t.type res.append(o) return HttpResponse(json.dumps({ "status": "1", "res": res })) def landuse_delete(request, pk): if request.user.is_authenticated: if pk: landuse = Landuse.objects.get(id=pk) landuse.delete() return HttpResponse('{"status":"1","message":"删除成功"}') else: return HttpResponse('{"status":"0","message":"请传入正确的id"}') else: return HttpResponse('{"status":"0","message":"请您登录后操作"}') @csrf_exempt def landuse_update(request, pk): if pk: landuse = Landuse.objects.get(id=pk) if request.method == 'POST': obj = json.loads(request.body.decode('utf-8')) form = obj['form'] username = obj['username'] Landuse.objects.filter(id=pk).update(typelanduse=form['typelanduse'], publisher=username) return HttpResponse(json.dumps({ "status": "1", "message": "修改成功", })) typelanduse = Landusetype.objects.all() res = [] for t in typelanduse: o = dict() o['id'] = str(t.id) o['type'] = t.type res.append(o) return HttpResponse(json.dumps({ "id": str(landuse.id), "typelanduse": landuse.typelanduse, "res": res, # "typelandcover": landuse.typelandcover, # "arealandcover": landuse.arealandcover, # "ph": landuse.ph, })) else: return HttpResponse('{"status":"0","message":"请传入正确的id"}') def landuse_search(request): findingscode = request.GET.get('findingscode') landuse = Landuse.objects.filter(findings__findingscode=findingscode).order_by('-created') paginator = Paginator(landuse, 10) page = int(request.GET.get('page', 1)) try: landuse_p = paginator.page(page) except PageNotAnInteger: landuse_p = paginator.page(1) except EmptyPage: landuse_p = paginator.page(paginator.num_pages) results = [] for l in landuse_p: o = dict() o['id'] = str(l.id) o['findings'] = findingscode o['typelanduse'] = l.typelanduse # o['arealanduse'] = l.arealanduse # o['typelandcover'] = l.typelandcover # o['arealandcover'] = l.arealandcover # o['ph'] = l.ph results.append(o) return HttpResponse(json.dumps({ "status": "1", "landuse": results, "count": len(landuse), "page_count": math.ceil(len(landuse) / 10), })) # 气象 @csrf_exempt def weather_add(request): if request.method == 'POST': obj = json.loads(request.body.decode('utf-8')) findingscode = obj['findingscode'] findings = Findings.objects.get(findingscode=findingscode) month = obj['month'] year = obj['year'] max = obj['max'] min = obj['min'] averagetemperature = obj['averagetemperature'] annualtemperature = obj['annualtemperature'] temperaturemin = obj['temperaturemin'] temperaturemax = obj['temperaturemax'] username = obj['username'] user = User.objects.get(username=username).username if findingscode is not None: weather = Weather(findings_id=findings.id, month=month, year=year, max=max, min=min, averagetemperature=averagetemperature, annualtemperature=annualtemperature, temperaturemin=temperaturemin, temperaturemax=temperaturemax, publisher=user) weather.save() return HttpResponse(json.dumps({ "status": "1", "message": "添加成功", })) def weather_delete(request, pk): if pk: weather = Weather.objects.get(id=pk) weather.delete() return HttpResponse('{"status":"1","message":"删除成功"}') else: return HttpResponse('{"status":"0","message":"请传入正确的id"}') @csrf_exempt def weather_update(request, pk): if pk: weather = Weather.objects.get(id=pk) if request.method == 'POST': obj = json.loads(request.body.decode('utf-8')) form = obj['form'] username = obj['username'] user = User.objects.get(username=username).username Weather.objects.filter(id=pk).update(month=form['month'], year=form['year'], max=form['max'], min=form['min'], averagetemperature=form['averagetemperature'], annualtemperature=form['annualtemperature'], temperaturemin=form['temperaturemin'], temperaturemax=form['temperaturemax'], publisher=user) return HttpResponse(json.dumps({ "status": "1", "message": "修改成功", })) return HttpResponse(json.dumps({ "month": weather.month, "year": weather.year, "max": weather.max, "min": weather.min, "averagetemperature": weather.averagetemperature, "annualtemperature": weather.annualtemperature, "temperaturemin": weather.temperaturemin, "temperaturemax": weather.temperaturemax })) else: return HttpResponse('{"status":"0","message":"请传入正确的id"}') def weather_search(request): findingscode = request.GET.get('findingscode') weather = Weather.objects.filter(findings__findingscode=findingscode).order_by('-created') results = [] paginator = Paginator(weather, 10) page = int(request.GET.get('page', 1)) try: weather_p = paginator.page(page) except PageNotAnInteger: weather_p = paginator.page(1) except EmptyPage: weather_p = paginator.page(paginator.num_pages) for w in weather_p: o = dict() o['id'] = str(w.id) o['findings'] = findingscode o['month'] = w.month o['year'] = w.year o['max'] = w.max o['min'] = w.min o['averagetemperature'] = w.averagetemperature o['annualtemperature'] = w.annualtemperature o['temperaturemin'] = w.temperaturemin o['temperaturemax'] = w.temperaturemax results.append(o) return HttpResponse(json.dumps({ "status": "1", "weather": results, "count": len(weather), "page_count": math.ceil(len(weather) / 10), })) # 群落 @csrf_exempt def community_add(request): if request.user.is_authenticated: if request.method == 'POST': obj = json.loads(request.body.decode('utf-8')) findings = obj['findings'] coenotype = obj['coenotype'] communityname = obj['communityname'] speciesnamechinese = obj['speciesnamechinese'] speciesnamelatin = obj['speciesnamelatin'] height = obj['height'] coverdegree = obj['coverdegree'] crownlength = obj['crownlength'] crownwidth = obj['crownwidth'] number = obj['number'] establishmentname = obj['establishmentname'] mainspeciesnamechinese = obj['mainspeciesnamechinese'] mainspeciesnamelatin = obj['mainspeciesnamelatin'] secondaryestablishmentcommunity = obj['secondaryestablishmentcommunity'] secondaryspecieschinese = obj['secondaryspecieschinese'] secondaryspecieslatin = obj['secondaryspecieslatin'] trees = obj['trees'] shrub = obj['shrub'] herbal = obj['herbal'] litters = obj['litters'] site = obj['site'] locationdescription = obj['locationdescription'] locationreferencepoint = obj['locationreferencepoint'] lon = obj['lon'] lat = obj['lat'] terrain = obj['terrain'] elevation = obj['elevation'] exposure = obj['exposure'] gradient = obj['gradient'] slopeposition = obj['slopeposition'] river = obj['river'] riverlength = obj['riverlength'] riverwidth = obj['riverwidth'] riverdeep = obj['riverdeep'] rivershape = obj['rivershape'] jamming = obj['jamming'] if findings is not None: community = Community(findings_id=findings, coenotype=coenotype, communityname=communityname, speciesnamechinese=speciesnamechinese, speciesnamelatin=speciesnamelatin, height=height, coverdegree=coverdegree, crownlength=crownlength, crownwidth=crownwidth, number=number, establishmentname=establishmentname, mainspeciesnamechinese=mainspeciesnamechinese, mainspeciesnamelatin=mainspeciesnamelatin, secondaryestablishmentcommunity=secondaryestablishmentcommunity, secondaryspecieschinese=secondaryspecieschinese, secondaryspecieslatin=secondaryspecieslatin, trees=trees, shrub=shrub, herbal=herbal, litters=litters, site=site, locationdescription=locationdescription, locationreferencepoint=locationreferencepoint, lon=lon, lat=lat, terrain=terrain, elevation=elevation, exposure=exposure, gradient=gradient, slopeposition=slopeposition, river=river, riverlength=riverlength, riverwidth=riverwidth, riverdeep=riverdeep, rivershape=rivershape, jamming=jamming) community.save() return HttpResponse(json.dumps({ "status": "1", "message": "添加成功", })) else: return HttpResponse(json.dumps({ "status": "", "message": "请输入完整信息", })) findings = Findings.objects.all() results = [] for f in findings: o = dict() o['findingscode'] = f.findingscode o['date'] = f.date o['id'] = str(f.id) o['investigators_id'] = str(f.investigators_id) results.append(o) return HttpResponse(json.dumps({ "findings": results, })) else: return HttpResponse('{"status":"0","message":"请您登录后操作"}') def community_delete(request, pk): if request.user.is_authenticated: if pk: community = Community.objects.get(id=pk) community.delete() return HttpResponse('{"status":"1","message":"删除成功"}') else: return HttpResponse('{"status":"0","message":"请传入正确的id"}') else: return HttpResponse('{"status":"0","message":"请您登录后操作"}') @csrf_exempt def community_update(request, pk): if request.user.is_authenticated: if pk: community = Community.objects.get(id=pk) if request.method == 'POST': obj = json.loads(request.body.decode('utf-8')) findings = obj['findings'] coenotype = obj['coenotype'] communityname = obj['communityname'] speciesnamechinese = obj['speciesnamechinese'] speciesnamelatin = obj['speciesnamelatin'] height = obj['height'] coverdegree = obj['coverdegree'] crownlength = obj['crownlength'] crownwidth = obj['crownwidth'] number = obj['number'] establishmentname = obj['establishmentname'] mainspeciesnamechinese = obj['mainspeciesnamechinese'] mainspeciesnamelatin = obj['mainspeciesnamelatin'] secondaryestablishmentcommunity = obj['secondaryestablishmentcommunity'] secondaryspecieschinese = obj['secondaryspecieschinese'] secondaryspecieslatin = obj['secondaryspecieslatin'] trees = obj['trees'] shrub = obj['shrub'] herbal = obj['herbal'] litters = obj['litters'] site = obj['site'] locationdescription = obj['locationdescription'] locationreferencepoint = obj['locationreferencepoint'] lon = obj['lon'] lat = obj['lat'] terrain = obj['terrain'] elevation = obj['elevation'] exposure = obj['exposure'] gradient = obj['gradient'] slopeposition = obj['slopeposition'] river = obj['river'] riverlength = obj['riverlength'] riverwidth = obj['riverwidth'] riverdeep = obj['riverdeep'] rivershape = obj['rivershape'] jamming = obj['jamming'] Community.objects.filter(id=pk).update(findings_id=findings, coenotype=coenotype, communityname=communityname, speciesnamechinese=speciesnamechinese, speciesnamelatin=speciesnamelatin, height=height, coverdegree=coverdegree, crownlength=crownlength, crownwidth=crownwidth, number=number, establishmentname=establishmentname, mainspeciesnamechinese=mainspeciesnamechinese, mainspeciesnamelatin=mainspeciesnamelatin, secondaryestablishmentcommunity=secondaryestablishmentcommunity, secondaryspecieschinese=secondaryspecieschinese, secondaryspecieslatin=secondaryspecieslatin, trees=trees, shrub=shrub, herbal=herbal, litters=litters, site=site, locationdescription=locationdescription, locationreferencepoint=locationreferencepoint, lon=lon, lat=lat, terrain=terrain, elevation=elevation, exposure=exposure, gradient=gradient, slopeposition=slopeposition, river=river, riverlength=riverlength, riverwidth=riverwidth, riverdeep=riverdeep, rivershape=rivershape, jamming=jamming) return HttpResponse(json.dumps({ "status": "1", "message": "修改成功", })) findings = Findings.objects.all() results = [] for f in findings: o = dict() o['findingscode'] = f.findingscode o['date'] = f.date o['id'] = str(f.id) o['investigators_id'] = str(f.investigators_id) results.append(o) return HttpResponse(json.dumps({ "findings": results, "id": str(community.id), "findings_id": str(community.findings_id), "coenotype": community.coenotype, "communityname": community.communityname, "speciesnamechinese": community.speciesnamechinese, "speciesnamelatin": community.speciesnamelatin, "height": community.height, "coverdegree": community.coverdegree, "crownlength": community.crownlength, "crownwidth": community.crownwidth, "number": community.number, "establishmentname": community.establishmentname, "mainspeciesnamechinese": community.mainspeciesnamechinese, "mainspeciesnamelatin": community.mainspeciesnamelatin, "secondaryestablishmentcommunity": community.secondaryestablishmentcommunity, "secondaryspecieschinese": community.secondaryspecieschinese, "secondaryspecieslatin": community.secondaryspecieslatin, "trees": community.trees, "shrub": community.shrub, "herbal": community.herbal, "litters": community.litters, "site": community.site, "locationdescription": community.locationdescription, "locationreferencepoint": community.locationreferencepoint, "lon": community.lon, "lat": community.lat, "terrain": community.terrain, "elevation": community.elevation, "exposure": community.exposure, "gradient": community.gradient, "slopeposition": community.slopeposition, "river": community.river, "riverlength": community.riverlength, "riverwidth": community.riverwidth, "riverdeep": community.riverdeep, "rivershape": community.rivershape, "jamming": community.jamming })) else: return HttpResponse('{"status":"0","message":"请传入正确的id"}') else: return HttpResponse('{"status":"0","message":"请您登录后操作"}') def community_search(request): community = Community.objects.all().order_by('-created') results = [] for c in community: o = dict() o['id'] = str(c.id) o['findings_id'] = str(c.findings_id) o['coenotype'] = c.coenotype o['communityname'] = c.communityname o['speciesnamechinese'] = c.speciesnamechinese o['speciesnamelatin'] = c.speciesnamelatin o['height'] = c.height o['coverdegree'] = c.coverdegree o['crownlength'] = c.crownlength o['crownwidth'] = c.crownwidth o['number'] = c.number o['establishmentname'] = c.establishmentname o['mainspeciesnamechinese'] = c.mainspeciesnamechinese o['mainspeciesnamelatin'] = c.mainspeciesnamelatin o['secondaryestablishmentcommunity'] = c.secondaryestablishmentcommunity o['secondaryspecieschinese'] = c.secondaryspecieschinese o['secondaryspecieslatin'] = c.secondaryspecieslatin o['trees'] = c.trees o['shrub'] = c.shrub o['herbal'] = c.herbal o['litters'] = c.litters o['site'] = c.site o['locationdescription'] = c.locationdescription o['locationreferencepoint'] = c.locationreferencepoint o['lon'] = c.lon o['lat'] = c.lat o['terrain'] = c.terrain o['elevation'] = c.elevation o['exposure'] = c.exposure o['gradient'] = c.gradient o['slopeposition'] = c.slopeposition o['river'] = c.river o['riverlength'] = c.riverlength o['riverwidth'] = c.riverwidth o['riverdeep'] = c.riverdeep o['rivershape'] = c.rivershape o['jamming'] = c.jamming results.append(o) return HttpResponse(json.dumps({ "status": "1", "community": community })) # 调查点数量 def index_echarts_findings(request): task = Task.objects.exclude(taskname__contains="中国荒漠主要植物群落调查及数据库构建 ").order_by('-created') print(task) results1 = [] for t in task: o = dict() findings = Findings.objects.filter(task_id=t.id).count() key = t.taskname value = findings o['value'] = value o['name'] = key results1.append(o) return HttpResponse(json.dumps({ "status": "0", "findingstask": results1, })) # 样本数量 def index_echarts_sample(request): task = Task.objects.all().order_by('-created') results = [] for t in task: o = dict() sampletrees = Sampletrees.objects.filter(findings__task_id=t.id).count() samplebush = Samplebush.objects.filter(findings__task_id=t.id).count() sampleherbal = Sampleherbal.objects.filter(findings__task_id=t.id).count() simplesoil = Simplesoil.objects.filter(findings__task_id=t.id).count() barcodes = Barcodes.objects.all().count() landuse = Landuse.objects.filter(findings__task_id=t.id).count() weather = Weather.objects.filter(findings__task_id=t.id).count() key = t.taskname value = int(int(sampletrees) + int(samplebush) + int(sampleherbal) + int(simplesoil) + int(barcodes) + int( landuse) + int(weather)) o['value'] = value o['name'] = key results.append(o) return HttpResponse(json.dumps({ "status": "0", "sample": results, })) # 样本类型 def index_echarts_sampletype(request): task = Task.objects.all().order_by('-created') product_list = [] findings_list = [] sampletrees_list = [] samplebush_list = [] sampleherbal_list = [] simplesoil_list = [] barcodes_list = [] landuse_list = [] weather_list = [] for t in task: product_list.append(t.taskname) findings = Findings.objects.filter(task_id=t.id).count() findings_list.append(findings) sampletrees1 = Sampletrees.objects.filter(findings__task_id=t.id).count() sampletrees_list.append(sampletrees1) samplebush = Samplebush.objects.filter(findings__task_id=t.id).count() samplebush_list.append(samplebush) sampleherbal = Sampleherbal.objects.filter(findings__task_id=t.id).count() sampleherbal_list.append(sampleherbal) simplesoil = Simplesoil.objects.filter(findings__task_id=t.id).count() simplesoil_list.append(simplesoil) barcodes = Barcodes.objects.all().count() barcodes_list.append(barcodes) landuse = Landuse.objects.filter(findings__task_id=t.id).count() landuse_list.append(landuse) weather = Weather.objects.filter(findings__task_id=t.id).count() weather_list.append(weather) return HttpResponse(json.dumps({ 'status': "1", 'product_list': product_list, 'findings_list': findings_list, 'sampletrees_list': sampletrees_list, 'samplebush_list': samplebush_list, 'sampleherbal_list': sampleherbal_list, 'simplesoil_list': simplesoil_list, 'barcodes_list': barcodes_list, 'landuse_list': landuse_list, 'weather_list': weather_list })) # 获得省份 def get_province(request): provinces = Area_code_2020.objects.filter(pcode='0') results = [] for p in provinces: o = dict() o['id'] = str(p.id) o['code'] = p.code o['level'] = p.level o['name'] = p.name o['pcode'] = p.pcode results.append(o) return HttpResponse(json.dumps({ "status": "1", "provinces": results })) # 获得市 def get_city(request): province_code = request.GET.get('province_code') citis = Area_code_2020.objects.filter(pcode=province_code) results = [] for c in citis: o = dict() o['id'] = str(c.id) o['code'] = c.code o['level'] = c.level o['name'] = c.name o['pcode'] = c.pcode results.append(o) return HttpResponse(json.dumps({ "status": "1", "citis": results })) # 获得县 def get_district(request): city_code = request.GET.get('city_code') districts = Area_code_2020.objects.filter(pcode=city_code) results = [] for d in districts: o = dict() o['id'] = str(d.id) o['code'] = d.code o['level'] = d.level o['name'] = d.name o['pcode'] = d.pcode results.append(o) return HttpResponse(json.dumps({ "status": "1", "districts": results })) # 获得乡 def get_country(request): district_code = request.GET.get('district_code') country = Area_code_2020.objects.filter(pcode=district_code) results = [] for c in country: o = dict() o['id'] = str(c.id) o['code'] = c.code o['level'] = c.level o['name'] = c.name o['pcode'] = c.pcode results.append(o) return HttpResponse(json.dumps({ "status": "1", "country": results })) # 获得村 def get_village(request): country_code = request.GET.get('country_code') villages = Area_code_2020.objects.filter(pcode=country_code) results = [] for v in villages: o = dict() o['id'] = str(v.id) o['code'] = v.code o['level'] = v.level o['name'] = v.name o['pcode'] = v.pcode results.append(o) return HttpResponse(json.dumps({ "status": "1", "villages": results })) # 获取专题组 def get_special(request): task = request.GET.get('task') results = [] if len(task) != 0: special = Special.objects.filter(task_id=task).order_by('-created') for s in special: o = dict() o['id'] = str(s.id) o['specialname'] = s.specialname o['specialcode'] = s.specialcode o['remark'] = s.remark results.append(o) return HttpResponse(json.dumps({ "status": "1", "special": results })) def latinname_search_for_specieslibrary(request): latinname = request.GET.get('latinname') species_data_list = [] if len(latinname) != 0: # species = Specieslibrary.objects.filter(Q(latinname__contains=latinname))[:20] species = Specieslibrary.objects.filter(latinname__istartswith=latinname)[:20] for s in species: o = dict() o['id'] = str(s.id) o['family'] = s.family o['familylatinname'] = s.familylatinname o['scientificchinesename'] = s.scientificchinesename o['latinname'] = s.latinname species_data_list.append(o) return HttpResponse(json.dumps({ "status": "1", "species_data_list": species_data_list })) return HttpResponse(json.dumps({ "status": "0", "message": "传入的拉丁名为空" })) def chinesename_search_for_specieslibrary(request): chinesename = request.GET.get('chinesename') species_data_list = [] if len(chinesename) != 0: species = Specieslibrary.objects.filter(Q(scientificchinesename__contains=chinesename))[:20] for s in species: o = dict() o['id'] = str(s.id) o['family'] = s.family o['familylatinname'] = s.familylatinname o['scientificchinesename'] = s.scientificchinesename o['latinname'] = s.latinname species_data_list.append(o) return HttpResponse(json.dumps({ "status": "1", "species_data_list": species_data_list })) return HttpResponse(json.dumps({ "status": "0", "message": "传入的中文名为空" })) # 乔木数据展示 def sampletrees_data_list(request): sampletrees = Sampletrees.objects.all().order_by('-created') paginator = Paginator(sampletrees, 10) page = int(request.GET.get('page', 1)) try: sampletrees_p = paginator.page(page) except PageNotAnInteger: sampletrees_p = paginator.page(1) except EmptyPage: sampletrees_p = paginator.page(paginator.num_pages) sampletrees_data_list = [] sampletreessampling_list = [] for s in sampletrees_p: sampletreessampling = Sampletreessampling.objects.filter(sampletrees_id=s.id) for s_g in sampletreessampling: i = dict() i['id'] = str(s_g.id) i['hight'] = s_g.hight i['dbh'] = s_g.dbh i['canopy1'] = s_g.canopy1 i['canopy2'] = s_g.canopy2 sampletreessampling_list.append(i) o = dict() o['id'] = str(s.id) o['findings'] = s.findings.findingscode o['smallkindarea'] = s.smallkindarea o['chinesename'] = Specieslibrary.objects.get(id=s.name_id).scientificchinesename o['latinname'] = Specieslibrary.objects.get(id=s.name_id).latinname o['phenophase'] = s.phenophase o['biotype'] = s.biotype o['totalfreshweight'] = s.totalfreshweight o['freshweightofsample'] = s.freshweightofsample o['totaldryweight'] = s.totaldryweight o['dryweightofsample'] = s.dryweightofsample o['abundance'] = s.abundance o['enforcement'] = s.enforcement o['sampletreerichness'] = s.sampletreesalways.sampletreerichness o['sampletreedensity'] = s.sampletreesalways.sampletreedensity sampletrees_data_list.append(o) return HttpResponse(json.dumps({ "status": "1", "sampletrees_data_list": sampletrees_data_list, "sampletreessampling_list": sampletreessampling_list, "count": len(sampletrees), "page_count": math.ceil(len(sampletrees) / 10), })) def task_distribution_sampletrees(request): task = Task.objects.all().order_by('-created') sampletrees_list = [] for t in task: o = dict() o['value'] = Sampletrees.objects.filter(findings__task_id=t.id).count() o['name'] = t.taskname sampletrees_list.append(o) return HttpResponse(json.dumps({ "status": "1", "sampletrees_list": sampletrees_list, })) # 灌木数据展示 def samplebush_data_list(request): samplebush = Samplebush.objects.all().order_by('-created') paginator = Paginator(samplebush, 10) page = int(request.GET.get('page', 1)) try: samplebush_p = paginator.page(page) except PageNotAnInteger: samplebush_p = paginator.page(1) except EmptyPage: samplebush_p = paginator.page(paginator.num_pages) samplebush_data_list = [] for s in samplebush_p: o = dict() o['id'] = str(s.id) o['findings'] = s.findings.findingscode o['smallkindside'] = s.smallkindside o['smallkindarea'] = s.smallkindarea o['chinesename'] = Specieslibrary.objects.get(id=s.name_id).scientificchinesename o['latinname'] = Specieslibrary.objects.get(id=s.name_id).latinname o['coverdegree'] = s.coverdegree o['totalfreshweight'] = s.totalfreshweight o['totaldryweight'] = s.totaldryweight o['abundance'] = s.abundance o['frequency'] = s.frequency if s.enforcement == 0: o['enforcement'] = '否' if s.enforcement == 1: o['enforcement'] = '是' o['samplebushrichness'] = s.samplebushalways.samplebushrichness o['samplebushdensity'] = s.samplebushalways.samplebushdensity samplebush_data_list.append(o) return HttpResponse(json.dumps({ "status": "1", "samplebush_data_list": samplebush_data_list, "count": len(samplebush), "page_count": math.ceil(len(samplebush) / 10), })) def task_distribution_samplebush(request): task = Task.objects.all().order_by('-created') samplebush_list = [] for t in task: o = dict() o['value'] = Samplebush.objects.filter(findings__task_id=t.id).count() o['name'] = t.taskname samplebush_list.append(o) return HttpResponse(json.dumps({ "status": "1", "samplebush_list": samplebush_list, })) # 草本数据展示 def sampleherbal_data_list(request): sampleherbal = Sampleherbal.objects.all().order_by('-created') paginator = Paginator(sampleherbal, 8) page = int(request.GET.get('page', 1)) try: sampleherbal_p = paginator.page(page) except PageNotAnInteger: sampleherbal_p = paginator.page(1) except EmptyPage: sampleherbal_p = paginator.page(paginator.num_pages) sampleherbal_data_list = [] for s in sampleherbal_p: o = dict() o['id'] = str(s.id) o['findings'] = s.findings.findingscode o['smallkindside'] = s.smallkindside o['smallkindarea'] = s.smallkindarea o['chinesename'] = Specieslibrary.objects.get(id=s.name_id).scientificchinesename o['latinname'] = Specieslibrary.objects.get(id=s.name_id).latinname o['ontotalfreshweight'] = s.ontotalfreshweight o['ontotaldryweight'] = s.ontotaldryweight o['abundance'] = s.abundance o['pointscoverage'] = s.pointscoverage o['speciesontotalfreshweight'] = s.speciesontotalfreshweight o['speciesontotaldryweight'] = s.speciesontotaldryweight o['enforcement'] = s.enforcement o['economic'] = s.economic o['sampleherbalrichness'] = s.sampleherbalalways.sampleherbalrichness o['sampleherbaldensity'] = s.sampleherbalalways.sampleherbaldensity o['sampleherbalcoverdegree'] = s.sampleherbalalways.sampleherbalcoverdegree sampleherbal_data_list.append(o) return HttpResponse(json.dumps({ "status": "1", "sampleherbal_data_list": sampleherbal_data_list, "count": len(sampleherbal), "page_count": math.ceil(len(sampleherbal) / 8), })) def task_distribution_sampleherbal(request): task = Task.objects.all().order_by('-created') sampleherbal_list = [] for t in task: o = dict() o['value'] = Sampleherbal.objects.filter(findings__task_id=t.id).count() o['name'] = t.taskname sampleherbal_list.append(o) return HttpResponse(json.dumps({ "status": "1", "sampleherbal_list": sampleherbal_list, })) # 调查点展示 def findings_data_list(request): findings = Findings.objects.all().order_by('-created') paginator = Paginator(findings, 8) page = int(request.GET.get('page', 1)) try: findings_p = paginator.page(page) except PageNotAnInteger: findings_p = paginator.page(1) except EmptyPage: findings_p = paginator.page(paginator.num_pages) findings_data_list = [] for f in findings_p: o = dict() o['id'] = str(f.id) o['findingscode'] = f.findingscode o['investigators'] = f.investigators.name o['date'] = f.date.split('T')[0] o['site'] = f.site o['terrain'] = f.terrain o['elevation'] = f.elevation o['gradient'] = f.gradient o['lon'] = f.lon o['lat'] = f.lat o['vegetationtypegroups'] = f.vegetationtypegroups o['vegetation'] = f.vegetation o['vegetationsubtypes'] = f.vegetationsubtypes o['formationgroup'] = f.formationgroup o['formation'] = f.formation o['lon1'] = round(float(f.lon), 2) o['lat1'] = round(float(f.lat), 2) findings_data_list.append(o) return HttpResponse(json.dumps({ "status": "1", "findings_data_list": findings_data_list, "count": len(findings), "page_count": math.ceil(len(findings) / 8), })) # 调查点分布 def findings_distribution_geo(request): findings = Findings.objects.all().order_by('-created') results = [] for f in findings: o = dict() o['lat'] = f.lat o['lon'] = f.lon o['findingscode'] = f.findingscode o['investigators'] = f.investigators.name if f.date: o['date'] = f.date.split('T')[0] o['terrain'] = f.terrain o['gradient'] = f.gradient o['elevation'] = f.elevation o['exposure'] = f.exposure o['site'] = f.site results.append(o) return HttpResponse(json.dumps({ "status": "1", "findings_distribution": results })) def findings_reveal(request, pk): findings = Findings.objects.filter(id=pk) results = [] for f in findings: o = dict() o['id'] = str(f.id) o['findingscode'] = f.findingscode o['investigators'] = f.investigators.name o['date'] = str(f.date).split('T')[0] o['site'] = f.site o['locationdescription'] = f.locationdescription o['elevation'] = f.elevation o['gradient'] = f.gradient o['terrain'] = f.terrain o['exposure'] = f.exposure o['river'] = f.river o['riverlength'] = f.riverlength o['riverwidth'] = f.riverwidth o['riverdeep'] = f.riverdeep o['rivershape'] = f.rivershape o['lon1'] = round(float(f.lon), 3) o['lat1'] = round(float(f.lat), 3) o['lon'] = f.lon o['lat'] = f.lat o['jamming'] = f.jamming o['vegetationtypegroups'] = f.vegetationtypegroups o['vegetation'] = f.vegetation o['vegetationsubtypes'] = f.vegetationsubtypes o['formationgroup'] = f.formationgroup o['formation'] = f.formation results.append(o) return HttpResponse(json.dumps({ "status": "0", "findings": results })) # 图——调查类型分布 def survey_type_distribution(request, pk): sampletrees = Sampletrees.objects.filter(findings_id=pk).count() samplebush = Samplebush.objects.filter(findings_id=pk).count() sampleherbal = Sampleherbal.objects.filter(findings_id=pk).count() simplesoil = Simplesoil.objects.filter(findings_id=pk).count() results = [] o1 = dict() o2 = dict() o3 = dict() o4 = dict() o1['name'] = '乔木' o1['value'] = sampletrees o2['name'] = '灌木' o2['value'] = samplebush o3['name'] = '草本' o3['value'] = sampleherbal o4['name'] = '土壤' o4['value'] = simplesoil results.append(o1) results.append(o2) results.append(o3) results.append(o4) return HttpResponse(json.dumps({ "status": "1", "results": results })) # 图-调查点数据量 def findings_data_size(request, pk): sampletrees = Sampletrees.objects.filter(findings_id=pk).count() samplebush = Samplebush.objects.filter(findings_id=pk).count() sampleherbal = Sampleherbal.objects.filter(findings_id=pk).count() simplesoil = Simplesoil.objects.filter(findings_id=pk).count() results = [] results.append(sampletrees) results.append(samplebush) results.append(sampleherbal) results.append(simplesoil) return HttpResponse(json.dumps({ "status": "1", "results": results })) # 乔木删除图片 def sampletrees_delete_image(request, pk): if pk: sampletreesplantimages = Sampletreesplantimages.objects.get(id=pk) sampletreesplantimages.delete() return HttpResponse(json.dumps({ "status": "1", "message": "删除成功" })) # 灌木图片删除 def samplebush_delete_image(request, pk): samplebushplantimages = Samplebushplantimages.objects.get(id=pk) samplebushplantimages.delete() return HttpResponse(json.dumps({ "status": "1", "message": "删除成功" })) # 草本图片删除 def sampleherbal_delete_image(request, pk): sampleherbalplantimages = Sampleherbalplantimages.objects.get(id=pk) sampleherbalplantimages.delete() return HttpResponse(json.dumps({ "status": "1", "message": "删除成功" })) # 数据详情信息 def sampletrees_detail(request, pk): s = Sampletrees.objects.get(id=pk) sampletrees_data_list = [] image_list = [] sampletreessampling_list = [] sampletreessampling = Sampletreessampling.objects.filter(sampletrees_id=s.id) for s_g in sampletreessampling: i = dict() i['id'] = str(s_g.id) i['hight'] = s_g.hight if s_g.dbh != '': i['dbh'] = round(float(s_g.dbh), 1) i['canopy1'] = s_g.canopy1 i['canopy2'] = s_g.canopy2 sampletreessampling_list.append(i) o = dict() o['id'] = str(s.id) o['findings'] = s.findings.findingscode o['exposure'] = s.findings.exposure o['terrain'] = s.findings.terrain o['smallkindarea'] = s.smallkindarea o['chinesename'] = Specieslibrary.objects.get(id=s.name_id).scientificchinesename o['latinname'] = Specieslibrary.objects.get(id=s.name_id).latinname o['phenophase'] = s.phenophase o['biotype'] = s.biotype o['totalfreshweight'] = s.totalfreshweight o['freshweightofsample'] = s.freshweightofsample o['totaldryweight'] = s.totaldryweight o['dryweightofsample'] = s.dryweightofsample o['abundance'] = s.abundance o['enforcement'] = s.enforcement o['economic'] = s.economic o['sampletreerichness'] = s.sampletreesalways.sampletreerichness o['sampletreedensity'] = s.sampletreesalways.sampletreedensity o['lon'] = s.findings.lon o['lat'] = s.findings.lat o['findingscode'] = s.findings.findingscode o['investigators'] = s.findings.investigators.name o['date'] = str(s.findings.date).split('T')[0] o['site'] = s.findings.site o['locationdescription'] = s.findings.locationdescription o['elevation'] = s.findings.elevation o['gradient'] = s.findings.gradient o['river'] = s.findings.river o['riverlength'] = s.findings.riverlength o['riverwidth'] = s.findings.riverwidth o['riverdeep'] = s.findings.riverdeep o['rivershape'] = s.findings.rivershape o['jamming'] = s.findings.jamming o['vegetationtypegroups'] = s.findings.vegetationtypegroups o['vegetation'] = s.findings.vegetation o['vegetationsubtypes'] = s.findings.vegetationsubtypes o['formationgroup'] = s.findings.formationgroup o['formation'] = s.findings.formation o['lon1'] = round(float(s.findings.lon), 2) o['lat1'] = round(float(s.findings.lat), 2) sampletrees_data_list.append(o) image = Sampletreesplantimages.objects.filter(sampletrees_id=s.id) for img in image: s = dict() s['type'] = img.type s['file'] = img.file.url image_list.append(s) return HttpResponse(json.dumps({ "status": "1", "sampletreessampling_list": sampletreessampling_list, "sampletrees_data_list": sampletrees_data_list, "image_list": image_list, })) def samplebush_detail(request, pk): s = Samplebush.objects.get(id=pk) samplebush_data_list = [] image_list = [] samplebushsampling_list = [] samplebushsampling = Samplebushsampling.objects.filter(samplebush_id=pk) for s_g in samplebushsampling: i = dict() i['id'] = str(s_g.id) i['canopy1'] = s_g.canopy1 i['canopy2'] = s_g.canopy2 i['hight'] = s_g.hight i['freshweightofsample'] = s_g.freshweightofsample i['canopy1'] = s_g.canopy1 samplebushsampling_list.append(i) o = dict() o['id'] = str(s.id) o['findings'] = s.findings.findingscode o['terrain'] = s.findings.terrain o['exposure'] = s.findings.exposure o['smallkindside'] = s.smallkindside o['smallkindarea'] = s.smallkindarea o['chinesename'] = Specieslibrary.objects.get(id=s.name_id).scientificchinesename o['latinname'] = Specieslibrary.objects.get(id=s.name_id).latinname o['coverdegree'] = s.coverdegree o['frequency'] = s.frequency o['totalfreshweight'] = s.totalfreshweight o['totaldryweight'] = s.totaldryweight o['abundance'] = s.abundance o['enforcement'] = s.enforcement o['economic'] = s.economic o['typical'] = s.typical o['samplebushrichness'] = s.samplebushalways.samplebushrichness o['samplebushdensity'] = s.samplebushalways.samplebushdensity o['findingscode'] = s.findings.findingscode o['investigators'] = s.findings.investigators.name o['date'] = str(s.findings.date).split('T')[0] o['site'] = s.findings.site o['locationdescription'] = s.findings.locationdescription o['elevation'] = s.findings.elevation o['gradient'] = s.findings.gradient o['river'] = s.findings.river o['riverlength'] = s.findings.riverlength o['riverwidth'] = s.findings.riverwidth o['riverdeep'] = s.findings.riverdeep o['rivershape'] = s.findings.rivershape o['jamming'] = s.findings.jamming o['vegetationtypegroups'] = s.findings.vegetationtypegroups o['vegetation'] = s.findings.vegetation o['vegetationsubtypes'] = s.findings.vegetationsubtypes o['formationgroup'] = s.findings.formationgroup o['formation'] = s.findings.formation o['lon'] = s.findings.lon o['lat'] = s.findings.lat o['lon1'] = round(float(s.findings.lon), 2) o['lat1'] = round(float(s.findings.lat), 2) samplebush_data_list.append(o) image = Samplebushplantimages.objects.filter(samplebush_id=s.id) for img in image: s = dict() s['type'] = img.type s['file'] = img.file.url image_list.append(s) return HttpResponse(json.dumps({ "status": "1", "samplebush_data_list": samplebush_data_list, "image_list": image_list, "samplebushsampling_list": samplebushsampling_list, })) def sampleherbal_detail(request, pk): s = Sampleherbal.objects.get(id=pk) sampleherbal_data_list = [] sampleherbalsampling_list = [] sampleherbalsampling = Sampleherbalsampling.objects.filter(sampleherbal_id=pk) for s_g in sampleherbalsampling: i = dict() i['id'] = str(s_g.id) i['hight'] = s_g.hight sampleherbalsampling_list.append(i) image_list = [] o = dict() o['id'] = str(s.id) o['findings'] = s.findings.findingscode o['terrain'] = s.findings.terrain o['exposure'] = s.findings.exposure o['smallkindside'] = s.smallkindside o['smallkindarea'] = s.smallkindarea o['chinesename'] = Specieslibrary.objects.get(id=s.name_id).scientificchinesename o['latinname'] = Specieslibrary.objects.get(id=s.name_id).latinname # o['totalfreshweight'] = s.totalfreshweight # o['totaldryweight'] = s.totaldryweight o['abundance'] = s.abundance o['pointscoverage'] = s.pointscoverage # o['abovegroundbiomass'] = s.abovegroundbiomass # o['undergroundbiomass'] = s.undergroundbiomass o['enforcement'] = s.enforcement o['economic'] = s.economic o['ontotalfreshweight'] = s.ontotalfreshweight o['ontotaldryweight'] = s.ontotaldryweight o['speciesontotalfreshweight'] = s.speciesontotalfreshweight o['speciesontotaldryweight'] = s.speciesontotaldryweight o['sampleherbalrichness'] = s.sampleherbalalways.sampleherbalrichness o['sampleherbaldensity'] = s.sampleherbalalways.sampleherbaldensity o['sampleherbalcoverdegree'] = s.sampleherbalalways.sampleherbalcoverdegree o['findingscode'] = s.findings.findingscode o['investigators'] = s.findings.investigators.name o['date'] = str(s.findings.date).split('T')[0] o['site'] = s.findings.site o['locationdescription'] = s.findings.locationdescription o['elevation'] = s.findings.elevation o['gradient'] = s.findings.gradient o['river'] = s.findings.river o['riverlength'] = s.findings.riverlength o['riverwidth'] = s.findings.riverwidth o['riverdeep'] = s.findings.riverdeep o['rivershape'] = s.findings.rivershape o['jamming'] = s.findings.jamming o['vegetationtypegroups'] = s.findings.vegetationtypegroups o['vegetation'] = s.findings.vegetation o['vegetationsubtypes'] = s.findings.vegetationsubtypes o['formationgroup'] = s.findings.formationgroup o['formation'] = s.findings.formation o['lon'] = s.findings.lon o['lat'] = s.findings.lat o['lon1'] = round(float(s.findings.lon), 2) o['lat1'] = round(float(s.findings.lat), 2) sampleherbal_data_list.append(o) image = Sampleherbalplantimages.objects.filter(sampleherbal_id=s.id) for img in image: s = dict() s['type'] = img.type s['file'] = img.file.url image_list.append(s) return HttpResponse(json.dumps({ "status": "1", "sampleherbal_data_list": sampleherbal_data_list, "image_list": image_list, "sampleherbalsampling_list": sampleherbalsampling_list, })) @csrf_exempt def drone_photo_upload(request): # findingscode = request.POST.get('findingscode') # print(str(findingscode) + "6666666666666666666666666666666") # findings = Findings.objects.get(findingscode=findingscode) # j = 0 # while request.FILES.get("files[%s][fi]" % (j)) is not None: # files = request.FILES.get("files[%s][fi]" % (j)) # dronephotos = Dronephotos(file=files, findings_id=findings.id) # # dronephotos.save() # j += 1 file = request.FILES.get("file") return HttpResponse(json.dumps({ "status": "1", "message": "上传成功" })) @csrf_exempt def scene_photo_upload(request): findingscode = request.POST.get('findingscode') findings = Findings.objects.get(findingscode=findingscode) j = 0 while request.FILES.get("files[%s][fi]" % (j)) is not None: files = request.FILES.get("files[%s][fi]" % (j)) scenephoto = Scenephoto(file=files, findings_id=findings.id) scenephoto.save() j += 1 return HttpResponse(json.dumps({ "status": "1", "message": "上传成功" })) @csrf_exempt def accessory_upload(request): findingscode = request.POST.get('findingscode') findings = Findings.objects.get(findingscode=findingscode) j = 0 while request.FILES.get("files[%s][fi]" % (j)) is not None: files = request.FILES.get("files[%s][fi]" % (j)) accessory = Accessory(file=files, findings_id=findings.id) accessory.save() j += 1 return HttpResponse(json.dumps({ "status": "1", "message": "上传成功" })) # 删除采样信息 def sampletreessampling_delete(request, pk): sampletreessampling = Sampletreessampling.objects.get(id=pk) sampletreessampling.delete() return HttpResponse('{"status":"1","message":"删除成功"}') def samplebushsampling_delete(request, pk): samplebushsampling = Samplebushsampling.objects.get(id=pk) samplebushsampling.delete() return HttpResponse('{"status":"1","message":"删除成功"}') def sampleherbalsampling_delete(request, pk): sampleherbalsampling = Sampleherbalsampling.objects.get(id=pk) sampleherbalsampling.delete() return HttpResponse('{"status":"1","message":"删除成功"}') def type_search_for_vegetationcommunity(request): type = request.GET.get('type') vegetationcommunity_data_list = [] vegetationcommunity = None if len(type) != 0: vegetationcommunity = Vegetationcommunity.objects.filter(type__contains=type).distinct('type') else: vegetationcommunity = Vegetationcommunity.objects.all().distinct('type') for v in vegetationcommunity: o = dict() o['id'] = str(v.id) o['type'] = v.type o['group'] = v.group vegetationcommunity_data_list.append(o) return HttpResponse(json.dumps({ "status": "1", "type_vegetationcommunity_data_list": vegetationcommunity_data_list })) def group_search_for_vegetationcommunity(request): type = request.GET.get('type') vegetationcommunity_data_list = [] vegetationcommunity = None if len(type) != 0: vegetationcommunity = Vegetationcommunity.objects.filter(type=type) for v in vegetationcommunity: o = dict() o['id'] = str(v.id) o['type'] = v.type o['group'] = v.group vegetationcommunity_data_list.append(o) return HttpResponse(json.dumps({ "status": "1", "group_vegetationcommunity_data_list": vegetationcommunity_data_list })) def dna_data_export(request): username = request.GET.get('username') dna = None dna_results = [] user = User.objects.get(username=username) jurisdiction = UserProfile.objects.get(user_id=user.id).jurisdiction if user.is_superuser is True or jurisdiction == 0: dna = Barcodes.objects.all() elif jurisdiction == 1: task_id = UserProfile.objects.get(user_id=user.id).task_id dna = Barcodes.objects.filter(findings__task_id=task_id) else: special_id = UserProfile.objects.get(user_id=user.id).special_id dna = Barcodes.objects.filter(findings__special_id=special_id) path = '/var/www/p3/DesertVegetationCommunitySurvey/media/downloadfiles/' with open(path + 'DNA-%s.csv' % (username), 'w') as csvfile: writer = csv.writer(csvfile) writer.writerow( ["chinesename", "latinname", "family", "category", "findingscode", "rbcL", "matK", "psbA-trnH", "trnL-F", "ITS", "publisher"]) for d in dna: chinesename = Specieslibrary.objects.get(id=d.name_id).scientificchinesename latinname = Specieslibrary.objects.get(id=d.name_id).latinname family = d.family category = d.category findingscode = d.findingscode rbcL = d.dna_1 matK = d.dna_2 psbA = d.dna_3 trnL = d.dna_4 ITS = d.dna_5 publisher = d.publisher writer.writerow( [chinesename, latinname, family, category, findingscode, rbcL, matK, psbA, trnL, ITS, publisher]) src_dir = path + 'DNA-' + username + '.csv' file = open(src_dir, 'rb') response = StreamingHttpResponse(file) response['Content-Type'] = 'application/octet-stream' response['Content-Disposition'] = 'attachment;filename="DNA-%s.csv"' % (username) return response def sampletrees_data_export(request): username = request.GET.get('username') sampletrees = None user = User.objects.get(username=username) jurisdiction = UserProfile.objects.get(user_id=user.id).jurisdiction if user.is_superuser is True or jurisdiction == 0: sampletrees = Sampletrees.objects.all() elif jurisdiction == 1: task_id = UserProfile.objects.get(user_id=user.id).task_id sampletrees = Sampletrees.objects.filter(findings__task_id=task_id) else: special_id = UserProfile.objects.get(user_id=user.id).special_id sampletrees = Sampletrees.objects.filter(findings__special_id=special_id) path = '/var/www/p3/DesertVegetationCommunitySurvey/media/downloadfiles/' with open(path + 'Sampletrees-%s.csv' % (username), 'w') as csvfile: writer = csv.writer(csvfile) writer.writerow( ["物种名", "拉丁名", "调查点编号", "样方面积", "物候相", "生活型", "多度", "是否珍稀濒危", "是否是经济植物", "乔木丰富度", "乔木密度", "数据发布者"]) for d in sampletrees: chinesename = Specieslibrary.objects.get(id=d.name_id).scientificchinesename latinname = Specieslibrary.objects.get(id=d.name_id).latinname findingscode = d.findings.findingscode smallkindarea = d.smallkindarea phenophase = d.phenophase biotype = d.biotype abundance = d.abundance enforcement = d.enforcement economic = d.economic publisher = d.publisher sampletreerichness = d.sampletreesalways.sampletreerichness sampletreedensity = d.sampletreesalways.sampletreedensity writer.writerow( [chinesename, latinname, findingscode, smallkindarea, phenophase, biotype, abundance, enforcement, economic, sampletreerichness, sampletreedensity, publisher]) src_dir = path + 'Sampletrees-' + username + '.csv' file = open(src_dir, 'rb') response = StreamingHttpResponse(file) response['Content-Type'] = 'application/octet-stream' response['Content-Disposition'] = 'attachment;filename="Sampletrees-%s.csv"' % (username) return response def samplebush_data_export(request): username = request.GET.get('username') samplebush = None user = User.objects.get(username=username) jurisdiction = UserProfile.objects.get(user_id=user.id).jurisdiction if user.is_superuser is True or jurisdiction == 0: samplebush = Samplebush.objects.all() elif jurisdiction == 1: task_id = UserProfile.objects.get(user_id=user.id).task_id samplebush = Samplebush.objects.filter(findings__task_id=task_id) else: special_id = UserProfile.objects.get(user_id=user.id).special_id samplebush = Samplebush.objects.filter(findings__special_id=special_id) path = '/var/www/p3/DesertVegetationCommunitySurvey/media/downloadfiles/' with open(path + 'Samplebush-%s.csv' % (username), 'w') as csvfile: writer = csv.writer(csvfile) writer.writerow( ["物种名", "拉丁名", "调查点编号", "样方面积", "小样方号", "盖度", "频度", "总干重", "总鲜重", "多度", "是否濒危", "是否是经济植物", "是否优势灌木", "灌木丰富度", "灌木密度", "数据发布者"]) for d in samplebush: chinesename = Specieslibrary.objects.get(id=d.name_id).scientificchinesename latinname = Specieslibrary.objects.get(id=d.name_id).latinname findingscode = d.findings.findingscode smallkindarea = d.smallkindarea smallkindside = d.smallkindside coverdegree = d.coverdegree frequency = d.frequency totaldryweight = d.totaldryweight totalfreshweight = d.totalfreshweight abundance = d.abundance enforcement = d.enforcement economic = d.economic typical = d.typical samplebushrichness = d.samplebushalways.samplebushrichness samplebushdensity = d.samplebushalways.samplebushdensity publisher = d.publisher writer.writerow( [chinesename, latinname, findingscode, smallkindarea, smallkindside, coverdegree, frequency, totaldryweight, totalfreshweight, abundance, enforcement, economic, typical, samplebushrichness, samplebushdensity, publisher]) src_dir = path + 'Samplebush-' + username + '.csv' file = open(src_dir, 'rb') response = StreamingHttpResponse(file) response['Content-Type'] = 'application/octet-stream' response['Content-Disposition'] = 'attachment;filename="Samplebush-%s.csv"' % (username) return response def sampleherbal_data_export(request): username = request.GET.get('username') samplebush = None user = User.objects.get(username=username) jurisdiction = UserProfile.objects.get(user_id=user.id).jurisdiction if user.is_superuser is True or jurisdiction == 0: sampleherbal = Sampleherbal.objects.all() elif jurisdiction == 1: task_id = UserProfile.objects.get(user_id=user.id).task_id sampleherbal = Sampleherbal.objects.filter(findings__task_id=task_id) else: special_id = UserProfile.objects.get(user_id=user.id).special_id sampleherbal = Sampleherbal.objects.filter(findings__special_id=special_id) path = '/var/www/p3/DesertVegetationCommunitySurvey/media/downloadfiles/' with open(path + 'Sampleherbal-%s.csv' % (username), 'w') as csvfile: writer = csv.writer(csvfile) writer.writerow( ["物种名", "拉丁名", "调查点编号", "样方面积", "小样方号", "样方地上总生物量总鲜重", "样方地上总生物量总干重", "多度", "分盖度", "物种地上总生物量总鲜重", "物种地上总生物量总干重", "是否濒危", "是否是经济植物", "草本丰富度", "草本密度", "草本总盖度", "数据发布者"]) for d in sampleherbal: chinesename = Specieslibrary.objects.get(id=d.name_id).scientificchinesename latinname = Specieslibrary.objects.get(id=d.name_id).latinname findingscode = d.findings.findingscode smallkindarea = d.smallkindarea smallkindside = d.smallkindside ontotalfreshweight = d.ontotalfreshweight ontotaldryweight = d.ontotaldryweight abundance = d.abundance pointscoverage = d.pointscoverage speciesontotalfreshweight = d.speciesontotalfreshweight speciesontotaldryweight = d.speciesontotaldryweight enforcement = d.enforcement economic = d.economic sampleherbalrichness = d.sampleherbalalways.sampleherbalrichness sampleherbaldensity = d.sampleherbalalways.sampleherbaldensity sampleherbalcoverdegree = d.sampleherbalalways.sampleherbalcoverdegree publisher = d.publisher writer.writerow( [chinesename, latinname, findingscode, smallkindarea, smallkindside, ontotalfreshweight, ontotaldryweight, abundance, pointscoverage, speciesontotalfreshweight, speciesontotaldryweight, enforcement, economic, sampleherbalrichness, sampleherbaldensity, sampleherbalcoverdegree, publisher]) src_dir = path + 'Sampleherbal-' + username + '.csv' file = open(src_dir, 'rb') response = StreamingHttpResponse(file) response['Content-Type'] = 'application/octet-stream' response['Content-Disposition'] = 'attachment;filename="Sampleherbal-%s.csv"' % (username) return response