-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidations.py
301 lines (243 loc) · 8.56 KB
/
validations.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import datetime
from variables import *
def check_role(username):
for user in all_users:
if username == user[0]:
role = user[3]
return role
def validation_username(username):
for user in all_users:
if username == user[0]:
print("Korisničko ime već postoji!!!")
return False
return True
def validation_password(password):
if len(password) < 6 or password.isalpha():
print("Šifra mora da sadrži barem 6 karaktera i 1 broj!!!")
return False
return True
def validation_is_word(input_value):
if input_value.isnumeric():
print("Unos ne sme da sadrži brojeve!!!")
return False
return True
def validation_time(input_value):
try:
datetime.datetime.strptime(input_value, '%H:%M')
return True
except ValueError:
print("Unesite vreme u odgovarajućem formatu!")
return False
def validation_date(input_value):
try:
datetime.datetime.strptime(input_value, '%d.%m.%Y.')
return True
except ValueError:
print("Unesite datum u odgovarajućem formatu!")
return False
def validation_name(input_value):
for movie in all_movies:
if input_value == movie[0]:
print("Takav film već postoji u sistemu!!!")
return False
return True
def validation_genre(input_value):
input_genre = input_value.split(", ")
for genre in input_genre:
if genre in genres:
return True
print("Unos nije odgovarajuć!!!")
return False
def validation_genre_search(input_value):
for genre in genres:
if input_value in genre:
return True
print("Unos nije odgovarajuć!!!")
return False
def validation_length(input_value):
if input_value.isnumeric():
return True
print("Unos mora biti broj!!!")
return False
def validation_year(input_value):
if input_value.isnumeric() and len(input_value) == 4:
return True
print("Format unosa nije validan (godina je formata ČETIRI BROJA!)!!!")
return False
def validation_days(input_value):
days = input_value.split(", ")
for weekday in days:
if weekday in working_days:
return True
else:
print("Unos nije odgovarajuć!!!")
return False
def validation_projection(input_hall, input_start_time, input_end_time, input_days):
for projection_code, projection in projections.items():
if projection["hall"] == input_hall.upper() and input_days.lower() in projection["days"].lower() and (
(projection["start time"][0:2] <= input_start_time[0:2] <= projection["end time"][0:2]) or
(projection["start time"][0:2] <= input_end_time[0:2] <= projection["end time"][0:2])):
print("Postoji projekcija koja se tada prikazuje!!!")
return False
return True
def validation_hall(input_value):
for hall in movie_halls.keys():
if input_value.upper() in hall:
return True
else:
print("Takva sala ne postoji!!!")
return False
def check_movie(input_movie_name):
for movie in all_movies:
if input_movie_name.lower() in movie[0].lower():
return True
print("Ne postoji takav film u sistemu!!!")
return False
def validation_editing(input_value, index):
if index == 0:
if validation_name(input_value):
return True
return False
elif index == 1:
if validation_genre(input_value):
return True
return False
elif index == 2:
if validation_length(input_value):
return True
return False
elif index == 3 or index == 4 or index == 5:
if validation_is_word(input_value):
return True
return False
elif index == 6:
if validation_year(input_value):
return True
return False
def validation_projection_search(input_value, index):
if index == 1:
if validation_date(input_value):
return True
return False
elif index == 2:
if check_movie(input_value):
return True
return False
elif index == 3 or index == 4:
if validation_time(input_value):
return True
return False
elif index == 5:
if validation_hall(input_value):
return True
return False
def validation_movie_search(input_value, index):
if index == 0:
if check_movie(input_value):
return True
return False
elif index == 1:
if validation_genre_search(input_value):
return True
return False
elif index == 3 or index == 4 or index == 5:
if validation_is_word(input_value):
return True
return False
elif index == 6:
if validation_year(input_value):
return True
return False
def check_ticket_price(day, projection):
import datetime
if datetime.datetime.strptime(day, "%d.%m.%Y.").weekday() == 1:
new_price = float(projection["ticket price"]) - 50.00
elif datetime.datetime.strptime(day, "%d.%m.%Y.").weekday() > 4:
new_price = float(projection["ticket price"]) + 50.00
else:
new_price = float(projection["ticket price"])
return new_price
def validation_seat(screening_code, selected_seat):
for row in hall_seats[screening_code.upper()]:
for i in range(len(row)):
if selected_seat.upper() == row[i]:
return True
print("Ne postoji takvo sedište!")
return False
def validation_ticket_key(input_value):
for key in tickets.keys():
if input_value in str(key):
return True
print("Ne postoji takva karta!")
return False
def validation_screening_code(input_value):
for key in screenings.keys():
if input_value in key:
return True
print("Ne postoji projekcija sa takvom šifrom!")
return False
def validation_start_time(screening_key):
today_string = datetime.datetime.today().strftime('%d.%m.%Y.')
today = today_string.split(".")
year_now = int(today[2])
month_now = int(today[1])
day_now = int(today[0])
screening_date = screenings[screening_key]["date"]
date = screening_date.split(".")
year = int(date[2])
month = int(date[1])
day = int(date[0])
now_string = datetime.datetime.now().strftime('%H:%M')
now = now_string.split(":")
hour_now = int(now[0])
minute_now = int(now[1])
second_now = 0
start_time = projections[screening_key[0:4]]["start time"].split(":")
start_hour = int(start_time[0])
start_minute = int(start_time[1])
start_second = 0
current = datetime.datetime(year_now, month_now, day_now, hour_now, minute_now, second_now)
start = datetime.datetime(year, month, day, start_hour, start_minute, start_second)
limit = start - datetime.timedelta(minutes=30)
if current >= limit:
return True
print("Još uvek mogu da se preuzmu rezervacije!!!")
return False
def validation_employee(input_value):
for user in all_users:
if input_value.lower() in user[0].lower() and user[3] != "Kupac":
return True
print("Ne postoji registrovani radnik sa takvim imenom!!!")
return False
def validation_client(input_value):
for ticket in tickets.values():
if input_value in ticket["client"]:
return True
print("Ne postoji karta rezervisana pod ovim imenom!!!")
return False
def validation_client_screening(input_client, input_screening):
for ticket in tickets.values():
if input_client in ticket["client"] and input_screening in ticket["screening code"]:
return True
print("Ovaj klijent nije rezervisao kartu za odabrani termin!!!")
return False
def validation_client_screening_seat(input_client, input_screening, input_seat):
for ticket in tickets.values():
if (input_client in ticket["client"] and input_screening in ticket["screening code"]
and input_seat in ticket["seat"]):
return True
print("Ovaj klijent nije rezervisao odabrano sedište za odabrani termin!!!")
return False
def split_date(date):
values = date.split(".")
day = values[0]
month = values[1]
year = values[2]
date_split = datetime.datetime(int(year), int(month), int(day))
return date_split
def validation_reserved_screening(input_value):
for ticket in tickets.values():
if ticket["status"] == "rezervisana" and input_value.upper() in ticket["screening code"]:
return True
print("Ne postoji rezervacija za ovaj termin!!!")
return False