Esempio n. 1
0
        return jsonify(res)


class FuelPriceChartView(MethodView):
    """
    Handle GET /ajax/chart-data/fuel-prices endpoint.
    """
    def get(self):
        resdata = []
        prices = db_session.query(FuelFill).filter(
            FuelFill.cost_per_gallon.__ne__(None)).order_by(asc(FuelFill.date))
        for point in prices.all():
            ds = point.date.strftime('%Y-%m-%d')
            resdata.append({'date': ds, 'price': float(point.cost_per_gallon)})
        res = {'data': resdata}
        return jsonify(res)


app.add_url_rule('/fuel', view_func=FuelView.as_view('fuel_view'))
app.add_url_rule('/ajax/fuelLog', view_func=FuelAjax.as_view('fuel_ajax'))
app.add_url_rule('/ajax/vehicle/<int:vehicle_id>',
                 view_func=VehicleAjax.as_view('vehicle_ajax'))
app.add_url_rule('/forms/vehicle',
                 view_func=VehicleFormHandler.as_view('vehicle_form'))
app.add_url_rule('/forms/fuel',
                 view_func=FuelLogFormHandler.as_view('fuel_form'))
app.add_url_rule('/ajax/chart-data/fuel-economy',
                 view_func=FuelMPGChartView.as_view('fuel_mpg_chart_view'))
app.add_url_rule('/ajax/chart-data/fuel-prices',
                 view_func=FuelPriceChartView.as_view('fuel_price_chart_view'))
Esempio n. 2
0
        trans.account_id = int(data['account'])
        trans.budget_id = int(data['budget'])
        trans.notes = data['notes'].strip()
        if data['is_active'] == 'true':
            trans.is_active = True
        else:
            trans.is_active = False
        logger.info('%s: %s', action, trans.as_dict)
        db_session.add(trans)
        db_session.commit()
        return 'Successfully saved ScheduledTransaction' \
               ' %d in database.' % trans.id


app.add_url_rule(
    '/scheduled',
    view_func=ScheduledView.as_view('scheduled_view')
)
app.add_url_rule(
    '/scheduled/<int:sched_trans_id>',
    view_func=ScheduledTransView.as_view('sched_trans')
)
app.add_url_rule(
    '/ajax/scheduled',
    view_func=ScheduledAjax.as_view('scheduled_ajax')
)
app.add_url_rule(
    '/ajax/scheduled/<int:sched_trans_id>',
    view_func=OneScheduledAjax.as_view('one_scheduled_ajax')
)
app.add_url_rule(
    '/forms/scheduled',
Esempio n. 3
0
from flask.views import MethodView
from flask import render_template, request
from versionfinder import find_version

from biweeklybudget.flaskapp.app import app
from biweeklybudget.version import VERSION, PROJECT_URL
from biweeklybudget.settings import DB_CONNSTRING

logger = logging.getLogger(__name__)

for lname in ['versionfinder', 'pip', 'git']:
    l = logging.getLogger(lname)
    l.setLevel(logging.CRITICAL)
    l.propagate = True


class PoolView(MethodView):
    """
    Render the GET /pool view using the ``pool.html`` template.
    """
    def get(self):
        return render_template('pool.html',
                               version=VERSION,
                               url=PROJECT_URL,
                               ua_str=request.headers.get(
                                   'User-Agent', 'unknown'),
                               db_uri=DB_CONNSTRING)


app.add_url_rule('/pool', view_func=PoolView.as_view('pool_view'))
Esempio n. 4
0
            args['search[value]'] = 'FILTERHACK'
        table = DataTable(
            args, OFXTransaction, db_session.query(OFXTransaction),
            [('date', 'date_posted',
              lambda i: i.date_posted.strftime('%Y-%m-%d')),
             ('amount', lambda a: float(a.amount)),
             ('account',
              'account.name', lambda i: "{} ({})".format(i.name, i.id)),
             ('type', 'trans_type'), 'name', 'memo', 'description', 'fitid',
             ('last_stmt', 'statement.id'),
             ('last_stmt_date', 'statement.as_of',
              lambda i: i.as_of.strftime('%Y-%m-%d')),
             ('reconcile_id', 'reconcile', lambda i: None
              if i.reconcile is None else i.reconcile.id)])
        table.add_data(acct_id=lambda o: o.account_id)
        if args['search[value]'] != '':
            table.searchable(lambda qs, s: self._filterhack(qs, s, args_dict))
        return jsonify(table.json())


app.add_url_rule('/ofx', view_func=OfxView.as_view('ofx_view'))
app.add_url_rule('/ajax/ofx', view_func=OfxAjax.as_view('ofx_ajax'))
app.add_url_rule('/ajax/ofx/<int:acct_id>/<fitid>',
                 view_func=OfxTransAjax.as_view('ofx_trans_ajax'))
app.add_url_rule('/api/ofx/accounts',
                 view_func=OfxAccounts.as_view('ofx_api_accounts'))
app.add_url_rule('/api/ofx/statement',
                 view_func=OfxStatementPost.as_view('ofx_api_statement'))
app.add_url_rule('/ofx/<int:acct_id>/<fitid>',
                 view_func=OfxTransView.as_view('ofx_trans'))
Esempio n. 5
0
            is_interest_charge=True
        )
        logger.info(
            'Adding manual interest transaction to OFXTransactions: '
            'account_id=%d statement_filename=%s statement=%s '
            'OFXTransaction=%s', acct.id, data['filename'], stmt,
            trans
        )
        db_session.add(trans)
        db_session.commit()
        return 'Successfully saved OFXTransaction with FITID %s in database' \
               '.' % trans.fitid


