@@ -27,23 +27,37 @@ def shutdown():
27
27
write ()
28
28
session .clear ()
29
29
shutdown_server ()
30
- flash ('Records Saved' )
30
+ print len (cache_records ())
31
+ try :
32
+ if len (cache_records ()) >= 1 :
33
+ flash (
34
+ 'Notification : Records Saved !'
35
+ )
36
+ except Exception :
37
+ flash (
38
+ 'Notification : New file created with name "%s" ' % (
39
+ sys .argv [1 ]
40
+ )
41
+ )
31
42
return render_template ('layouts/shutdown.html' )
32
43
33
44
34
45
# Controllers.
35
-
36
-
37
46
def write ():
38
47
try :
39
48
records = cache_records ()
40
49
for i in records :
41
50
print i
42
51
except Exception :
43
- flash ('New File created with name %s' % (sys .argv [1 ]))
44
-
52
+ flash (
53
+ 'New File created with name %s' % (
54
+ sys .argv [1 ]
55
+ )
56
+ )
45
57
with open (sys .argv [1 ], 'w+' ) as csvfile :
46
- fieldnames = ['ids' , 'student_name' , 'academics' , 'sports' , 'social' ]
58
+ fieldnames = [
59
+ 'ids' , 'student_name' , 'academics' , 'sports' , 'social'
60
+ ]
47
61
writer = csv .DictWriter (csvfile , fieldnames = fieldnames )
48
62
49
63
writer .writeheader ()
@@ -69,9 +83,10 @@ def read_cache():
69
83
70
84
def write_cache (student_name , academics , sports , social ):
71
85
data = cache_records ()
72
- if len (data ) >= 20 :
86
+ if len (data ) > 20 :
73
87
count = session ['count' ]
74
- delete_cache (count )
88
+ print count
89
+ data = delete_cache (count )
75
90
new_dict = {}
76
91
new_dict ['ids' ] = ids_get ()
77
92
new_dict ['student_name' ] = student_name
@@ -129,12 +144,10 @@ def delete():
129
144
session ['ids' ] = request .form ['submit' ]
130
145
session ['delete' ] = request .form ['delete' ]
131
146
ids = session ['ids' ]
132
- data = delete_cache (
133
- session ['ids' ]
134
- )
147
+ data = delete_cache (ids )
135
148
session ['data' ] = data
136
149
flash (
137
- 'Successfully Deleted ID %s' % (ids )
150
+ 'Notification : Successfully deleted records with ID %s' % (ids )
138
151
)
139
152
session ['ids' ] = None
140
153
session ['student_name' ] = None
@@ -166,19 +179,19 @@ def update():
166
179
social = form .social .data
167
180
if academics is None or int (academics ) > 100 :
168
181
flash (
169
- '%s is not a valid score.\
182
+ 'Notification : %s is not a valid score.\
170
183
Please enter valid score for Academics' % (
171
184
academics ))
172
185
return redirect (url_for ('update' ))
173
186
elif sports is None or int (sports ) > 100 :
174
187
flash (
175
- '%s is not a valid score.\
188
+ 'Notification : %s is not a valid score.\
176
189
Please enter valid score for Sports' % (
177
190
sports ))
178
191
return redirect (url_for ('update' ))
179
192
elif social is None or int (social ) > 100 :
180
193
flash (
181
- '%s is not a valid score.\
194
+ 'Notification : %s is not a valid score.\
182
195
Please enter valid score for Social' % (
183
196
social ))
184
197
return redirect (url_for ('update' ))
@@ -189,7 +202,7 @@ def update():
189
202
)
190
203
session ['data' ] = data
191
204
flash (
192
- 'Successfully Updated %s \
205
+ 'Notification : Successfully updated record for %s \
193
206
with ID %s' % (name , ids )
194
207
)
195
208
return redirect (url_for ('home' ))
@@ -203,7 +216,10 @@ def addinfo():
203
216
try :
204
217
ids = ids_get ()
205
218
except Exception :
206
- flash ('File Doesnot exits Shutdown to Create a file with name %s' % (sys .argv [1 ]))
219
+ flash (
220
+ 'Notification : File doesnot exits. Shutdown to create a \
221
+ file with name %s' % (sys .argv [1 ])
222
+ )
207
223
return redirect (url_for ('home' ))
208
224
form = add_student (request .form )
209
225
if request .method == 'POST' :
@@ -212,34 +228,42 @@ def addinfo():
212
228
sports = form .sports .data
213
229
social = form .social .data
214
230
if student_name is None :
215
- flash ('%s is not vaild. Please Enter valid name' % student_name )
231
+ flash (
232
+ 'Notification : %s is not vaild. Please Enter valid \
233
+ name' % student_name
234
+ )
216
235
return redirect (url_for ('addinfo' ))
217
236
elif academics is None or int (academics ) > 100 :
218
237
flash (
219
- '%s is not a valid score.\
238
+ 'Notification : %s is not a valid score.\
220
239
Please enter valid score for Academics' % (
221
- academics ))
240
+ academics )
241
+ )
222
242
return redirect (url_for ('addinfo' ))
223
243
elif sports is None or int (sports ) > 100 :
224
244
flash (
225
- '%s is not a valid score.\
245
+ 'Notification : %s is not a valid score.\
226
246
Please enter valid score for Sports' % (
227
- sports ))
247
+ sports )
248
+ )
228
249
return redirect (url_for ('addinfo' ))
229
250
elif social is None or int (social ) > 100 :
230
251
flash (
231
- '%s is not a valid score.\
252
+ 'Notification : %s is not a valid score.\
232
253
Please enter valid score for Social' % (
233
- social ))
254
+ social )
255
+ )
234
256
return redirect (url_for ('addinfo' ))
235
257
else :
236
258
data = write_cache (
237
259
student_name , academics , sports , social
238
260
)
239
261
session ['data' ] = data
240
262
flash (
241
- 'Successfully Added new Records with ID %s \
242
- for Student Name %s' % (ids , student_name )
263
+ 'Notification : %s successfully added to records \
264
+ with ID %s' % (
265
+ student_name , ids
266
+ )
243
267
)
244
268
return redirect (url_for ('home' ))
245
269
return render_template ('forms/register.html' , form = form , ids = ids )
@@ -256,8 +280,9 @@ def search():
256
280
records = cache_records ()
257
281
except Exception :
258
282
flash (
259
- 'No such file Present,\
260
- please provide a vailid file or shutdown to create file' )
283
+ 'Notification : No such file present.\
284
+ Please provide a valid file or shutdown to create file'
285
+ )
261
286
return redirect (url_for ('home' ))
262
287
try :
263
288
match = filter (
@@ -267,7 +292,7 @@ def search():
267
292
if i ['ids' ] == int (search ):
268
293
count [int (search )] = count [int (search )] + 1
269
294
except Exception :
270
- flash ('Invalid ID Provided , Please Provide ID' )
295
+ flash ('Notification : Invalid ID provided , Please provide ID' )
271
296
return redirect (url_for ('home' ))
272
297
return render_template (
273
298
'pages/placeholder.search.html' , match = match , search = search
0 commit comments