from flask import Blueprint, flash, redirect, render_template, request, url_for
from wtforms.fields.html5 import DecimalRangeField
from bson.objectid import ObjectId

from app import logger
from app.mod_budget.form import AddEntryForm, EditBudgetForm
from app.mod_budget.model import Category, CategoryBudget, Expense, Income
from app.mod_auth.helper import requireAuth

budget = Blueprint('budget', __name__, template_folder = 'templates')

@budget.route('/')
@requireAuth()
def default():
    return "Hello World!"

@budget.route('/income/add', methods = ['GET', 'POST'])
@requireAuth()
def addIncome():
    form = AddEntryForm(request.form)
    # Load the categories from the DB into the SelectField
    form.loadCategories()

    if request.method == 'POST' and form.validate():
        income = Income()
        form.populate_obj(income)

        # Insert category into the ReferenceField.
        income.category = Category.objects(id = ObjectId(income.category)).first()
        income.save()

        flash('Your income has been added.')
        return redirect(url_for('budget.default'))
    return render_template('budget/income/add.html', form = form)

@budget.route('/edit', methods = ['GET', 'POST'])
@requireAuth()
def editBudget():

@@ -1174,19 +1174,26 @@
 oute('/e
-dit
+xpense/add
 ', metho
@@ -1237,18 +1237,582 @@
 def 
-editBudget():
+addExpense():%0A    form = AddEntryForm(request.form)%0A    # Load the categories from the DB into the SelectField%0A    form.loadCategories()%0A%0A    if request.method == 'POST' and form.validate():%0A        expense = Expense()%0A        form.populate_obj(expense)%0A%0A        # Insert category into the ReferenceField.%0A        expense.category = Category.objects(id = ObjectId(expense.category)).first()%0A        expense.save()%0A%0A        flash('Your income has been added.')%0A        return redirect(url_for('budget.default'))%0A    return render_template('budget/expense/add.html', form = form)
 %0A

Add addExpense function