From 9aa7e62d0f77f27590dac1cae5603e8f7efb891f Mon Sep 17 00:00:00 2001 From: Nicolas Vanvyve Date: Mon, 13 Jan 2020 21:17:55 +0100 Subject: Import previously exported json data (#518) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #417 * New tab upload * Extract data from JSON * Add users * Black format * Try to add bill * Import bills * Add french translation msg * Black reformat missing * Deactivated users are supported * Test import * Remove temp file in upload_json() * Incomplete tests * tests import * Update ihatemoney/translations/fr/LC_MESSAGES/messages.po Co-Authored-By: Rémy HUBSCHER * Remove useless variable and check json format * Use String.IO and test for wrong json * Remove coma Co-authored-by: Rémy HUBSCHER --- ihatemoney/forms.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'ihatemoney/forms.py') diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index eb1bf2b..88afd29 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -10,6 +10,8 @@ from wtforms.validators import ( NumberRange, Optional, ) +from flask_wtf.file import FileField, FileAllowed, FileRequired + from flask_babel import lazy_gettext as _ from flask import request from werkzeug.security import generate_password_hash @@ -110,6 +112,12 @@ class EditProjectForm(FlaskForm): return project +class UploadForm(FlaskForm): + file = FileField( + "JSON", validators=[FileRequired(), FileAllowed(["json", "JSON"], "JSON only!")] + ) + + class ProjectForm(EditProjectForm): id = StringField(_("Project identifier"), validators=[DataRequired()]) password = PasswordField(_("Private code"), validators=[DataRequired()]) @@ -181,6 +189,15 @@ class BillForm(FlaskForm): bill.external_link = self.external_link.data bill.date = self.date.data bill.owers = [Person.query.get(ower, project) for ower in self.payed_for.data] + return bill + + def fake_form(self, bill, project): + bill.payer_id = self.payer + bill.amount = self.amount + bill.what = self.what + bill.external_link = "" + bill.date = self.date + bill.owers = [Person.query.get(ower, project) for ower in self.payed_for] return bill -- cgit v1.1