Ejemplo n.º 1
0
def add_income(request):
    dbsession = DBSession()
    if 'amount' and 'name' in request.POST:
        amount = request.POST['amount']
        name = request.POST['name']
        income = Income(name, float(amount))
        dbsession.add(income)
        return HTTPFound(location=route_url('settings', request))

    return {'error': 'Please enter income name and amount.'}
Ejemplo n.º 2
0
def add_income(request):
    dbsession = DBSession()
    if 'amount' and 'name' in request.POST:
        amount = request.POST['amount']
        name = request.POST['name']
        income = Income(name, float(amount))
        dbsession.add(income)
        return HTTPFound(location=route_url('settings', request))

    return {'error':'Please enter income name and amount.'}
Ejemplo n.º 3
0
def add_periodic_expense(request):
    dbsession = DBSession()
    if 'amount' and 'name' in request.POST:
        amount = request.POST['amount']
        name = request.POST['name']
        expense = PeriodicExpense(name, float(amount))
        dbsession.add(expense)
        return HTTPFound(location=route_url('settings', request))

    return {'error':'Please enter periodic expence name and amount.'}
Ejemplo n.º 4
0
def add_periodic_expense(request):
    dbsession = DBSession()
    if 'amount' and 'name' in request.POST:
        amount = request.POST['amount']
        name = request.POST['name']
        expense = PeriodicExpense(name, float(amount))
        dbsession.add(expense)
        return HTTPFound(location=route_url('settings', request))

    return {'error': 'Please enter periodic expence name and amount.'}
Ejemplo n.º 5
0
def add_period(request):
    dbsession = DBSession()
    if 'period' in request.POST:
        period_name = request.POST['period']
        today = datetime.date.today()
        month = datetime.timedelta(days=30)
        period = Period(period_name, today, today + month)
        dbsession.add(period)
        return HTTPFound(location=route_url('settings', request))

    return {'error': 'Please enter period name.'}
Ejemplo n.º 6
0
def add_period(request):
    dbsession = DBSession()
    if 'period' in request.POST:
        period_name = request.POST['period']
        today = datetime.date.today()
        month = datetime.timedelta(days=30)
        period = Period(period_name, today, today+month)
        dbsession.add(period)
        return HTTPFound(location=route_url('settings', request))

    return {'error':'Please enter period name.'}
Ejemplo n.º 7
0
def settings_view(request):
    if not request.session.get('admin'):
        return HTTPFound(location=route_url('home', request))
    dbsession = DBSession()
    periods = dbsession.query(Period).all()
    #TODO In future we will implement possibility to choose in which period we are.
    if periods:
        period = periods[0]  # Current period
        expenses = dbsession.query(PeriodicExpense).filter(
            PeriodicExpense.period_id == period.id).all()
        incomes = dbsession.query(Income).filter(
            Income.period_id == period.id).all()

        return {'periods': periods, 'expenses': expenses, 'incomes': incomes}
    return {'periods': periods}
Ejemplo n.º 8
0
def add_spending(request):
    dbsession = DBSession()
    if 'amount' and 'name' in request.POST:
        amount = request.POST['amount']
        name = request.POST['name']

        #TODO Add amount validation.

        expense = Expense(name, float(amount))
        dbsession.add(expense)

        q = {'period': 1}
        return HTTPFound(location=route_url('spend', request, _query=q))

    return {'error': 'Please enter spending name and spended amount.'}
Ejemplo n.º 9
0
def settings_view(request):
    if not request.session.get('admin'):
        return HTTPFound(location=route_url('home', request))
    dbsession = DBSession()
    periods = dbsession.query(Period).all()
    #TODO In future we will implement possibility to choose in which period we are.
    if periods:
        period = periods[0] # Current period
        expenses = dbsession.query(PeriodicExpense).filter(PeriodicExpense.period_id == period.id).all()
        incomes = dbsession.query(Income).filter(Income.period_id == period.id).all()

        return {'periods': periods,
                'expenses': expenses,
                'incomes': incomes}
    return {'periods': periods}
