def fecharaula(id_aula=None): # if id_aula==None: s = tables.Aula.__table__.update().where(tables.Aula.id==id_aula).values(ativa=0) conn = engine.connect() conn.execute(s) return redirect(url_for('lista', id_aula=id_aula))
def rent(): if request.method == 'POST': friends_id = request.form.getlist('friend') location_id = request.form.get('locs') date = request.form.get('date') # celebration number_of_friends = len(friends_id) celebration_type = "date" if number_of_friends == 1 else "party" conn.execute( 'insert into "celebration" values (default, \'{}\', {}, default);'. format(celebration_type, number_of_friends)) celebration_id = list( conn.execute('select max(id) from "celebration"'))[0][0] # order conn.execute( 'insert into "orders" values (default, {}, {}, \'{}\', {});'. format(storage["id"], location_id, date, celebration_id)) order_id = list(conn.execute('select max(id) from "orders"'))[0][0] # payment conn.execute( 'insert into "payment" values (default, {}, {}, false);'.format( order_id, number_of_friends * 50)) # order_friends for friend_id in friends_id: conn.execute( 'insert into "order_friends" values (default, {}, {});'.format( order_id, friend_id)) return redirect(url_for('home_page')) return redirect(url_for("rent_page"))
def login(): if request.method == 'POST': sql_str = "SELECT Username, Email FROM UserTable WHERE Email='" + request.form[ 'email'] + "';" req_email = conn.execute(sql_str).fetchall() hashed_pass = hashlib.sha256(request.form['password'] + "SALT").hexdigest() sql_str = "SELECT Password FROM UserTable WHERE Password='******';" req_pass = conn.execute(sql_str).fetchall() valid = False if len(req_email) == 1 and len(req_pass) == 1: if str(req_email[0][1]) == request.form['email']: if str(req_pass[0][0]) == hashed_pass: valid = True if valid == True: session['CURR_USER'] = req_email[0][0] session['LOGGED_IN'] = 'YES' return redirect(url_for('success')) else: return render_template("login.html", error=True, logged_in=session['LOGGED_IN']) # return the user login page on a GET request return render_template("login.html", error=False, logged_in=session['LOGGED_IN'])
def register(): form = CadForm() if form.validate_on_submit(): if form.password.data == form.re_password.data: s = select([User]).where(or_(User.username==form.username.data, User.email==form.email.data)).limit(1) result = conn.execute(s) is_unique = True for row in result: is_unique = False break if not is_unique: flash("This is user is already registered.") else: stmt = insert(User).values(username=form.username.data, email=form.email.data, password=form.password.data, name=form.username.data) conn.execute(stmt) flash("Successfully registered! Please log in, now.") return redirect(url_for('login')) else: flash("The password don't match.") return render_template('register.html', form=form)
def return_gift(): if request.method == 'POST': gift_id = request.form.get('gifts') conn.execute( 'update present set returned=true where id={};'.format(gift_id)) return redirect(url_for('home_page')) return redirect(url_for("return_page"))
def update_games(timestamp, p1_id, p2_id, p1_score, p2_score): df = pd.read_sql(sql='SELECT * FROM game_log;', con=conn, parse_dates=['created_at']) try: p1_id = int(p1_id) p2_id = int(p2_id) p1_score = int(p1_score) p2_score = int(p2_score) except TypeError: pass else: if p1_score >= p2_score: winner_id = p1_id winner_score = p1_score looser_id = p2_id looser_score = p2_score else: winner_id = p2_id winner_score = p2_score looser_id = p1_id looser_score = p1_score utc_stamp = str(datetime.utcfromtimestamp(int(timestamp / 1000))) conn.execute("INSERT INTO game_log "\ "(winner_id, winner_score, looser_id, looser_score, created_at) "\ "VALUES({}, {}, {}, {}, '{}');".format(winner_id, winner_score, looser_id, looser_score, utc_stamp)) finally: kfactor_list = pd.read_sql(sql='SELECT * FROM kfactor;', con=conn)['value'].tolist() kfactor = kfactor_list.pop() init_player_df = pd.read_sql(sql='SELECT * FROM player_ids;', con=conn) init_game_log_df = pd.read_sql(sql='SELECT * FROM game_log;', con=conn, parse_dates=['created_at']) elo_score_df = elo_score.make_elo_scores_df(init_game_log_df, init_player_df, K=kfactor) player_dict = init_player_df.set_index("player_id").to_dict('index') figure = go.Figure(data=[ go.Scatter(x=elo_score_df.index, y=elo_score_df[i], name=player_dict[i]['player_name']) for i in list(elo_score_df) ], layout=go.Layout(hovermode='closest')) return (figure)
def del_games(n_clicks): if n_clicks == 1: return ("Are you sure? If so click again") try: if n_clicks > 1: conn.execute("DELETE FROM game_log;") return ("Players Deleted!") except TypeError: return ("")
def dayoff(): if request.method == 'POST': date = request.form.get('date') message = request.form.get('message') conn.execute( 'insert into days_off values (default, {}, \'{}\', \'{}\');'. format(storage["id"], date, message)) return redirect(url_for('home_page')) return redirect(url_for("dayoff_page"))
def gift(): if request.method == 'POST': friend_id = request.form.get('friend') gift_name = request.form.get('gift') date = request.form.get('date') query = 'insert into "present" values (default, \'{}\', {}, \'{}\', false, \'{}\');'.format( gift_name, storage["id"], friend_id, date) conn.execute(query) return redirect(url_for('home_page')) return redirect(url_for("gift_page"))
def rent_page(): friends = list( conn.execute( 'select id, full_name, age, phone_number from "friend" where available=true' )) friends = list((x[0], " ".join(map(str, x[1:]))) for x in friends) locations = list(conn.execute('select * from "locations"')) locations = list( (x[0], x[2] + " - " + ", ".join(map(str, (x[1], ) + x[3:]))) for x in locations) return render_template('rent.html', friends=friends, locations=locations)
def deposit(): if request.method == 'POST': money = request.form.get('deposit') balance = list( conn.execute('select cash from {} where id={}'.format( storage["status"], storage["id"])))[0][0] balance = int(balance) + int(money) conn.execute('update {} set cash={} where id={};'.format( storage["status"], balance, storage["id"])) return redirect(url_for('home_page')) return redirect(url_for("deposit_page"))
def index(): form = PreForm() form.prof.choices = [(p.nome, p.nome) for p in tables.Professor.query.all()] if request.method == "POST" and form.validate_on_submit(): if form.id_uri.data: id_uri = form.id_uri.data query = select([tables.Aluno.id]).where(tables.Aluno.ID_URI == id_uri) elif form.email.data: email = form.email.data query = select([tables.Aluno.id]).where(tables.Aluno.email == email) else: flash('formulario vazio') return redirect(url_for('index')) conn = engine.connect() res = conn.execute(query).fetchone() if res: id_aluno = res['id'] query = select([tables.Aula.id]).where( and_( tables.Aula.id_prof == tables.Professor.id, and_( tables.Aula.ativa == 1, and_( tables.Professor.apelido == form.prof.data, tables.Aula.dia == date.today() )))) result = conn.execute(query).fetchone() if result: id_aula = result['id'] new_presenca = tables.Presenca(id_aula, id_aluno) db.session.add(new_presenca) flash("Sua presença foi marcada com sucesso!") try: db.session.commit() except exc.IntegrityError: db.session.rollback() flash("Voce ja tem presenca nessa aula") else: flash("O professor nao tem nenhuma aula aberta pro dia de hoje") else: flash("Dado nao cadastrado") else: if form.errors: flash(form.errors) return render_template('home/index.html', form=form)
def complaint_page(): query = """select friend.id, full_name from "friend" join order_friends on friend.id=friend_id join orders on order_id=orders.id where client_id={};""".format(storage["id"]) friends = list(conn.execute(query)) query = """select orders.id, locations.name, order_date from orders join locations on location_id=locations.id where client_id={};""".format(storage["id"]) orders = list(conn.execute(query)) orders = [(x[0], '{} {}'.format(x[1], x[2])) for x in orders] return render_template('complaint.html', friends=friends, orders=orders)
def withdraw(): if request.method == 'POST': money = request.form.get('withdraw') balance = list( conn.execute('select cash from {} where id={}'.format( storage["status"], storage["id"])))[0][0] if int(balance) >= int(money): balance = int(balance) - int(money) conn.execute('update {} set cash={} where id={};'.format( storage["status"], balance, storage["id"])) return redirect(url_for('home_page')) return redirect(url_for("withdraw_page"))
def profile(): storage["id"] = list( conn.execute('select max(id) from "{}"'.format( storage["status"])))[0][0] + 1 query = 'insert into "{}" values ({}, \'{}\', {}, \'{}\', 200, '.format( storage["status"], storage["id"], request.form.get('full_name'), request.form.get('age'), request.form.get('phone')) if storage["status"] == 'friend': query += 'true, ' query += '\'{}\', \'{}\');'.format(storage["username"], storage["password"]) conn.execute(query) return redirect(url_for('home_page'))
def get_percent_pub(ntop=20, nyears=15): PubTable = Table('pubs', metadata, autoload=True, autoload_with=engine) s = select([PubTable]) rp = conn.execute(s) affiliation_dict = {} affil_pubs = defaultdict(int) for rec in rp.fetchall(): affil_data = rec.data['abstracts-retrieval-response'].get('affiliation', []) if isinstance(affil_data, dict): if affil_data['affiliation-country'] == 'Thailand': affilname = affil_data.get('affilname', '') if affilname: affil_pubs[affilname] += 1 elif isinstance(affil_data, list): for affil in affil_data: if affil['affiliation-country'] == 'Thailand': affilname = affil.get('affilname', '') if affilname: affil_pubs[affilname] += 1 top_universities = sorted(affil_pubs.items(), key=lambda x: x[1], reverse=True)[:ntop] other_universities = sorted(affil_pubs.items(), key=lambda x: x[1], reverse=True)[ntop:] plot_data = {'data': [], 'labels': []} for item in top_universities: af, num = item plot_data['data'].append(affil_pubs[af]) plot_data['labels'].append(af) other_num = sum([num for af, num in other_universities]) plot_data['data'].append(other_num) plot_data['labels'].append('others') return jsonify(plot_data)
def songs(): sql_str = "SELECT * FROM Song;" all_songs = conn.execute(sql_str).fetchall() return render_template("songs.html", username=session['CURR_USER'], logged_in=session['LOGGED_IN'], song_list=all_songs)
def calculate_tdif(): year = int(request.args.get('year', 0)) PubTable = Table('pubs', metadata, autoload=True, autoload_with=engine) abstracts = [] bigram_set = defaultdict(int) s = select([PubTable]) for row in conn.execute(s): try: abstract = row.data['abstracts-retrieval-response']['coredata']['dc:description'] except KeyError: continue abstract = [token.lower() for token in regexp_tokenize(abstract, '[^\d\W\s]{3,}') if token.lower() not in stop_words] abstracts.append(' '.join(abstract)) if row.pub_date.year == year: for bg in nltk.ngrams(abstract, 2): bigram_set[' '.join(bg)] += 1 vectorizer = TfidfVectorizer(stop_words='english', ngram_range=(2, 2), analyzer='word', min_df=10, max_df=0.8) vectorizer.fit(abstracts) highlights = {} for k in bigram_set: highlights[k] = float(vectorizer.vocabulary_.get(k, 0)) plot_data = {'data': [], 'labels': []} for k, v in sorted(highlights.items(), key=lambda x: x[1], reverse=True)[:100]: plot_data['data'].append(v) plot_data['labels'].append(k) return jsonify(plot_data)
def get_wordcloud(): year = int(request.args.get('year')) PubTable = Table('pubs', metadata, autoload=True, autoload_with=engine) abstracts = [] s = select([PubTable]) for row in conn.execute(s): if row.pub_date.year == year: try: abstract = row.data['abstracts-retrieval-response']['coredata']['dc:description'] except KeyError: continue abstract = [token.lower() for token in regexp_tokenize(abstract, '[^\d\W\s]{3,}') if token.lower() not in stop_words] abstracts.append(' '.join(abstract)) img = BytesIO() wordcloud = WordCloud( background_color='white', stopwords=stop_words, max_words=200, max_font_size=40, random_state=42, width=800, height=400 ).generate(str(abstracts)) wordcloud.to_image().save(img, 'png') img.seek(0) return send_file(img, mimetype='image/png')
def bill_page(): bills = list( conn.execute("""select payment.id, total_sum from payment join orders on order_id = orders.id where client_id={} and payed=False""". format(storage["id"]))) return render_template('bill.html', bills=bills)
def consulta(): form = ConsultaAulas() if request.method == "POST" and form.validate_on_submit(): if form.id_uri.data: id_uri = form.id_uri.data query = select([tables.Aula.dia, tables.Aula.nivel, tables.Professor.apelido]).where( and_( tables.Aula.id == tables.Presenca.id_aula, and_(tables.Presenca.id_aluno==tables.Aluno.id, and_(tables.Aluno.ID_URI == id_uri, and_(tables.Aula.id_prof == tables.Professor.id, tables.Aula.ativa == 0 ) ) ) ) ) if form.email.data: email = form.email.data query = select([tables.Aula.dia, tables.Aula.nivel, tables.Professor.apelido]).where( and_( tables.Aula.id == tables.Presenca.id_aula, and_(tables.Presenca.id_aluno==tables.Aluno.id, and_(tables.Aluno.email == email, and_(tables.Aula.id_prof == tables.Professor.id, tables.Aula.ativa == 0 ) ) ) ) ) conn = engine.connect() result = conn.execute(query) return render_template('home/mostraAulas.html', aulas=result) else: return render_template('home/consultaAulas.html', form=form)
def get_active_scholarship_studs_author(duration=5, nyears=20): ScholarTable = Table('scholarship_info', kwmetadata, autoload=True, autoload_with=kwengine) s = select([ScholarTable.c.first_name_en, ScholarTable.c.last_name_en]) scholars = set() for rec in kwconn.execute(s): firstname, lastname = rec firstname = firstname.lower() \ .replace('mrs.', '') \ .replace('mr.', '') \ .replace('ms.', '') \ .replace('dr.', '') if firstname and lastname: scholars.add('{}.'.format(' '.join([lastname.lower(), firstname.lower()[0]]))) PubTable = Table('pubs', metadata, autoload=True, autoload_with=engine) s = select([PubTable]) year_scholar_authors = defaultdict(set) for rec in conn.execute(s): year = rec.pub_date.year authors = rec.data['abstracts-retrieval-response']['authors']['author'] if isinstance(authors, list): for author in authors: idxname = author['ce:indexed-name'].lower() if idxname in scholars: year_scholar_authors[year].add(idxname) else: idxname = authors['ce:indexed-name'].lower() if idxname in scholars: year_scholar_authors[year].add(idxname) sorted_years = sorted(year_scholar_authors, reverse=False)[2:nyears] start_year = sorted_years[0] last_year = sorted_years[-1] active_authors = [] inactive_authors = [] all_authors = set() for yr in sorted_years: if yr > last_year: active_author_set = year_scholar_authors[last_year] else: active_author_set = year_scholar_authors[yr] for y in range(yr, yr + duration): active_author_set.update(year_scholar_authors[y]) all_authors.update((year_scholar_authors[y])) active_authors.append(len(active_author_set)) inactive_authors.append(len(all_authors) - len(active_author_set)) plot_data = {'data': [], 'labels': sorted_years} plot_data['data'].append({ 'data': active_authors, 'label': 'Active Authors' }) plot_data['data'].append({ 'data': inactive_authors, 'label': 'Inactive Authors' }) return jsonify(plot_data)
def report(project_number=None): if project_number: sql = "select * from project where id =%s"% project_number else: sql = "select * from project where id in (select project_id from initiative_project where initiative_id=1)" result=conn.execute(sql) print result entries = [{"id" : row[0], "project_number" :row[3],"project_name":row[5],"url":row[4]} for row in result.fetchall()] return render_template('index.html', entries=entries)
def get_author_per_year(ntop=20, nyears=15): PubTable = Table('pubs', metadata, autoload=True, autoload_with=engine) s = select([PubTable]) rp = conn.execute(s) author_affiliation_years = defaultdict(dict) affiliation_dict = {} affiliation_pubs = defaultdict(int) for rec in rp.fetchall(): thai_affs = set() affil_data = rec.data['abstracts-retrieval-response'].get('affiliation', []) if isinstance(affil_data, dict): if affil_data['affiliation-country'] == 'Thailand': thai_affs.add(affil_data['@id']) affiliation_dict[affil_data['@id']] = affil_data['affilname'] affiliation_pubs[affil_data['@id']] += 1 elif isinstance(affil_data, list): for affil in affil_data: if affil['affiliation-country'] == 'Thailand': thai_affs.add(affil['@id']) affiliation_dict[affil['@id']] = affil['affilname'] affiliation_pubs[affil['@id']] += 1 authors = rec.data['abstracts-retrieval-response']['authors']['author'] year = rec.pub_date.year if year not in author_affiliation_years: author_affiliation_years[year] = defaultdict(dict) if isinstance(authors, list): for author in authors: if 'affiliation' in author: if isinstance(author['affiliation'], list): # multiple affiliations for affil in author['affiliation']: if affil['@id'] in thai_affs: if affil['@id'] in author_affiliation_years[year]: author_affiliation_years[year][affil['@id']].add(author['ce:indexed-name']) else: author_affiliation_years[year][affil['@id']] = set([author['ce:indexed-name']]) elif author['affiliation']['@id'] in thai_affs: if author['affiliation']['@id'] in author_affiliation_years[year]: author_affiliation_years[year][author['affiliation']['@id']].add(author['ce:indexed-name']) else: author_affiliation_years[year][author['affiliation']['@id']] = set( [author['ce:indexed-name']]) top_universities = [x[0] for x in sorted(affiliation_pubs.items(), key=lambda x: x[1], reverse=True)[:ntop]] sorted_years = sorted(author_affiliation_years.keys(), reverse=False)[-nyears:] plot_data = {'data': [], 'labels': sorted_years} for af in top_universities: item = {'label': affiliation_dict[af], 'data': []} for year in sorted_years: item['data'].append(len(author_affiliation_years[year][af])) plot_data['data'].append(item) return jsonify(plot_data)
def get_num_scholarship_studs(ntop=20, nyears=20): ScholarTable = Table('scholarship_info', kwmetadata, autoload=True, autoload_with=kwengine) s = select([ScholarTable.c.first_name_en, ScholarTable.c.last_name_en]) scholars = set() for rec in kwconn.execute(s): firstname, lastname = rec firstname = firstname.lower() \ .replace('mrs.', '') \ .replace('mr.', '') \ .replace('ms.', '') \ .replace('dr.', '') if firstname and lastname: scholars.add('{}.'.format(' '.join([lastname.lower(), firstname.lower()[0]]))) PubTable = Table('pubs', metadata, autoload=True, autoload_with=engine) s = select([PubTable]) year_scholar_authors = defaultdict(set) for rec in conn.execute(s): year = rec.pub_date.year authors = rec.data['abstracts-retrieval-response']['authors']['author'] if isinstance(authors, list): for author in authors: idxname = author['ce:indexed-name'].lower() if idxname in scholars: year_scholar_authors[year].add(idxname) else: idxname = authors['ce:indexed-name'].lower() if idxname in scholars: year_scholar_authors[year].add(idxname) sorted_years = sorted(year_scholar_authors, reverse=False)[:nyears] all_scholar_authors = set() old_scholars = defaultdict(set) new_scholars = defaultdict(set) for yr in sorted_years: old_scholars[yr] = year_scholar_authors[yr].intersection(all_scholar_authors) new_scholars[yr] = year_scholar_authors[yr].difference(all_scholar_authors) all_scholar_authors.update(year_scholar_authors[yr]) plot_data = {'data': [], 'labels': sorted_years} oldss = [] newss = [] for yr in sorted_years: oldss.append(len(old_scholars[yr])) newss.append(len(new_scholars[yr])) plot_data['data'].append({ 'data': oldss, 'label': 'Scholars' }) plot_data['data'].append({ 'data': newss, 'label': 'New Scholars' }) return jsonify(plot_data)
def song_edit(song_url): if request.method == 'POST': sql_str = "UPDATE Song SET Title='" + request.form['title'] + "', " + "Genre='" + request.form['genre'] + \ "', Track_type='" + request.form['track_type'] + "' WHERE Song_Url='" + song_url + "';" updated_song = conn.execute(sql_str) return render_template("edit.html", error='False') elif request.method == 'GET': sql_str = "SELECT * FROM Song WHERE Song_Url='" + song_url + "';" req_song = conn.execute(sql_str).fetchall() song_title = req_song[0][0] genre = req_song[0][4] track_type = req_song[0][5] return render_template("edit.html", username=session['CURR_USER'], logged_in=session['LOGGED_IN'], song_title=song_title, song_url=song_url, genre=genre, track_type=track_type)
def verAulas(id_professor = None): if current_user.is_admin: query = select([tables.Professor.nome, tables.Professor.apelido, tables.Professor.id, tables.Professor.ID_URI]) conn = engine.connect() result = conn.execute(query) return render_template('home/verAulas.html', professores = result) else: flash("A área que você tentou acessar é restrita.") return redirect(url_for("warning"))
def upload(): if request.method == 'POST': sql_str = "INSERT INTO Song(Title, Created_at, Soundcloud_Views, Song_Url, Genre, Track_type, Duration, " + \ "Soundcloud_Favorites) VALUES('" + request.form['title'] + "', 1234, 0, '" + request.form['song_url'] + \ "', '" + request.form['genre'] + "', '" + request.form['track_type'] + "', 8, 0);" new_song = conn.execute(sql_str) return redirect(url_for('songs')) return render_template("upload.html", username=session['CURR_USER'], logged_in=session['LOGGED_IN'])
def update_league_table(n_clicks, value): init_df = pd.read_sql(sql='SELECT * FROM player_ids;', con=conn) if value not in ["", None, "enter a new player" ] + init_df['player_name'].tolist(): conn.execute( "INSERT INTO player_ids (player_name) VALUES('{}');".format(value)) kfactor_list = pd.read_sql(sql='SELECT * FROM kfactor;', con=conn)['value'].tolist() kfactor = kfactor_list.pop() game_log_df = pd.read_sql(sql='SELECT * FROM game_log;', con=conn) player_df = pd.read_sql(sql='SELECT * FROM player_ids;', con=conn) elo_score_df = elo_score.make_elo_scores_df(game_log_df, player_df, K=kfactor) df = make_score_table(player_df, elo_score_df) return (df.to_dict("rows"))
def complaint(): if request.method == 'POST': friend_id = request.form.get('friends') order_id = request.form.get('orders') date = request.form.get('date') message = request.form.get('message') coincide = len( list( conn.execute( 'select * from order_friends where order_id={} and friend_id={}' .format(order_id, friend_id)))) if coincide: query = 'insert into complaints values (default, {}, {}, \'{}\', \'{}\');'.format( friend_id, order_id, date, message) conn.execute(query) return redirect(url_for('home_page')) return redirect(url_for("complaint_page"))
def get_active_scholarship_studs_author_graduate(duration=5, nyears=20): ScholarTable = Table('scholarship_info', kwmetadata, autoload=True, autoload_with=kwengine) s = select([ScholarTable.c.first_name_en, ScholarTable.c.last_name_en, ScholarTable.c.graduated_date]) scholars = {} for rec in kwconn.execute(s): firstname, lastname, graduate_date = rec firstname = firstname.lower() \ .replace('mrs.', '') \ .replace('mr.', '') \ .replace('ms.', '') \ .replace('dr.', '') if firstname and lastname: scholars['{}.'.format(' '.join( [lastname.lower(), firstname.lower()[0]]))] = graduate_date PubTable = Table('pubs', metadata, autoload=True, autoload_with=engine) s = select([PubTable]) scholar_authors = defaultdict(set) for rec in conn.execute(s): year = rec.pub_date.year authors = rec.data['abstracts-retrieval-response']['authors']['author'] if isinstance(authors, list): for author in authors: idxname = author['ce:indexed-name'].lower() if idxname in scholars: if author['@seq'] == '1': scholar_authors[idxname].add(year) else: idxname = authors['ce:indexed-name'].lower() if idxname in scholars: if author['@seq'] == '1': scholar_authors[idxname].add(year) time_after_graduate = defaultdict(int) for author in scholar_authors: graduate_date = scholars[author] if graduate_date: valid_pub_years = [i for i in scholar_authors[author] if i > graduate_date.year] if valid_pub_years: tag = min(valid_pub_years) - graduate_date.year time_after_graduate[tag] += 1 numyear = range(min(time_after_graduate.keys()), max(time_after_graduate.keys())+1) tagdata = [] for ny in numyear: tagdata.append(time_after_graduate[ny]) plot_data = {'data': [], 'labels': list(numyear)} plot_data['data'].append({ 'data': tagdata, 'label': 'Time after graduate' }) return jsonify(plot_data)
def detail(project_number): sql="select * from cida where project_number='{}'".format(project_number) print sql result =conn.execute(sql) details = [dict(row) for row in result.fetchall()] return render_template('detail.html', details=details)