desertvegetationcommunitysu.../dashboard/views.py

3641 lines
150 KiB
Python

# -*- 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.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
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']
print(str(username) + "66666666666666666666666666666666666666666666666666666")
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()
print(user.id, task)
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, ]
print(str(form))
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, ]
print(str(form))
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)
print("发送成功")
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')
print(email)
results = User.objects.filter(email=email)
print(results)
if len(results) == 0:
return HttpResponse(json.dumps({
"status": "0",
"message": "该邮箱尚未注册,请输入正确的邮箱"
}))
form = [email, ]
print(str(form))
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)
print("发送成功")
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']
print(str(remark))
task = Task(principal=principal, linkman=linkman, taskname=taskname, taskcode=taskcode, remark=remark)
print(str(task))
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)
print(str(task.id))
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()
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']
print(str(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()
results = []
for i in investigators:
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
}))
def findings_search(request):
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({
"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)
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')
print(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)
print(sampletreesplantimages)
for s in sampletreesplantimages:
file = dict()
file['file'] = s.file.url
file['type'] = s.type
file['id'] = str(s.id)
file_list.append(file)
print(file_list)
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)
results = []
for s in sampletrees:
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
}))
# 灌木样本
@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)
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')
print(type(radio3), type(radio2), type(radio1))
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')
print(samplebushrichness, 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)
results = []
for s in samplebush:
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
}))
# 草本样本
@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)
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)
print(sampleherbalplantimages)
for s in sampleherbalplantimages:
file = dict()
file['file'] = s.file.url
file['type'] = s.type
file['id'] = str(s.id)
file_list.append(file)
print(file_list)
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)
results = []
for s in sampleherbal:
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
}))
# 土壤样本
@csrf_exempt
def simplesoil_add(request):
if request.method == 'POST':
findingscode = request.POST.get('findingscode')
findings = Findings.objects.get(findingscode=findingscode)
username = request.POST.get('username')
matrix = request.POST.get('matrix')
color = request.POST.get('color')
agrotype = request.POST.get('agrotype')
thickness = request.POST.get('thickness')
rootbiomassarea = request.POST.get('rootbiomassarea')
undertotaldryweight1 = request.POST.get('undertotaldryweight1')
undertotaldryweight2 = request.POST.get('undertotaldryweight2')
undertotaldryweight3 = request.POST.get('undertotaldryweight3')
smallkindside = request.POST.get('smallkindside')
j = 0
file = request.FILES.get("files[%s][fi]" % (j))
print(str(file) + "777777777777777777777777777777777")
soildepth1 = request.POST.get('soildepth1')
ph1 = request.POST.get('ph1')
organiccontent1 = request.POST.get('organiccontent1')
nitrogen1 = request.POST.get('nitrogen1')
phosphor1 = request.POST.get('phosphor1')
kalium1 = request.POST.get('kalium1')
gravel1 = request.POST.get('gravel1')
mediumCoarseSand1 = request.POST.get('mediumCoarseSand1')
fineSand1 = request.POST.get('fineSand1')
veryFineSand1 = request.POST.get('veryFineSand1')
mucilage1 = request.POST.get('mucilage1')
soildepth2 = request.POST.get('soildepth2')
ph2 = request.POST.get('ph2')
organiccontent2 = request.POST.get('organiccontent2')
nitrogen2 = request.POST.get('nitrogen2')
phosphor2 = request.POST.get('phosphor2')
kalium2 = request.POST.get('kalium2')
gravel2 = request.POST.get('gravel2')
mediumCoarseSand2 = request.POST.get('mediumCoarseSand2')
fineSand2 = request.POST.get('fineSand2')
veryFineSand2 = request.POST.get('veryFineSand2')
mucilage2 = request.POST.get('mucilage2')
soildepth3 = request.POST.get('soildepth3')
ph3 = request.POST.get('ph3')
organiccontent3 = request.POST.get('organiccontent3')
nitrogen3 = request.POST.get('nitrogen3')
phosphor3 = request.POST.get('phosphor3')
kalium3 = request.POST.get('kalium3')
gravel3 = request.POST.get('gravel3')
mediumCoarseSand3 = request.POST.get('mediumCoarseSand3')
fineSand3 = request.POST.get('fineSand3')
veryFineSand3 = request.POST.get('veryFineSand3')
mucilage3 = request.POST.get('mucilage3')
soildepth4 = request.POST.get('soildepth4')
ph4 = request.POST.get('ph4')
organiccontent4 = request.POST.get('organiccontent4')
nitrogen4 = request.POST.get('nitrogen4')
phosphor4 = request.POST.get('phosphor4')
kalium4 = request.POST.get('kalium4')
gravel4 = request.POST.get('gravel4')
mediumCoarseSand4 = request.POST.get('mediumCoarseSand4')
fineSand4 = request.POST.get('fineSand4')
veryFineSand4 = request.POST.get('veryFineSand4')
mucilage4 = request.POST.get('mucilage4')
soildepth5 = request.POST.get('soildepth5')
ph5 = request.POST.get('ph5')
organiccontent5 = request.POST.get('organiccontent5')
nitrogen5 = request.POST.get('nitrogen5')
phosphor5 = request.POST.get('phosphor5')
kalium5 = request.POST.get('kalium5')
gravel5 = request.POST.get('gravel5')
mediumCoarseSand5 = request.POST.get('mediumCoarseSand5')
fineSand5 = request.POST.get('fineSand5')
veryFineSand5 = request.POST.get('veryFineSand5')
mucilage5 = request.POST.get('mucilage5')
soildepth6 = request.POST.get('soildepth6')
ph6 = request.POST.get('ph6')
organiccontent6 = request.POST.get('organiccontent6')
nitrogen6 = request.POST.get('nitrogen6')
phosphor6 = request.POST.get('phosphor6')
kalium6 = request.POST.get('kalium6')
gravel6 = request.POST.get('gravel6')
mediumCoarseSand6 = request.POST.get('mediumCoarseSand6')
fineSand6 = request.POST.get('fineSand6')
veryFineSand6 = request.POST.get('veryFineSand6')
mucilage6 = request.POST.get('mucilage6')
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,
undertotaldryweight1=undertotaldryweight1, undertotaldryweight2=undertotaldryweight2,
undertotaldryweight3=undertotaldryweight3, file=file, rootbiomassarea=rootbiomassarea,smallkindside=smallkindside)
simplesoil1.save()
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,
undertotaldryweight1=undertotaldryweight1, undertotaldryweight2=undertotaldryweight2,
undertotaldryweight3=undertotaldryweight3, file=file, rootbiomassarea=rootbiomassarea,smallkindside=smallkindside)
simplesoil2.save()
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,
undertotaldryweight1=undertotaldryweight1, undertotaldryweight2=undertotaldryweight2,
undertotaldryweight3=undertotaldryweight3, file=file, rootbiomassarea=rootbiomassarea,smallkindside=smallkindside)
simplesoil3.save()
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,
undertotaldryweight1=undertotaldryweight1, undertotaldryweight2=undertotaldryweight2,
undertotaldryweight3=undertotaldryweight3, file=file, rootbiomassarea=rootbiomassarea,smallkindside=smallkindside)
simplesoil4.save()
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,
undertotaldryweight1=undertotaldryweight1, undertotaldryweight2=undertotaldryweight2,
undertotaldryweight3=undertotaldryweight3, file=file, rootbiomassarea=rootbiomassarea,smallkindside=smallkindside)
simplesoil5.save()
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,
undertotaldryweight1=undertotaldryweight1, undertotaldryweight2=undertotaldryweight2,
undertotaldryweight3=undertotaldryweight3, file=file, rootbiomassarea=rootbiomassarea,smallkindside=smallkindside)
simplesoil6.save()
return HttpResponse(json.dumps({
"status": "1",
"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':
j = 0
file = request.FILES.get("files[%s][fi]" % (j))
print(str(file) + "9999999999999999999999999999999")
username = request.POST.get('username')
soildepth = request.POST.get('soildepth')
agrotype = request.POST.get('agrotype')
matrix = request.POST.get('matrix')
ph = request.POST.get('ph')
color = request.POST.get('color')
organiccontent = request.POST.get('organiccontent')
nitrogen = request.POST.get('nitrogen')
phosphor = request.POST.get('phosphor')
kalium = request.POST.get('kalium')
gravel = request.POST.get('gravel')
mediumCoarseSand = request.POST.get('mediumCoarseSand')
fineSand = request.POST.get('fineSand')
veryFineSand = request.POST.get('veryFineSand')
mucilage = request.POST.get('mucilage')
thickness = request.POST.get('thickness')
rootbiomassarea = request.POST.get('rootbiomassarea')
undertotaldryweight1 = request.POST.get('undertotaldryweight1')
undertotaldryweight2 = request.POST.get('undertotaldryweight2')
undertotaldryweight3 = request.POST.get('undertotaldryweight3')
smallkindside = request.POST.get('smallkindside')
if file is not None:
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,
undertotaldryweight1=undertotaldryweight1,
undertotaldryweight2=undertotaldryweight2,
undertotaldryweight3=undertotaldryweight3,
rootbiomassarea=rootbiomassarea,smallkindside=smallkindside)
s = Simplesoil.objects.get(id=pk)
s.file = file
s.save()
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,
undertotaldryweight1=undertotaldryweight1,
undertotaldryweight2=undertotaldryweight2,
undertotaldryweight3=undertotaldryweight3,
rootbiomassarea=rootbiomassarea,smallkindside=smallkindside)
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,
"undertotaldryweight1": simplesoil.undertotaldryweight1,
"undertotaldryweight2": simplesoil.undertotaldryweight2,
"undertotaldryweight3": simplesoil.undertotaldryweight3,
"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)
results = []
for s in simplesoil:
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
o['undertotaldryweight1'] = s.undertotaldryweight1
o['undertotaldryweight2'] = s.undertotaldryweight2
o['undertotaldryweight3'] = s.undertotaldryweight3
results.append(o)
return HttpResponse(json.dumps({
"status": "1",
"simplesoil": results
}))
# 条形码
@csrf_exempt
def barcodes_upload(request):
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
findingscode = obj['findingscode']
chinesename = form['chinesename']
latinname = form['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 = Barcodes.objects.filter(name_id=id)
if len(results) != 0:
if len(chinesename) == 0 or len(latinname) == 0:
return HttpResponse(json.dumps({
"status": "0",
"message": "该物种已经存在"
}))
findings = Findings.objects.get(findingscode=findingscode)
barcodes = Barcodes(findings_id=findings.id, name_id=id,
dna_1=form['dna_1'],
dna_2=form['dna_2'], dna_3=form['dna_3'], dna_4=form['dna_4'], dna_5=form['dna_5'],
publisher=user, family=form['family'], category=form['category'],
findingscode=form['findingscode'])
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':
obj = json.loads(request.body.decode('utf-8'))
form = obj['form']
username = obj['username']
chinesename = form['chinesename']
latinname = form['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 = Barcodes.objects.filter(name_id=id)
if len(results) != 0:
if len(chinesename) == 0 or len(latinname) == 0:
return HttpResponse(json.dumps({
"status": "0",
"message": "该物种已经存在"
}))
Barcodes.objects.filter(id=pk).update(name_id=id, dna_1=form['dna_1'],
dna_2=form['dna_2'],
dna_3=form['dna_3'], dna_4=form['dna_4'], dna_5=form['dna_5'],
publisher=username, family=form['family'], category=form['category'],
findingscode=form['findingscode'])
return HttpResponse(json.dumps({
"status": "1",
"message": "修改成功",
}))
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,
"dna_1": barcodes.dna_1,
"dna_2": barcodes.dna_2,
"dna_3": barcodes.dna_3,
"dna_4": barcodes.dna_4,
"dna_5": barcodes.dna_5,
"family": barcodes.family,
"category": barcodes.category,
"findingscode": barcodes.findingscode,
}))
def barcodes_search(request):
findingscode = request.GET.get('findingscode')
barcodes = Barcodes.objects.filter(findings__findingscode=findingscode)
results = []
for b in barcodes:
o = dict()
o['id'] = str(b.id)
o['findingscode'] = findingscode
o['chinesename'] = Specieslibrary.objects.get(id=b.name_id).scientificchinesename
o['latinname'] = Specieslibrary.objects.get(id=b.name_id).latinname
o['family'] = b.family
o['category'] = b.category
o['dna_1'] = b.dna_1
o['dna_2'] = b.dna_2
o['dna_3'] = b.dna_3
o['dna_4'] = b.dna_4
o['dna_5'] = b.dna_5
results.append(o)
return HttpResponse(json.dumps({
"status": "1",
"barcodes": results
}))
# 土地利用
@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": "请输入完整信息",
}))
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": "修改成功",
}))
return HttpResponse(json.dumps({
"id": str(landuse.id),
"typelanduse": landuse.typelanduse,
# "arealanduse": landuse.arealanduse,
# "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)
results = []
for l in landuse:
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
}))
# 气象
@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)
results = []
for w in weather:
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
}))
# 群落
@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()
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.all()
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()
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.filter(findings__task_id=t.id).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()
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()
print(str(sampletrees1) + "=========================================")
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.filter(findings__task_id=t.id).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)
print(str(product_list))
print(str(sampletrees_list))
print(str(findings_list))
print(str(sampleherbal_list))
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)
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]
print(species)
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]
print(species)
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)
print(species_data_list)
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()
sampletrees_data_list = []
sampletreessampling_list = []
for s in sampletrees:
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,
}))
def task_distribution_sampletrees(request):
task = Task.objects.all()
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()
samplebush_data_list = []
for s in samplebush:
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,
}))
def task_distribution_samplebush(request):
task = Task.objects.all()
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()
sampleherbal_data_list = []
for s in sampleherbal:
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,
}))
def task_distribution_sampleherbal(request):
task = Task.objects.all()
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)
print(sampleherbal_list)
return HttpResponse(json.dumps({
"status": "1",
"sampleherbal_list": sampleherbal_list,
}))
# 调查点展示
def findings_data_list(request):
findings = Findings.objects.all()
findings_data_list = []
for f in findings:
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,
}))
# 调查点分布
def findings_distribution_geo(request):
findings = Findings.objects.all()
results = []
for f in findings:
o = dict()
o['lat'] = f.lat
o['lon'] = f.lon
o['findingscode'] = f.findingscode
o['investigators'] = f.investigators.name
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)
print(results)
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)
print(results)
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):
print(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
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))
print(files)
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')
print(type)
vegetationcommunity_data_list = []
vegetationcommunity = None
if len(type) != 0:
vegetationcommunity = Vegetationcommunity.objects.filter(type__contains=type)[:20]
print(vegetationcommunity)
else:
vegetationcommunity = Vegetationcommunity.objects.all()
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):
group = request.GET.get('group')
vegetationcommunity_data_list = []
vegetationcommunity = None
if len(group) != 0:
vegetationcommunity = Vegetationcommunity.objects.filter(group__contains=group)[:20]
else:
vegetationcommunity = Vegetationcommunity.objects.all()
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')
print("username:" + str(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'
print(src_dir)
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')
print("username:" + str(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'
print(src_dir)
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')
print("username:" + str(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'
print(src_dir)
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')
print("username:" + str(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'
print(src_dir)
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