40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
#! /usr/bin/env python3
|
|
from bottle import route, run, template
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from models import *
|
|
|
|
engine = create_engine("sqlite:///app.db")
|
|
Base = declarative_base()
|
|
|
|
Session = sessionmaker(bind=engine)
|
|
session = Session()
|
|
|
|
|
|
@route('/')
|
|
def index():
|
|
return template('index')
|
|
|
|
@route('/categories')
|
|
def categories():
|
|
categories = session.query(Category).all()
|
|
categories = [c for c in categories if c.is_child()]
|
|
return template('categories', categories=categories)
|
|
|
|
@route('/category/<name>')
|
|
def category(name):
|
|
c = session.query(Category).filter(Category.name==name).first()
|
|
if c:
|
|
transactions = session.query(Transaction).filter(Transaction.category_id==c.id).all()
|
|
else:
|
|
transactions = []
|
|
|
|
return template('category', category=c,transactions=transactions)
|
|
|
|
@route('/transactions')
|
|
def transactions():
|
|
transactions = session.query(Transaction).all()
|
|
return template('transactions', transactions=transactions)
|
|
|
|
run(host='localhost', port=8080, reloader=True)
|