|
|
from django.shortcuts import render,redirect
|
|
|
|
|
|
from SS01.models import User,TravelInfo,SaleTicketDetail
|
|
|
from django.http import HttpResponse
|
|
|
from SS01.utils import errorResponse,getPublicData,getIndexData,getChangeSelfInfo
|
|
|
|
|
|
# Create your views here.
|
|
|
|
|
|
def login(request):
|
|
|
if request.method == 'GET':
|
|
|
return render(request,'login.html')
|
|
|
else:
|
|
|
username = request.POST.get('username')
|
|
|
password = request.POST.get('password')
|
|
|
|
|
|
cd = username
|
|
|
zhlei = request.POST.get('zhlei')
|
|
|
data = {cd:zhlei}
|
|
|
|
|
|
if zhlei == "普通用户":
|
|
|
try:
|
|
|
User.objects.get(username=username,password=password) #get查询,如果未存在就执行except
|
|
|
request.session['username'] = username
|
|
|
return redirect('/SS01/index')
|
|
|
except:
|
|
|
return errorResponse.errorResponse(request,'账号或密码错误!') #utils中的模块,调用errorMsg函数
|
|
|
else:
|
|
|
try:
|
|
|
User.objects.get(username=username, password=password) # get查询,如果未存在就执行except
|
|
|
request.session['username'] = username
|
|
|
return redirect('/SS01/Mindex')
|
|
|
except:
|
|
|
return errorResponse.errorResponse(request, '账号或密码错误!') # utils中的模块,调用errorMsg函数
|
|
|
|
|
|
def register(request):
|
|
|
if request.method == 'GET':
|
|
|
return render(request,'register.html')
|
|
|
else:
|
|
|
zhlei = request.POST.get('zhlei')
|
|
|
username = request.POST.get('username')
|
|
|
password = request.POST.get('password')
|
|
|
confirmPassword = request.POST.get('confirmPassword')
|
|
|
try:
|
|
|
User.objects.get(username=username) #get查询,如果未存在就执行except创建用户
|
|
|
except:
|
|
|
if not username or not password or not confirmPassword or not zhlei:
|
|
|
return HttpResponse('不允许为空!')
|
|
|
if password != confirmPassword:
|
|
|
return HttpResponse('两次密码不一致!')
|
|
|
User.objects.create(username=username,password=password,ZHlei=zhlei)#创建一个用户
|
|
|
return redirect('/SS01/login')
|
|
|
|
|
|
return errorResponse.errorResponse(request,'该账号已存在')
|
|
|
|
|
|
def logOut(request):
|
|
|
request.session.clear()
|
|
|
return redirect('/SS01/login')
|
|
|
|
|
|
def index(request):
|
|
|
username = request.session.get('username') #在后台有一个username的值,只有登录以后才会跳转到首页页面
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
A5Len, commentsLenTitle, provienceDicSort = getIndexData.getIndexTagData()
|
|
|
scoreTop10Data,saleCountTop10 = getIndexData.getAnthorData()
|
|
|
year,mon,day = getIndexData.getNowTime()
|
|
|
geoData = getIndexData.getGeoData()
|
|
|
return render(request,'index.html',{
|
|
|
'userInfo': userInfo,
|
|
|
'A5Len':A5Len,
|
|
|
'commentsLenTitle': commentsLenTitle,
|
|
|
'provienceDicSort': provienceDicSort,
|
|
|
'scoreTop10Data':scoreTop10Data,
|
|
|
'nowTime':{
|
|
|
'year': year,
|
|
|
'mon': getPublicData.monthList[mon-1],
|
|
|
'day': day,
|
|
|
},
|
|
|
'geoData':geoData,
|
|
|
'saleCountTop10':saleCountTop10,
|
|
|
})
|
|
|
def changeSelfInfo(request):
|
|
|
username = request.session.get('username')
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
year, mon, day = getIndexData.getNowTime()
|
|
|
if request.method == 'POST':
|
|
|
getChangeSelfInfo.changeSelfInfo(username,request.POST,request.FILES)
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
|
|
|
return render(request, 'changeSelfInfo.html', {
|
|
|
'userInfo': userInfo,
|
|
|
'nowTime': {
|
|
|
'year': year,
|
|
|
'mon': getPublicData.monthList[mon - 1],
|
|
|
'day': day,
|
|
|
},
|
|
|
})
|
|
|
def changePassword(request):
|
|
|
username = request.session.get('username')
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
year, mon, day = getIndexData.getNowTime()
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
res = getChangeSelfInfo.getChangePassword(userInfo,request.POST)
|
|
|
if res != None:
|
|
|
return errorResponse.errorResponse(request,res)
|
|
|
|
|
|
return render(request, 'changePassword.html', {
|
|
|
'userInfo': userInfo,
|
|
|
'nowTime': {
|
|
|
'year': year,
|
|
|
'mon': getPublicData.monthList[mon - 1],
|
|
|
'day': day,
|
|
|
},
|
|
|
})
|
|
|
def saleTicket(request):
|
|
|
username = request.session.get('username')
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
year, mon, day = getIndexData.getNowTime()
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
title = request.POST.get('title')
|
|
|
cday = request.POST.get('cday')
|
|
|
name = request.POST.get('name')
|
|
|
idcard = request.POST.get('idcard')
|
|
|
connection = request.POST.get('connection')
|
|
|
if title == '':
|
|
|
return HttpResponse('景区名不能为空!请返回重新填写!')
|
|
|
if cday == '':
|
|
|
return HttpResponse('预约日期不能为空!请返回重新填写!')
|
|
|
if name == '':
|
|
|
return HttpResponse('您的姓名不能为空!请返回重新填写!')
|
|
|
if idcard == '':
|
|
|
return HttpResponse('身份证号不能为空!请返回重新填写!')
|
|
|
if connection == '':
|
|
|
return HttpResponse('联系方式不能为空!请返回重新填写!')
|
|
|
SaleTicketDetail.objects.create(
|
|
|
title=title,
|
|
|
day=cday,
|
|
|
name=name,
|
|
|
Idcard=idcard,
|
|
|
connection=connection,
|
|
|
) # 创建数据
|
|
|
|
|
|
return render(request, 'saleTicket.html', {
|
|
|
'userInfo': userInfo,
|
|
|
'nowTime': {
|
|
|
'year': year,
|
|
|
'mon': getPublicData.monthList[mon - 1],
|
|
|
'day': day,
|
|
|
},
|
|
|
})
|
|
|
def saleTicketInfo(request):
|
|
|
username = request.session.get('username')
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
saleTicketInfoData = SaleTicketDetail.objects.all()
|
|
|
year, mon, day = getIndexData.getNowTime()
|
|
|
return render(request, 'saleTicketInfo.html', {
|
|
|
'userInfo': userInfo,
|
|
|
'saleTicketInfoData':saleTicketInfoData,
|
|
|
'nowTime': {
|
|
|
'year': year,
|
|
|
'mon': getPublicData.monthList[mon - 1],
|
|
|
'day': day,
|
|
|
},
|
|
|
})
|
|
|
def ticketFox(request):
|
|
|
username = request.session.get('username')
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
year, mon, day = getIndexData.getNowTime()
|
|
|
nid = request.GET.get('nid')
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
titlefox = request.POST.get('titleFox')
|
|
|
cdayfox = request.POST.get('cdayFox')
|
|
|
connectionfox = request.POST.get('connectionFox')
|
|
|
|
|
|
if titlefox == '':
|
|
|
return HttpResponse('景区名不能为空!请返回重新填写!')
|
|
|
elif cdayfox == '':
|
|
|
return HttpResponse('预约时间不能为空!请返回重新填写!')
|
|
|
elif connectionfox == '':
|
|
|
return HttpResponse('联系方式不能为空!请返回重新填写!')
|
|
|
else:
|
|
|
SaleTicketDetail.objects.filter(id=nid).update(
|
|
|
title=titlefox,
|
|
|
day=cdayfox,
|
|
|
connection=connectionfox
|
|
|
)
|
|
|
return redirect("/SS01/saleTicketInfo/")
|
|
|
|
|
|
return render(request, 'ticketFox.html', {
|
|
|
'userInfo': userInfo,
|
|
|
'nowTime': {
|
|
|
'year': year,
|
|
|
'mon': getPublicData.monthList[mon - 1],
|
|
|
'day': day,
|
|
|
},
|
|
|
})
|
|
|
def saleTicketInfo_delete(request):
|
|
|
nid = request.GET.get('nid')
|
|
|
|
|
|
SaleTicketDetail.objects.filter(id=nid).delete()
|
|
|
|
|
|
return redirect('../')
|
|
|
|
|
|
def MGchangeSelfInfo(request):
|
|
|
username = request.session.get('username')
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
year, mon, day = getIndexData.getNowTime()
|
|
|
if request.method == 'POST':
|
|
|
getChangeSelfInfo.changeSelfInfo(username,request.POST,request.FILES)
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
|
|
|
return render(request, 'MGchangeSelfInfo.html', {
|
|
|
'userInfo': userInfo,
|
|
|
'nowTime': {
|
|
|
'year': year,
|
|
|
'mon': getPublicData.monthList[mon - 1],
|
|
|
'day': day,
|
|
|
},
|
|
|
})
|
|
|
def MGchangePassword(request):
|
|
|
username = request.session.get('username')
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
year, mon, day = getIndexData.getNowTime()
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
res = getChangeSelfInfo.getChangePassword(userInfo,request.POST)
|
|
|
if res != None:
|
|
|
return errorResponse.errorResponse(request,res)
|
|
|
|
|
|
return render(request, 'MGchangePassword.html', {
|
|
|
'userInfo': userInfo,
|
|
|
'nowTime': {
|
|
|
'year': year,
|
|
|
'mon': getPublicData.monthList[mon - 1],
|
|
|
'day': day,
|
|
|
},
|
|
|
})
|
|
|
|
|
|
def Mindex(request):
|
|
|
username = request.session.get('username') # 在后台有一个username的值,只有登录以后才会跳转到首页页面
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
A5Len, commentsLenTitle, provienceDicSort = getIndexData.getIndexTagData()
|
|
|
scoreTop10Data, saleCountTop10 = getIndexData.getAnthorData()
|
|
|
year, mon, day = getIndexData.getNowTime()
|
|
|
geoData = getIndexData.getGeoData()
|
|
|
return render(request, 'Mindex.html', {
|
|
|
'userInfo': userInfo,
|
|
|
'A5Len': A5Len,
|
|
|
'commentsLenTitle': commentsLenTitle,
|
|
|
'provienceDicSort': provienceDicSort,
|
|
|
'scoreTop10Data': scoreTop10Data,
|
|
|
'nowTime': {
|
|
|
'year': year,
|
|
|
'mon': getPublicData.monthList[mon - 1],
|
|
|
'day': day,
|
|
|
},
|
|
|
'geoData': geoData,
|
|
|
'saleCountTop10': saleCountTop10,
|
|
|
})
|
|
|
def MAddJD(request):
|
|
|
username = request.session.get('username')
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
year, mon, day = getIndexData.getNowTime()
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
titlefox = request.POST.get('title')
|
|
|
levelfox = request.POST.get('level')
|
|
|
provincefox = request.POST.get('province')
|
|
|
scorefox = request.POST.get('score')
|
|
|
pricefox = request.POST.get('price')
|
|
|
saleCountfox = request.POST.get('saleCount')
|
|
|
detailAddressfox = request.POST.get('detailAddress')
|
|
|
shortIntrofox = request.POST.get('shortIntro')
|
|
|
detailIntrofox = request.POST.get('detailIntro')
|
|
|
|
|
|
if titlefox == '':
|
|
|
return HttpResponse('景区名称不能为空!请返回重新填写!')
|
|
|
elif levelfox == '':
|
|
|
return HttpResponse('景点等级不能为空!请返回重新填写!')
|
|
|
elif provincefox == '':
|
|
|
return HttpResponse('景区地点不能为空!请返回重新填写!')
|
|
|
elif scorefox == '':
|
|
|
return HttpResponse('景区评分不能为空!请返回重新填写!')
|
|
|
elif pricefox == '':
|
|
|
return HttpResponse('价格不能为空!请返回重新填写!')
|
|
|
elif saleCountfox == '':
|
|
|
return HttpResponse('销量不能为空!请返回重新填写!')
|
|
|
elif detailAddressfox == '':
|
|
|
return HttpResponse('详细地址不能为空!请返回重新填写!')
|
|
|
elif shortIntrofox == '':
|
|
|
return HttpResponse('简介不能为空!请返回重新填写!')
|
|
|
elif detailIntrofox == '':
|
|
|
return HttpResponse('详细介绍不能为空!请返回重新填写!')
|
|
|
else:
|
|
|
Mr = "www.baidu.com"
|
|
|
TravelInfo.objects.create(
|
|
|
title=titlefox,
|
|
|
level=levelfox,
|
|
|
discount=Mr,
|
|
|
saleCount=saleCountfox,
|
|
|
province=provincefox,
|
|
|
star=Mr,
|
|
|
detailAddress=detailAddressfox,
|
|
|
shortIntro=shortIntrofox,
|
|
|
detailUrl=Mr,
|
|
|
score=scorefox,
|
|
|
price=pricefox,
|
|
|
commentsLen=Mr,
|
|
|
detailIntro=detailIntrofox,
|
|
|
img_list=Mr,
|
|
|
comments=Mr,
|
|
|
cover=Mr,
|
|
|
) # 创建数据
|
|
|
|
|
|
return render(request, 'MAddJD.html', {
|
|
|
'userInfo': userInfo,
|
|
|
'nowTime': {
|
|
|
'year': year,
|
|
|
'mon': getPublicData.monthList[mon - 1],
|
|
|
'day': day,
|
|
|
},
|
|
|
})
|
|
|
def MaddressDetail(request):
|
|
|
username = request.session.get('username')
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
MaddressDetailData = TravelInfo.objects.all()
|
|
|
year, mon, day = getIndexData.getNowTime()
|
|
|
return render(request, 'MaddressDetail.html', {
|
|
|
'userInfo': userInfo,
|
|
|
'MaddressDetailData':MaddressDetailData,
|
|
|
'nowTime': {
|
|
|
'year': year,
|
|
|
'mon': getPublicData.monthList[mon - 1],
|
|
|
'day': day,
|
|
|
},
|
|
|
})
|
|
|
def MaddressFox(request):
|
|
|
username = request.session.get('username')
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
|
|
|
year, mon, day = getIndexData.getNowTime()
|
|
|
nid = request.GET.get('nid')
|
|
|
MaddressDetailData = TravelInfo.objects.get(id=nid)
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
titlefox = request.POST.get('title')
|
|
|
levelfox = request.POST.get('level')
|
|
|
provincefox = request.POST.get('province')
|
|
|
scorefox = request.POST.get('score')
|
|
|
pricefox = request.POST.get('price')
|
|
|
saleCountfox = request.POST.get('saleCount')
|
|
|
detailAddressfox = request.POST.get('detailAddress')
|
|
|
shortIntrofox = request.POST.get('shortIntro')
|
|
|
detailIntrofox = request.POST.get('detailIntro')
|
|
|
|
|
|
if titlefox == '':
|
|
|
return HttpResponse('景区名称不能为空!请返回重新填写!')
|
|
|
elif levelfox == '':
|
|
|
return HttpResponse('景点等级不能为空!请返回重新填写!')
|
|
|
elif provincefox == '':
|
|
|
return HttpResponse('景区地点不能为空!请返回重新填写!')
|
|
|
elif scorefox == '':
|
|
|
return HttpResponse('景区评分不能为空!请返回重新填写!')
|
|
|
elif pricefox == '':
|
|
|
return HttpResponse('价格不能为空!请返回重新填写!')
|
|
|
elif saleCountfox == '':
|
|
|
return HttpResponse('销量不能为空!请返回重新填写!')
|
|
|
elif detailAddressfox == '':
|
|
|
return HttpResponse('详细地址不能为空!请返回重新填写!')
|
|
|
elif shortIntrofox == '':
|
|
|
return HttpResponse('简介不能为空!请返回重新填写!')
|
|
|
elif detailIntrofox == '':
|
|
|
return HttpResponse('详细介绍不能为空!请返回重新填写!')
|
|
|
else:
|
|
|
TravelInfo.objects.filter(id=nid).update(
|
|
|
title=titlefox,
|
|
|
level=levelfox,
|
|
|
saleCount=saleCountfox,
|
|
|
province=provincefox,
|
|
|
detailAddress=detailAddressfox,
|
|
|
shortIntro=shortIntrofox,
|
|
|
score=scorefox,
|
|
|
price=pricefox,
|
|
|
detailIntro=detailIntrofox,
|
|
|
)
|
|
|
return redirect("/SS01/MaddressDetail/")
|
|
|
|
|
|
return render(request, 'MaddressFox.html', {
|
|
|
'userInfo':userInfo,
|
|
|
'MaddressDetailData':MaddressDetailData,
|
|
|
'nowTime': {
|
|
|
'year': year,
|
|
|
'mon': getPublicData.monthList[mon - 1],
|
|
|
'day': day,
|
|
|
},
|
|
|
})
|
|
|
def MaddressDetail_delete(request):
|
|
|
nid = request.GET.get('nid')
|
|
|
TravelInfo.objects.filter(id=nid).delete()
|
|
|
return redirect('../')
|
|
|
|
|
|
def userDetail(request):
|
|
|
username = request.session.get('username')
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
userDetailData = SaleTicketDetail.objects.all()
|
|
|
year, mon, day = getIndexData.getNowTime()
|
|
|
return render(request, 'userDetail.html', {
|
|
|
'userInfo': userInfo,
|
|
|
'userDetailData':userDetailData,
|
|
|
'nowTime': {
|
|
|
'year': year,
|
|
|
'mon': getPublicData.monthList[mon - 1],
|
|
|
'day': day,
|
|
|
},
|
|
|
})
|
|
|
|
|
|
def userFox(request):
|
|
|
username = request.session.get('username')
|
|
|
userInfo = User.objects.get(username=username)
|
|
|
year, mon, day = getIndexData.getNowTime()
|
|
|
nid = request.GET.get('nid')
|
|
|
|
|
|
SaleTicketDetailw = SaleTicketDetail.objects.get(id=nid)
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
titlefox = request.POST.get('titleFox')
|
|
|
cdayfox = request.POST.get('cdayFox')
|
|
|
cnameFox = request.POST.get('nameFox')
|
|
|
cIDcardFoxfox = request.POST.get('IDcardFox')
|
|
|
connectionfox = request.POST.get('connectionFox')
|
|
|
|
|
|
if titlefox == '':
|
|
|
return HttpResponse('景区名不能为空!请返回重新填写!')
|
|
|
elif cdayfox == '':
|
|
|
return HttpResponse('预约时间不能为空!请返回重新填写!')
|
|
|
elif cnameFox == '':
|
|
|
return HttpResponse('真实姓名不能为空!请返回重新填写!')
|
|
|
elif cIDcardFoxfox == '':
|
|
|
return HttpResponse('身份证号不能为空!请返回重新填写!')
|
|
|
elif connectionfox == '':
|
|
|
return HttpResponse('联系方式不能为空!请返回重新填写!')
|
|
|
else:
|
|
|
SaleTicketDetail.objects.filter(id=nid).update(
|
|
|
title=titlefox,
|
|
|
day=cdayfox,
|
|
|
connection=connectionfox,
|
|
|
name=cnameFox,
|
|
|
Idcard=cIDcardFoxfox,
|
|
|
)
|
|
|
return redirect("/SS01/userDetail/")
|
|
|
|
|
|
return render(request, 'userFox.html', {
|
|
|
'userInfo': userInfo,
|
|
|
'SaleTicketDetailw':SaleTicketDetailw,
|
|
|
'nowTime': {
|
|
|
'year': year,
|
|
|
'mon': getPublicData.monthList[mon - 1],
|
|
|
'day': day,
|
|
|
},
|
|
|
})
|
|
|
|
|
|
def userDetail_delete(request):
|
|
|
nid = request.GET.get('nid')
|
|
|
SaleTicketDetail.objects.filter(id=nid).delete()
|
|
|
return redirect('../')
|
|
|
|