From 61df8aaffb55cfb76670ae7ad5e3ad224b84325c Mon Sep 17 00:00:00 2001 From: Youe Graillot Date: Sun, 28 Nov 2021 02:58:10 +0100 Subject: [PATCH] cospend compatible import --- ihatemoney/utils.py | 7 ++++++- ihatemoney/web.py | 11 +++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ihatemoney/utils.py b/ihatemoney/utils.py index c5e16de1..19d3aea6 100644 --- a/ihatemoney/utils.py +++ b/ihatemoney/utils.py @@ -154,10 +154,15 @@ def csv2list_of_dicts(csv_to_convert): """Take a csv in-memory file and turns it into a list of dictionnaries """ - csv_file = TextIOWrapper(csv_to_convert) + csv_file = TextIOWrapper(csv_to_convert, encoding="utf-8") reader = csv.DictReader(csv_file) result = [] for r in reader: + # cospend filtering + if r["what"] == "deleteMeIfYouWant": + continue + elif r["what"] == "categoryname": + break r["amount"] = float(r["amount"]) r["payer_weight"] = float(r["payer_weight"]) r["owers"] = [o.strip() for o in r["owers"].split(",")] diff --git a/ihatemoney/web.py b/ihatemoney/web.py index 68c41376..cc6ae28d 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -477,14 +477,9 @@ def import_project(): # set it to project default. if e.get("currency", "") in ["", "XXX"]: e["currency"] = g.project.default_currency - if len(e) != len(attr): - raise ValueError(_("Invalid JSON")) - list_attr = [] - for i in e: - list_attr.append(i) - list_attr.sort() - if list_attr != attr: - raise ValueError(_("Invalid JSON")) + for a in attr: + if a not in e: + raise ValueError(_("Missing attribute {}").format(a)) # Keep track of currencies currencies.add(e["currency"])