Skip to content

Commit d7c8465

Browse files
committed
Save the uploaded file and transaction metadata
1 parent 4ca903e commit d7c8465

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

project/ndaparser/views.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
from .forms import UploadForm
99
from .importer import NDAImporter
10+
from .parser import parseLine
11+
from .models import UploadedTransaction
1012

1113

1214
class NordeaUploadView(FormView):
@@ -32,6 +34,24 @@ def form_valid(self, form):
3234
h = NDAImporter(f)
3335
transactions = h.import_transactions(transactions_handler)
3436

37+
# parse the file again for the last transaction timestamp
38+
last_stamp = None
39+
with open(tmp.name) as fp:
40+
for line in fp:
41+
nt = parseLine(line)
42+
if not nt:
43+
continue
44+
if not last_stamp:
45+
last_stamp = nt.timestamp
46+
if nt.timestamp > last_stamp:
47+
last_stamp = nt.timestamp
48+
49+
UploadedTransaction(
50+
last_transaction = last_stamp,
51+
file = self.request.FILES['ndafile'],
52+
user = self.request.user
53+
).save()
54+
3555
# Done with the temp file, get rid of it
3656
os.unlink(tmp.name)
3757

0 commit comments

Comments
 (0)