igdb/code/database/queries.py

22 lines
601 B
Python
Raw Normal View History

2020-01-09 21:10:27 +01:00
from app.models import Glacier, Annual_Data, User
from app import db
def query_annual_data(form):
annual_data = db.session.query(Annual_Data).filter_by(year=form.year.data)
query = annual_data
if form.name.data:
query = (
db.session.query(Annual_Data)
.filter_by(year=form.year.data)
.join(Glacier, Glacier.id == Annual_Data.id)
.filter_by(name=form.name.data)
.group_by(Glacier.id)
)
return query
def query_user(form):
user = User.query.filter_by(username=form.username.data).first()
return user