app.add_url_rule(
    '/accounts/credit-payoff',
    view_func=CreditPayoffsView.as_view('credit_payoffs_view')
)
app.add_url_rule(
    '/settings/credit-payoff',
    view_func=PayoffSettingsFormHandler.as_view('payoff_settings_form')
)
app.add_url_rule(
    '/ajax/account_ofx_ajax/<int:account_id>',
    view_func=AccountOfxAjax.as_view('account_ofx_ajax')
)
app.add_url_rule(
    '/forms/credit-payoff-account-ofx',
    view_func=AccountOfxFormHandler.as_view('payoff_account_ofx_form')
)
Esempio n. 6
0
                        description=desc,
                        notes=data['notes'],
                        account=st.account,
                        scheduled_trans=st,
                        planned_budget=st.budget)
        db_session.add(t)
        db_session.add(TxnReconcile(transaction=t, note=desc))
        db_session.commit()
        logger.info(
            'Created Transaction %d to skip '
            'ScheduledTransaction %d', t.id, st.id)
        return 'Successfully created Transaction %d to skip ' \
               'ScheduledTransaction %d.' % (t.id, st.id)


app.add_url_rule('/payperiods',
                 view_func=PayPeriodsView.as_view('payperiods_view'))

app.add_url_rule('/payperiod/<period_date>',
                 view_func=PayPeriodView.as_view('payperiod_view'))

app.add_url_rule('/pay_period_for',
                 view_func=PeriodForDateView.as_view('pay_period_for_view'))

app.add_url_rule(
    '/forms/sched_to_trans',
    view_func=SchedToTransFormHandler.as_view('sched_to_trans_form'))

app.add_url_rule(
    '/forms/skip_sched_trans',
    view_func=SkipSchedTransFormHandler.as_view('skip_sched_trans_form'))
Esempio n. 7
0
                data[ds] = copy(datedict)
                data[ds]['date'] = ds
            if bal.ledger is None:
                data[ds][bal.account.name] = 0.0
            else:
                data[ds][bal.account.name] = float(bal.ledger)
        resdata = []
        last = None
        for k in sorted(data.keys()):
            if last is None:
                last = data[k]
                continue
            d = copy(data[k])
            for subk in acct_names:
                if d[subk] is None:
                    d[subk] = last[subk]
            last = d
            resdata.append(d)
        res = {
            'data': resdata,
            'keys': sorted(acct_names)
        }
        return jsonify(res)


app.add_url_rule('/', view_func=IndexView.as_view('index_view'))
app.add_url_rule(
    '/ajax/chart-data/account-balances',
    view_func=AcctBalanaceChartView.as_view('acct_balance_chart_view')
)
                    continue
                fixeddata[key].append(d)
        val = json.dumps(fixeddata, sort_keys=True, cls=MagicJSONEncoder)
        try:
            parse_payoff_settings_json(val)
        except Exception as ex:
            logger.error('Error converting payoff settings JSON',
                         exc_info=True)
            return jsonify({
                'success': False,
                'error_message': 'Error parsing JSON: %s' % ex
            })
        logger.info('Changing setting value to: %s', val)
        setting.value = val
        db_session.add(setting)
        db_session.commit()
        return jsonify({
            'success':
            True,
            'success_message':
            'Successfully updated setting '
            '"credit-payoff" in database.'
        })


app.add_url_rule('/accounts/credit-payoff',
                 view_func=CreditPayoffsView.as_view('credit_payoffs_view'))
app.add_url_rule(
    '/settings/credit-payoff',
    view_func=PayoffSettingsFormHandler.as_view('payoff_settings_form'))
Esempio n. 9
0
            return jsonify({
                'success':
                False,
                'error_message':
                'Exception committing reconcile(s): %s' % ex
            }), 400
        return jsonify({
            'success':
            True,
            'success_message':
            'Successfully reconciled '
            '%d transactions' % rec_count
        })


app.add_url_rule('/reconcile',
                 view_func=ReconcileView.as_view('reconcile_view'))

