Skip to content

Commit

Permalink
GIRL LOOK AT DAT DATA
Browse files Browse the repository at this point in the history
  • Loading branch information
sara committed Nov 20, 2017
1 parent 66c0895 commit 4162450
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 42 deletions.
30 changes: 18 additions & 12 deletions app/templates/results.html
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>
45 changes: 15 additions & 30 deletions app/views.py
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"


0 comments on commit 4162450

Please sign in to comment.