aboutsummaryrefslogtreecommitdiff
path: root/ihatemoney/forms.py
diff options
context:
space:
mode:
authorNicolas Vanvyve <NVanvyve@users.noreply.github.com>2020-01-13 21:17:55 +0100
committerGlandos <bugs-github@antipoul.fr>2020-01-13 21:17:55 +0100
commit9aa7e62d0f77f27590dac1cae5603e8f7efb891f (patch)
treefdccec64b145d2600a18f300bfec5891acd5fc73 /ihatemoney/forms.py
parent73a4d139fffe3fdbabd0a47839eacc9964810066 (diff)
downloadihatemoney-mirror-9aa7e62d0f77f27590dac1cae5603e8f7efb891f.zip
ihatemoney-mirror-9aa7e62d0f77f27590dac1cae5603e8f7efb891f.tar.gz
ihatemoney-mirror-9aa7e62d0f77f27590dac1cae5603e8f7efb891f.tar.bz2
Import previously exported json data (#518)
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 <hubscher.remy@gmail.com> * Remove useless variable and check json format * Use String.IO and test for wrong json * Remove coma Co-authored-by: Rémy HUBSCHER <hubscher.remy@gmail.com>
Diffstat (limited to 'ihatemoney/forms.py')
-rw-r--r--ihatemoney/forms.py17
1 files changed, 17 insertions, 0 deletions
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