Skip to content

Commit 66d4c5e

Browse files
authored
Merge pull request #31 from hriks/file
fix notification messages
2 parents 2ec6f0a + 1093ab3 commit 66d4c5e

File tree

4 files changed

+65
-33
lines changed

4 files changed

+65
-33
lines changed

app.py

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,37 @@ def shutdown():
2727
write()
2828
session.clear()
2929
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+
)
3142
return render_template('layouts/shutdown.html')
3243

3344

3445
# Controllers.
35-
36-
3746
def write():
3847
try:
3948
records = cache_records()
4049
for i in records:
4150
print i
4251
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+
)
4557
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+
]
4761
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
4862

4963
writer.writeheader()
@@ -69,9 +83,10 @@ def read_cache():
6983

7084
def write_cache(student_name, academics, sports, social):
7185
data = cache_records()
72-
if len(data) >= 20:
86+
if len(data) > 20:
7387
count = session['count']
74-
delete_cache(count)
88+
print count
89+
data = delete_cache(count)
7590
new_dict = {}
7691
new_dict['ids'] = ids_get()
7792
new_dict['student_name'] = student_name
@@ -129,12 +144,10 @@ def delete():
129144
session['ids'] = request.form['submit']
130145
session['delete'] = request.form['delete']
131146
ids = session['ids']
132-
data = delete_cache(
133-
session['ids']
134-
)
147+
data = delete_cache(ids)
135148
session['data'] = data
136149
flash(
137-
'Successfully Deleted ID %s' % (ids)
150+
'Notification : Successfully deleted records with ID %s' % (ids)
138151
)
139152
session['ids'] = None
140153
session['student_name'] = None
@@ -166,19 +179,19 @@ def update():
166179
social = form.social.data
167180
if academics is None or int(academics) > 100:
168181
flash(
169-
'%s is not a valid score.\
182+
'Notification : %s is not a valid score.\
170183
Please enter valid score for Academics' % (
171184
academics))
172185
return redirect(url_for('update'))
173186
elif sports is None or int(sports) > 100:
174187
flash(
175-
'%s is not a valid score.\
188+
'Notification : %s is not a valid score.\
176189
Please enter valid score for Sports' % (
177190
sports))
178191
return redirect(url_for('update'))
179192
elif social is None or int(social) > 100:
180193
flash(
181-
'%s is not a valid score.\
194+
'Notification : %s is not a valid score.\
182195
Please enter valid score for Social' % (
183196
social))
184197
return redirect(url_for('update'))
@@ -189,7 +202,7 @@ def update():
189202
)
190203
session['data'] = data
191204
flash(
192-
'Successfully Updated %s \
205+
'Notification : Successfully updated record for %s \
193206
with ID %s' % (name, ids)
194207
)
195208
return redirect(url_for('home'))
@@ -203,7 +216,10 @@ def addinfo():
203216
try:
204217
ids = ids_get()
205218
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+
)
207223
return redirect(url_for('home'))
208224
form = add_student(request.form)
209225
if request.method == 'POST':
@@ -212,34 +228,42 @@ def addinfo():
212228
sports = form.sports.data
213229
social = form.social.data
214230
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+
)
216235
return redirect(url_for('addinfo'))
217236
elif academics is None or int(academics) > 100:
218237
flash(
219-
'%s is not a valid score.\
238+
'Notification : %s is not a valid score.\
220239
Please enter valid score for Academics' % (
221-
academics))
240+
academics)
241+
)
222242
return redirect(url_for('addinfo'))
223243
elif sports is None or int(sports) > 100:
224244
flash(
225-
'%s is not a valid score.\
245+
'Notification : %s is not a valid score.\
226246
Please enter valid score for Sports' % (
227-
sports))
247+
sports)
248+
)
228249
return redirect(url_for('addinfo'))
229250
elif social is None or int(social) > 100:
230251
flash(
231-
'%s is not a valid score.\
252+
'Notification : %s is not a valid score.\
232253
Please enter valid score for Social' % (
233-
social))
254+
social)
255+
)
234256
return redirect(url_for('addinfo'))
235257
else:
236258
data = write_cache(
237259
student_name, academics, sports, social
238260
)
239261
session['data'] = data
240262
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+
)
243267
)
244268
return redirect(url_for('home'))
245269
return render_template('forms/register.html', form=form, ids=ids)
@@ -256,8 +280,9 @@ def search():
256280
records = cache_records()
257281
except Exception:
258282
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+
)
261286
return redirect(url_for('home'))
262287
try:
263288
match = filter(
@@ -267,7 +292,7 @@ def search():
267292
if i['ids'] == int(search):
268293
count[int(search)] = count[int(search)] + 1
269294
except Exception:
270-
flash('Invalid ID Provided, Please Provide ID')
295+
flash('Notification : Invalid ID provided, Please provide ID')
271296
return redirect(url_for('home'))
272297
return render_template(
273298
'pages/placeholder.search.html', match=match, search=search

templates/errors/404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
{% block content %}
33
<h1>Sorry ...</h1>
44
<p>There's nothing here!</p>
5-
<p><a href="{{url_for('index')}}">Back</a></p>
5+
<p><a href="{{url_for('home')}}">Back</a></p>
66
{% endblock %}

templates/errors/500.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
{% block content %}
33
<h1>Something's wrong!</h1>
44
<p>Fortunately we are on the job, and you can just return home!</p>
5-
<p><a href="{{url_for('index')}}">Back</a></p>
5+
<p><a href="{{url_for('home')}}">Back</a></p>
66
{% endblock %}

templates/layouts/shutdown.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,16 @@
7373
{% for message in messages %}
7474
<div class="alert alert-warning fade in">
7575
<a class="close" data-dismiss="alert">&times;</a>
76-
<b>Please wait.....Saving Records</b>
77-
<b>Application Shutdown, Now you can close Browser</b>
76+
{% if message %}
77+
{{message}}</br>
78+
<b>Please wait.....</b></br>
79+
<b>Shutting Down</br>
80+
Now you can close Browser</b>
7881
</div>
82+
{% else %}
83+
<b>Please wait.....Saving Records</b>
84+
<b>Application shutdown, Now you can close browser</b>
85+
{% endif %}
7986
{% endfor %}
8087
{% endif %}
8188
{% endwith %}

0 commit comments

Comments
 (0)