-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
<DOCTYPE html> | ||
|
||
<table> | ||
<table border = "1"> | ||
<tr> | ||
<th> Student ID </th> | ||
<th> Student Name </th> | ||
<th> Gender </th> | ||
<th> Grad Year </th> | ||
</tr> | ||
{% for result in results %} | ||
<tr> | ||
{% for field in result %} | ||
<td> {{ field }} </td> | ||
{% endfor %} | ||
<!--<td> {{ result [1] }} </td> | ||
<td> {{ result[2] }} </td> | ||
<td> {{ result [3] }} </td>--> | ||
</tr> | ||
{% endfor %} | ||
{% for student in students %} | ||
<tr> | ||
<td> | ||
{{ student['studentid'] }} | ||
</td> | ||
<td> | ||
{{ student['name'] }} | ||
</td> | ||
<td> | ||
{{ student['gradyear'] }} | ||
</td> | ||
<td> | ||
{{ student['gender'] }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tr> | ||
<table> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,29 @@ | ||
from flask import request, render_template, redirect, url_for | ||
from app import app, engine | ||
from app import app | ||
from forms import SearchForm | ||
from sqlalchemy import inspect | ||
from models import session | ||
from collections import namedtuple | ||
|
||
@app.route('/', methods=['GET', 'POST']) | ||
def landing(): | ||
form = SearchForm(request.form) | ||
con = engine.connect() | ||
if request.method == 'POST' and form.validate(): | ||
if form.data['studentid']: | ||
return get_student(form.data['studentid'], con) | ||
return redirect(url_for('get_student', name=form.data['studentid'])) | ||
else: | ||
return render_template('land.html', form=form) | ||
|
||
def get_student(name, con): | ||
result = con.execute("select * from students where name=%s", (name)).fetchall() | ||
result_dict = dict((col, getattr(studentid, name, gender, gradyear)) for col in result[0] | ||
if len(result_dict) != 0: | ||
return redirect(url_for('index', query=result)) | ||
else: | ||
return redirect(url_for('land')) | ||
|
||
|
||
@app.route('/results/<query>', methods=['GET', 'POST']) | ||
def index(query): | ||
return render_template('results.html', results=query) | ||
|
||
@app.route('/results/<name>', methods=['GET', 'POST']) | ||
def get_student(name): | ||
result = session.execute("select * from students where name=:val",{'val': name}) | ||
Student = namedtuple('Student', result.keys()) | ||
students = [Student(*r) for r in result.fetchall()] | ||
students = [student.__dict__ for student in students] | ||
if len(students) != 0: | ||
return render_template('results.html', students=students) | ||
return redirect (url_for('land')) | ||
|
||
@app.route('/create', methods=['GET', 'POST']) | ||
def land(): | ||
return render_template('create.html') | ||
# if any(i.isdigit() for i in s): | ||
# if (select * from students where studentid = student_identifier) != None: | ||
# return student_identifier | ||
# else: | ||
# return 'error' | ||
# elif any(i.isalpha() for i in student_identifier) = False: | ||
# if (select * from students where name=student_identifier) != None: | ||
# return student_identifier | ||
# else: | ||
# return student_identifier | ||
# else: | ||
# return "error, you put the string in wrong" | ||
|
||
|