vanth/vanth/pages/accounts.py
Eli Ribble 393ef748cc Get OFX file upload working through celery
I switched to using ofxparse because my own parser wasn't up to snuff on
handling the download file that I got from my bank and I got sick of
maintaining my own because SGML is an ugly mess

This commit means that my automatic download won't work any more because
it's expecting to pass data through my own parser, which we're not going
to do any more. That's okay because my bank's OFX integration is
actually down anyways
2016-08-11 10:54:29 -06:00

62 lines
2.2 KiB
Python

import logging
import flask
import werkzeug.utils
import vanth.celery
import vanth.pages.tools
import vanth.platform.ofxaccount
import vanth.platform.ofxsource
LOGGER = logging.getLogger()
blueprint = flask.Blueprint('accounts', __name__)
@blueprint.route('/accounts/', methods=['GET'])
def get_accounts():
my_accounts = vanth.platform.ofxaccount.by_user(flask.session['user_id'])
sources = vanth.platform.ofxsource.get()
return flask.render_template('accounts.html', accounts=my_accounts, sources=sources)
@blueprint.route('/accounts/<uuid:account_uuid>/', methods=['GET'])
def get_account(account_uuid):
account = vanth.platform.ofxaccount.by_uuid(account_uuid)
records = vanth.platform.ofxrecord.by_account(account_uuid)
return flask.render_template('account.html', account=account, records=records)
@blueprint.route('/account/', methods=['POST'])
@vanth.pages.tools.parse({
'account_id' : str,
'account_type' : str,
'institution' : str,
'name' : str,
'password' : str,
'user_id' : str,
})
def post_account(arguments):
arguments['owner'] = flask.session['user_id']
vanth.platform.ofxaccount.create(arguments)
return flask.redirect('/accounts/')
@blueprint.route('/update/', methods=['POST'])
@vanth.pages.tools.parse({
'account_uuid' : str,
})
def post_update(arguments):
vanth.celery.update_account.delay(**arguments)
return flask.redirect('/accounts/')
@blueprint.route('/transactions/', methods=['POST'])
@vanth.pages.tools.parse({
'account_uuid' : str,
})
def post_transactions(arguments):
if 'transactions' not in flask.request.files:
return flask.render_template('error.html', error="You did not include the content of the file in your upload")
transactions = flask.request.files['transactions']
if transactions.filename == '':
return flask.redirect('/accounts/{}/'.format(arguments['account_uuid']))
filename = werkzeug.utils.secure_filename(transactions.filename)
LOGGER.info("Saving uploaded file %s to %s", transactions.filename, filename)
transactions.save(filename)
vanth.celery.process_transaction_upload.delay(arguments['account_uuid'], filename)
return flask.redirect('/accounts/{}/'.format(arguments['account_uuid']))