Skip to content

Commit 8ab6886

Browse files
authored
Merge pull request #37 from hriks/fixes
Able to Create file if file not present with shutting down
2 parents 4b1c3d0 + 35ffadc commit 8ab6886

File tree

2 files changed

+61
-15
lines changed

2 files changed

+61
-15
lines changed

app.py

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ def shutdown():
4545
return render('layouts/shutdown.html')
4646

4747

48+
@app.route('/create', methods=['POST'])
49+
def create():
50+
with open(sys.argv[1], 'w+') as csvfile:
51+
fieldnames = [
52+
'ids', 'student_name', 'academics', 'sports', 'social'
53+
]
54+
writer = csv.DictWriter(
55+
csvfile, fieldnames=fieldnames
56+
)
57+
58+
writer.writeheader()
59+
s['swipe'] = 1
60+
print s['swipe']
61+
hriks(
62+
'Notification : New file created with name "%s" ' % (
63+
sys.argv[1]
64+
)
65+
)
66+
return redirect(url_for('home'))
67+
68+
4869
# Controllers.
4970
def write():
5071
try:
@@ -153,7 +174,19 @@ def cache_records():
153174

154175
@app.route('/', methods=['GET', 'POST'])
155176
def home():
156-
return render('pages/placeholder.home.html')
177+
try:
178+
input_file = csv.DictReader(open(sys.argv[1]))
179+
except Exception:
180+
input_file = None
181+
file = sys.argv[1]
182+
print input_file
183+
if input_file:
184+
swipe = 1
185+
s['swipe'] = swipe
186+
else:
187+
swipe = 0
188+
s['swipe'] = swipe
189+
return render('pages/placeholder.home.html', filename=file, swipe=swipe)
157190

158191

159192
@app.route('/delete', methods=['GET', 'POST'])
@@ -279,27 +312,21 @@ def addinfo():
279312
student_name, academics, sports, social
280313
)
281314
s['data'] = data
282-
if 'delete_id' in s:
283-
hriks(
284-
'Notification : %s successfully added to records \
285-
with ID %s and deleted ID %s due to minimum access' % (
286-
student_name, ids, s['delete_id']
287-
)
288-
)
289-
else:
290-
hriks(
291-
'Notification : %s successfully added to records \
292-
with ID %s' % (
293-
student_name, ids
294-
)
315+
hriks(
316+
'Notification : %s successfully added to records \
317+
with ID %s' % (
318+
student_name, ids
295319
)
320+
)
296321
s.pop('delete_id', None)
297322
return redirect(url_for('home'))
298323
return render('forms/register.html', form=form, ids=ids)
299324

300325

301326
@app.route('/search', methods=['GET', 'POST'])
302327
def search():
328+
if 'swipe' in s:
329+
swipe = s['swipe']
303330
if 'p' not in s:
304331
s['count'] = count_dict
305332
print s['count']
@@ -333,7 +360,8 @@ def search():
333360
hriks('Notification : Invalid ID provided, Please provide ID')
334361
return redirect(url_for('home'))
335362
return render(
336-
'pages/placeholder.search.html', match=match, search=search
363+
'pages/placeholder.search.html', match=match, search=search,
364+
swipe=swipe
337365
)
338366
return render('pages/placeholder.search.html', search=search)
339367

templates/layouts/main.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
{% endfor %}
123123
{% endif %}
124124
{% endwith %}
125+
{% if swipe == 1 %}
125126
<div class="alert alert-block alert-error fade in" style="background-color: lightgreen">
126127
<a class="close" data-dismiss="alert">&times;</a>
127128
<p style="text-align: center; color: red">
@@ -137,6 +138,23 @@
137138
</b>
138139
</form>
139140
</div>
141+
{% else %}
142+
<div class="alert alert-block alert-error fade in" style="background-color: lightgreen">
143+
<a class="close" data-dismiss="alert">&times;</a>
144+
<p style="text-align: center; color: red">
145+
<b>No File Found!</b>
146+
</p>
147+
<form action="create" method= POST>
148+
<b>
149+
<a>
150+
<button name="submit" class ="button" type="submit" style="width: 100%">
151+
Create {{ filename }}
152+
</button>
153+
</a>
154+
</b>
155+
</form>
156+
</div>
157+
{% endif %}
140158
<div style="text-align: right;">
141159
<form action="search" method="post" class="form">
142160
<input type="text" name="search" placeholder="Enter ID....">

0 commit comments

Comments
 (0)