app.add_url_rule('/ajax/reconcile/<int:reconcile_id>',
                 view_func=TxnReconcileAjax.as_view('txn_reconcile_ajax'))

app.add_url_rule(
    '/ajax/unreconciled/ofx',
    view_func=OfxUnreconciledAjax.as_view('ofx_unreconciled_ajax'))

app.add_url_rule(
    '/ajax/unreconciled/trans',
    view_func=TransUnreconciledAjax.as_view('trans_unreconciled_ajax'))

app.add_url_rule('/ajax/reconcile',
                 view_func=ReconcileAjax.as_view('reconcile_ajax'))
Esempio n. 10
0
        trans.notes = data['notes'].strip()
        budg_amts = {}
        for bid, budg_amt in data['budgets'].items():
            budg = db_session.query(Budget).get(int(bid))
            budg_amts[budg] = Decimal(budg_amt)
        trans.set_budget_amounts(budg_amts)
        logger.info('%s: %s', action, trans.as_dict)
        db_session.add(trans)
        db_session.commit()
        return {
            'success_message':
            'Successfully saved Transaction %d  in database.'
            '' % trans.id,
            'success':
            True,
            'trans_id':
            trans.id
        }


app.add_url_rule('/transactions',
                 view_func=TransactionsView.as_view('transactions_view'))
app.add_url_rule('/transactions/<int:trans_id>',
                 view_func=OneTransactionView.as_view('one_transaction_view'))
app.add_url_rule('/ajax/transactions',
                 view_func=TransactionsAjax.as_view('transactions_ajax'))
app.add_url_rule('/ajax/transactions/<int:trans_id>',
                 view_func=OneTransactionAjax.as_view('one_transaction_ajax'))
app.add_url_rule('/forms/transaction',
                 view_func=TransactionFormHandler.as_view('transaction_form'))
Esempio n. 11
0
from flask import render_template, request
from versionfinder import find_version

from biweeklybudget.flaskapp.app import app
from biweeklybudget.version import VERSION, PROJECT_URL
from biweeklybudget.settings import DB_CONNSTRING

logger = logging.getLogger(__name__)

for lname in ['versionfinder', 'pip', 'git']:
    l = logging.getLogger(lname)
    l.setLevel(logging.CRITICAL)
    l.propagate = True


class HelpView(MethodView):
    """
    Render the GET /help view using the ``help.html`` template.
    """
    def get(self):
        return render_template(
            'help.html',
            ver_info=find_version('biweeklybudget').long_str,
            version=VERSION,
            url=PROJECT_URL,
            ua_str=request.headers.get('User-Agent', 'unknown'),
            db_uri=DB_CONNSTRING)


app.add_url_rule('/help', view_func=HelpView.as_view('help_view'))
Esempio n. 12
0
            item.is_active = False
        logger.info('%s: %s', action, item.as_dict)
        db_session.add(item)
        db_session.commit()
        return {
            'success_message':
            'Successfully saved BoMItem %d '
            'in database.' % item.id,
            'success':
            True,
            'id':
            item.id
        }


app.add_url_rule('/projects', view_func=ProjectsView.as_view('projects'))
app.add_url_rule('/forms/projects',
                 view_func=ProjectsFormHandler.as_view('projects_form'))
app.add_url_rule('/ajax/projects',
                 view_func=ProjectsAjax.as_view('projects_ajax'))
app.add_url_rule('/projects/<int:project_id>',
                 view_func=BoMItemView.as_view('bom_item_view'))
app.add_url_rule('/ajax/projects/<int:project_id>',
                 view_func=ProjectAjax.as_view('ajax_project_view'))
app.add_url_rule('/ajax/projects/<int:project_id>/bom_items',
                 view_func=BoMItemsAjax.as_view('bom_items_ajax'))
app.add_url_rule('/ajax/projects/bom_item/<int:id>',
                 view_func=BoMItemAjax.as_view('bom_item_ajax'))
app.add_url_rule('/forms/bom_item',
                 view_func=BoMItemFormHandler.as_view('bom_item_form'))
Esempio n. 13
0
    along with biweeklybudget.  If not, see <http://www.gnu.org/licenses/>.

The Copyright and Authors attributions contained herein may not be removed or
otherwise altered, except to add the Author attribution of a contributor to
this work. (Additional Terms pursuant to Section 7b of the AGPL v3)
################################################################################
While not legally required, I sincerely request that anyone who finds
bugs please submit them at <https://github.com/jantman/biweeklybudget> or
to me via email, and that you send any contributions or improvements
either as a pull request on GitHub, or to me via email.
################################################################################

