From 438c073e0fa87fd5ee966872571ea1688aafa558 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Wed, 10 Aug 2016 17:20:00 -0600 Subject: [PATCH] Add simple function for uploading OFX-based transactions The OFX direct connection for my bank isn't working right now. I have a support ticket in. Until then I'm going to work on doing a manual upload and parse of transactions from this OFX document --- templates/account.html | 6 ++++++ vanth/pages/accounts.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/templates/account.html b/templates/account.html index a3061e0..b6272e0 100644 --- a/templates/account.html +++ b/templates/account.html @@ -29,4 +29,10 @@ {% else %}

This account does not have any transactions yet

{% endif %} +
+

Want to upload your own transactions? Cool. Do it here.

+ + + +
{% endblock %} diff --git a/vanth/pages/accounts.py b/vanth/pages/accounts.py index 723fe68..fc45523 100644 --- a/vanth/pages/accounts.py +++ b/vanth/pages/accounts.py @@ -1,10 +1,14 @@ +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']) @@ -40,3 +44,18 @@ def post_account(arguments): 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) + return flask.redirect('/accounts/{}/'.format(arguments['account_uuid']))