def edit_category(category_id): db_session = create_session() categories_dao = CategoryDAO(db_session) category = categories_dao.find_by_id_and_user_id(category_id, session["id"]) db_session.close() return render_template("categories/edit.html", category=category)
def list_categories(): db_session = create_session() categories_dao = CategoryDAO(db_session) categories = categories_dao.find_by_user_id(session["id"]) db_session.close() return render_template("categories/index.html", categories=categories)
def edit_transaction(transaction_id): db_session = create_session() category_dao = CategoryDAO(db_session) categories = category_dao.find_by_user_id(session["id"]) account_dao = AccountDAO(db_session) accounts = account_dao.find_by_user_id(session["id"]) transaction_dao = TransactionDAO(db_session) transaction = transaction_dao.find_by_id_and_user_id( transaction_id=transaction_id, user_id=session["id"] ) destination_accnt_id = None linked_transaction_id = None if transaction.link_id is not None: linked_transaction = transaction_dao.find_linked_transaction( link_id=transaction.link_id, user_id=session["id"], transaction_id=transaction.id ) destination_accnt_id = linked_transaction.source_accnt_id linked_transaction_id = linked_transaction.id db_session.close() return render_template( "transactions/edit.html", categories=categories, accounts=accounts, category_id=transaction.category_id, date=transaction.date, description=transaction.description, destination_accnt_id=destination_accnt_id, id=transaction.id, source_accnt_id=transaction.source_accnt_id, value=transaction.value, link_id=linked_transaction_id )
def list_transactions(): db_session = create_session() transaction_dao = TransactionDAO(db_session) all_transactions = transaction_dao.find_by_user_id(user_id=session["id"]) category_dao = CategoryDAO(db_session) categories = category_dao.find_by_user_id(session["id"]) account_dao = AccountDAO(db_session) accounts = account_dao.find_by_user_id(session["id"]) db_session.close() return render_template("transactions/index.html", transactions=all_transactions, categories=categories, accounts=accounts)
def validate_categories(db_session, *category_ids, user_id): category_dao = CategoryDAO(db_session) for category_id in category_ids: if category_id is None or int(category_id) == -1: continue category = category_dao.find_by_id_and_user_id( category_id=category_id, user_id=user_id ) if category is None: return False return True
def new_transaction(): db_session = create_session() category_dao = CategoryDAO(db_session) categories = category_dao.find_by_user_id(session["id"]) account_dao = AccountDAO(db_session) accounts = account_dao.find_by_user_id(session["id"]) db_session.close() return render_template( "transactions/edit.html", categories=categories, date=datetime.now(), destination_accnt_id=None, accounts=accounts )
def save_category(): db_session = create_session() categories_dao = CategoryDAO(db_session) category_id = request.form["id"] if category_id == "": category_id = None categories_dao.save( category_id=category_id, name=request.form["name"], user_id=session["id"], ) db_session.commit() db_session.close() return redirect(url_for("list_categories"))