AUTHORS:
Jason Antman <*****@*****.**> <http://www.jasonantman.com>
################################################################################
"""

# NOTE - DO NOT forget to add this to __init__.py
from flask.views import MethodView
from flask import render_template

from biweeklybudget.flaskapp.app import app


class ExampleView(MethodView):
    def get(self):
        return render_template('example.html')


app.add_url_rule('/example', view_func=ExampleView.as_view('example_view'))
Esempio n. 14
0
                    records[ds] = {'date': ds}
                if budg_name not in records[ds]:
                    records[ds][budg_name] = Decimal('0')
                records[ds][budg_name] += bt.amount
        result = [records[k] for k in sorted(records.keys())]
        res = {'data': result, 'keys': sorted(list(budgets_present))}
        return jsonify(res)

    def _budget_names(self):
        return {
            x.id: x.name
            for x in db_session.query(Budget).filter(
                Budget.is_income.__eq__(False),
                Budget.omit_from_graphs.__eq__(False)).all()
        }


app.add_url_rule('/budgets', view_func=BudgetsView.as_view('budgets_view'))
app.add_url_rule('/budgets/<int:budget_id>',
                 view_func=OneBudgetView.as_view('one_budget_view'))
app.add_url_rule('/ajax/budget/<int:budget_id>',
                 view_func=BudgetAjax.as_view('budget_ajax'))
app.add_url_rule('/forms/budget',
                 view_func=BudgetFormHandler.as_view('budget_form'))
app.add_url_rule(
    '/forms/budget_transfer',
    view_func=BudgetTxfrFormHandler.as_view('budget_transfer_form'))
app.add_url_rule(
    '/ajax/chart-data/budget-spending/<string:aggregation>',
    view_func=BudgetSpendingChartView.as_view('budget_spending_chart_view'))
Esempio n. 15
0
bugs please submit them at <https://github.com/jantman/biweeklybudget> or
to me via email, and that you send any contributions or improvements
either as a pull request on GitHub, or to me via email.
################################################################################

AUTHORS:
Jason Antman <*****@*****.**> <http://www.jasonantman.com>
################################################################################
"""

from flask.views import MethodView
from biweeklybudget.settings import BIWEEKLYBUDGET_TEST_TIMESTAMP
from biweeklybudget.utils import dtnow
from biweeklybudget.flaskapp.app import app


class DateTestJS(MethodView):
    """
    Handle GET /utils/datetest.js endpoint.
    """
    def get(self):
        if BIWEEKLYBUDGET_TEST_TIMESTAMP is None:
            return 'var BIWEEKLYBUDGET_DEFAULT_DATE = new Date();'
        dt = dtnow()
        return 'var BIWEEKLYBUDGET_DEFAULT_DATE = new Date(%s, %s, %s);' % (
            dt.year, (dt.month - 1), dt.day)


app.add_url_rule('/utils/datetest.js',
                 view_func=DateTestJS.as_view('date_test_js'))
Esempio n. 16
0
                         notes=notes,
                         planned_budget=budget)
        db_session.add(t1)
        t2 = Transaction(date=trans_date,
                         budget_amounts={budget: (-1 * amt)},
                         budgeted_amount=(-1 * amt),
                         description=desc,
                         account=to_acct,
                         notes=notes,
                         planned_budget=budget)
        db_session.add(t2)
        t1.transfer = t2
        db_session.add(t1)
        t2.transfer = t1
        db_session.add(t2)
        db_session.commit()
        return 'Successfully saved Transactions %d and %d in database.' % (
            t1.id, t2.id)


app.add_url_rule('/accounts', view_func=AccountsView.as_view('accounts_view'))
app.add_url_rule('/ajax/account/<int:account_id>',
                 view_func=AccountAjax.as_view('account_ajax'))
app.add_url_rule('/accounts/<int:acct_id>',
                 view_func=OneAccountView.as_view('account_view'))
app.add_url_rule('/forms/account',
                 view_func=AccountFormHandler.as_view('account_form'))
app.add_url_rule(
    '/forms/account_transfer',
    view_func=AccountTxfrFormHandler.as_view('account_transfer_form'))
Esempio n. 17
0
from flask.views import MethodView
from flask import render_template, request
from versionfinder import find_version

from biweeklybudget.flaskapp.app import app
from biweeklybudget.version import VERSION, PROJECT_URL
from biweeklybudget.settings import DB_CONNSTRING

logger = logging.getLogger(__name__)

for lname in ['versionfinder', 'pip', 'git']:
    l = logging.getLogger(lname)
    l.setLevel(logging.CRITICAL)
    l.propagate = True


class LawnView(MethodView):
    """
    Render the GET /lawn view using the ``lawn.html`` template.
    """
    def get(self):
        return render_template('lawn.html',
                               version=VERSION,
                               url=PROJECT_URL,
                               ua_str=request.headers.get(
                                   'User-Agent', 'unknown'),
                               db_uri=DB_CONNSTRING)


app.add_url_rule('/lawn', view_func=LawnView.as_view('lawn_view'))