-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
101 lines (84 loc) · 3.14 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from django.shortcuts import render
from django.core.mail import send_mail,BadHeaderError
from .models import Booking,Driver
from .forms import BookingForm,Driverform,UserForm
from django.shortcuts import redirect
from django.contrib.auth import authenticate, login, logout
from django.contrib import messages
from django.contrib.auth.decorators import login_required
# Create your views here.
def index(request):
form=BookingForm()
registered=False
if request.method=='POST':
form=BookingForm(data=request.POST)
if form.is_valid():
user_detail=form.save()
print(user_detail)
registered=True
return redirect('index')
return render(request,'index.html',context={'myform':form})
def contact(request):
if request.method=="POST":
proj_name=request.POST['name']
proj_email=request.POST['email']
proj_subject=request.POST['subject']
proj_message=request.POST['message']
send_mail(
proj_name,
proj_message,
proj_email,
['jonathanjhonnyamarwal@gmail.com'],
fail_silently=False,
)
return render(request,'contact.html',{'name':proj_name})
else:
return render(request,'contact.html',{})
def driver(request):
p=Driverform()
user_form = UserForm()
registered=False
if request.method=="POST":
user_form = UserForm(data=request.POST)
p=Driverform(data=request.POST)
print(p.is_valid(),end=" ")
print("hello")
print(user_form.is_valid())
if user_form.is_valid() and p.is_valid() :
# driver_details=p.save()
# print(driver_details)
x=user_form.save()
x.set_password(x.password)
x.save()
p.save(x.username)
registered=True
user=user_form.cleaned_data.get('username')
messages.success(request,'The Account was created for '+ user)
return redirect('login')
# print(p)
return render(request,'driver.html',context={'detailsform':p,'userform':user_form})
@login_required
def bookingdetails(request):
# bookingdetails=Booking.objects.filter()
bookingdetails=Booking.objects.all()
return render(request,'detail.html',context={'bookingdetails':bookingdetails})
@login_required
def driverdetails(request):
driverdetails=Driver.objects.all()
print(driverdetails)
print(request)
return render(request,'driverdetails.html',context={'driverdetails':driverdetails})
def loginform(request):
if request.method =='POST':
username=request.POST.get('username')
password=request.POST.get('password')
user=authenticate(request,username=username,password=password)
if user is not None:
login(request,user)
return redirect('details')
else:
messages.info(request,'The Username or Password is Incorrect')
return render(request,'login.html',context={})
def logoutform(request):
logout(request)
return redirect('login')