Ejemplo n.º 10
0
def add_spending(request):
    dbsession = DBSession()
    if 'amount' and 'name' in request.POST:
        amount = request.POST['amount']
        name = request.POST['name']

        #TODO Add amount validation.

        expense = Expense(name, float(amount))
        dbsession.add(expense)

        q = {'period': 1}
        return HTTPFound(location=route_url('spend', request, _query=q))

    return {'error':'Please enter spending name and spended amount.'}
Ejemplo n.º 11
0
def spend_view(request):
    if not request.session.get('admin'):
        return HTTPFound(location=route_url('home', request))
    today = datetime.date.today()
    period_id = request.GET.get('period', None)
    if period_id:
        dbsession = DBSession()
        expenses = dbsession.query(Expense).\
            filter(Expense.period_id==int(period_id)).\
            filter(Expense.date==today).all()

        period = Period.get_by_id(period_id)
        expenses_sum = period.get_expenses(today)
        return {'expenses': expenses, 'expenses_sum': expenses_sum}

    return HTTPFound(location=route_url('app', request))
Ejemplo n.º 12
0
def spend_view(request):
    if not request.session.get('admin'):
        return HTTPFound(location=route_url('home', request))
    today = datetime.date.today()
    period_id = request.GET.get('period', None)
    if period_id:
        dbsession = DBSession()
        expenses = dbsession.query(Expense).\
            filter(Expense.period_id==int(period_id)).\
            filter(Expense.date==today).all()

        period = Period.get_by_id(period_id)
        expenses_sum = period.get_expenses(today)
        return {'expenses': expenses,
                'expenses_sum': expenses_sum}

    return HTTPFound(location=route_url('app', request))
Ejemplo n.º 13
0
def populate():
    session = DBSession()
    day = datetime.timedelta(days=1)
    month = datetime.timedelta(days=30)
    today = datetime.date.today()
    tomorrow = today + day

    default = Period('Default', today, today + month)
    session.add(default)

    #Default expences
    apartment = PeriodicExpense('Apartment rent', 300.00)
    session.add(apartment)

    #Incomes
    salary = Income('Salary', 1000.00)
    session.add(salary)

    session.flush()
    transaction.commit()
Ejemplo n.º 14
0
def app_view(request):
    if not request.session.get('admin'):
        return HTTPFound(location=route_url('home', request))
    today = datetime.date.today()
    dbsession = DBSession()
    period = dbsession.query(Period).first()
    if not period:
        return HTTPFound(location=route_url('settings', request))

    to_spend = period.to_spend(today)
    spent_today = period.get_expenses(today)
    left_today = period.to_spend(today) - spent_today
    money_left = period.money_left()
    days_left = (period.end-datetime.datetime.utcnow()).days

    return {'period': period,
            'left_today': left_today,
            'spent_today': spent_today,
            'money_left': money_left,
            'to_spend': to_spend,
            'days_left': days_left}
Ejemplo n.º 15
0
def app_view(request):
    if not request.session.get('admin'):
        return HTTPFound(location=route_url('home', request))
    today = datetime.date.today()
    dbsession = DBSession()
    period = dbsession.query(Period).first()
    if not period:
        return HTTPFound(location=route_url('settings', request))

    to_spend = period.to_spend(today)
    spent_today = period.get_expenses(today)
    left_today = period.to_spend(today) - spent_today
    money_left = period.money_left()
    days_left = (period.end - datetime.datetime.utcnow()).days

    return {
        'period': period,
        'left_today': left_today,
        'spent_today': spent_today,
        'money_left': money_left,
        'to_spend': to_spend,
        'days_left': days_left
    }
Ejemplo n.º 16
0
def populate():
    session = DBSession()
    day = datetime.timedelta(days=1)
    month = datetime.timedelta(days=30)
    today = datetime.date.today()
    tomorrow = today+day

    default = Period('Default', today, today+month)
    session.add(default)

    #Default expences
    apartment = PeriodicExpense('Apartment rent', 300.00)
    session.add(apartment)

    #Incomes
    salary = Income('Salary', 1000.00)
    session.add(salary)

    session.flush()
    transaction.commit()
Ejemplo n.º 17
0
def setup_app(command, conf, vars):
    engine = engine_from_config(conf, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)
    populate()
Ejemplo n.º 18
0
def setup_app(command, conf, vars):
    engine = engine_from_config(conf, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)
    populate()