|
|
|
@ -0,0 +1,203 @@
|
|
|
|
|
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')
|
|
|
|
|
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函数
|
|
|
|
|
|
|
|
|
|
def register(request):
|
|
|
|
|
if request.method == 'GET':
|
|
|
|
|
return render(request,'register.html')
|
|
|
|
|
else:
|
|
|
|
|
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:
|
|
|
|
|
return HttpResponse('不允许为空!')
|
|
|
|
|
if password != confirmPassword:
|
|
|
|
|
return HttpResponse('两次密码不一致!')
|
|
|
|
|
User.objects.create(username=username,password=password)#创建一个用户
|
|
|
|
|
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('../')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|