-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
129 lines (109 loc) · 4.02 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from django.shortcuts import render
from disaster.models import main,login,givealert
from django.http import HttpResponse
from django.http import Http404
def index(request):
Template_get="index.html"
if request.method=='GET':
govtalert={'alert':givealert.objects.last()}
return render(request,Template_get,govtalert)
if request.method=='POST':
govtalert={'alert':givealert.objects.last()}
return render(request,Template_get,govtalert)
def index_post(request):
Template_post="output.html"
if request.method=='POST':
try:
num=request.POST.get('input',None)
selected=main.objects.get(yourlocation=num)
context={'data':selected}
except main.DoesNotExist:
raise Http404("entered location does not existed")
return render(request,Template_post,context)
def govt_page(request):
Template_alert="alert.html"
Template="login.html"
Template_admin="admin.html"
if request.method == 'GET':
return render(request,Template)
if request.method == 'POST':
user = request.POST.get('user',False)
pas = request.POST.get('passkey',False)
if login.objects.filter(username=user).exists() and login.objects.filter(password=pas).exists():
context = {'username':user}
return render(request,Template_admin,context)
else:
context={'error':"username or password is wrong"}
return render(request,Template,context)
def delete(request):
Template="deldata.html"
if request.method == 'GET':
return render(request,Template)
if request.method == 'POST':
user = request.POST.get('delsafeplace',False)
if main.objects.filter(yourlocation=user).exists():
delete = main.objects.filter(yourlocation=user).delete()
context={'delete':"your entered location is deleted"}
return render(request,Template,context)
else:
context={'delete':"entered location is not exist"}
return render(request,Template,context)
def forgot(request):
Template="forgotpswd.html"
if request.method == 'GET':
return render(request,Template)
if request.method == 'POST':
username = request.POST.get('username',False)
schoolans = request.POST.get('school',False)
user = login.objects.get(username=username)
ans = login.objects.get(answer=schoolans)
if user and ans:
context={'user':login.objects.get(username=username)}
return render(request,Template,context)
def adddata(request):
if request.method =="GET":
Template_alert ="enter data.html"
return render(request,Template_alert)
if request.method == "POST":
Template_data="enter data.html"
safeplaces1 = request.POST.get('safeplace1')
safeplaces2 = request.POST.get('safeplace2')
safeplaces3 = request.POST.get('safeplace3')
safeplaces4 = request.POST.get('safeplace4')
safeplaces5 = request.POST.get('safeplace5')
transports1 = request.POST.get('transport1')
transports2 = request.POST.get('transport2')
transports3 = request.POST.get('transport3')
rescue1 = request.POST.get('rescue1')
rescue2 = request.POST.get('rescue2')
rescue3 = request.POST.get('rescue3')
if main.objects.filter(yourlocation=safeplaces1).exists():
context={'error':"entered location is all ready exist"}
return render(request,Template_data,context)
else:
post=main(yourlocation=safeplaces1,
safeplacesname=safeplaces2,
safeplacesdistance=safeplaces3,
safeplacescapacity=safeplaces4,
safeplacescontact=safeplaces5,
transportname=transports1,
transporttypeof=transports2,
transportcontact=transports3,
rescueteammembers=rescue2,
rescuecontact=rescue3,
rescueteamtype=rescue1,
)
post.save()
context = {'error':'successfully added data'}
return render(request,Template_data,context)
def govtadmin(request):
Template_addgovt="add govt.html"
return render(request,Template_addgovt)
def alert(request):
Template_admin="alert.html"
if request.method=="GET":
return render(request,Template_admin)
if request.method=="POST":
alert = request.POST.get('alert_','True')
instance = givealert.objects.create(alertinfo=alert)
return render(request,Template_admin)