From 632dff8c6019f5ccd268bb0d2579951b3ab68885 Mon Sep 17 00:00:00 2001 From: Glandos Date: Fri, 12 Nov 2021 23:33:31 +0100 Subject: [PATCH 1/4] Support WTForms 3 --- ihatemoney/api/common.py | 2 +- ihatemoney/forms.py | 19 ++++++++++++++++--- ihatemoney/tests/api_test.py | 4 ++-- setup.cfg | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ihatemoney/api/common.py b/ihatemoney/api/common.py index fa097dec9..ef26650bb 100644 --- a/ihatemoney/api/common.py +++ b/ihatemoney/api/common.py @@ -3,7 +3,7 @@ from flask import current_app, request from flask_restful import Resource, abort from werkzeug.security import check_password_hash -from wtforms.fields.core import BooleanField +from wtforms.fields import BooleanField from ihatemoney.forms import EditProjectForm, MemberForm, ProjectForm, get_billform_for from ihatemoney.models import Bill, Person, Project, db diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index a55166e8f..e303287a0 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -9,9 +9,22 @@ from flask_wtf.form import FlaskForm from markupsafe import Markup from werkzeug.security import check_password_hash, generate_password_hash -from wtforms.fields.core import Label, SelectField, SelectMultipleField -from wtforms.fields.html5 import DateField, DecimalField, URLField -from wtforms.fields.simple import BooleanField, PasswordField, StringField, SubmitField +from wtforms.fields import ( + BooleanField, + DateField, + DecimalField, + Label, + PasswordField, + SelectField, + SelectMultipleField, + StringField, + SubmitField, +) +try: + # Compat for WTForms <= 2.3.3 + from wtforms.fields.html5 import URLField +except ModuleNotFoundError: + from wtforms.fields import URLField from wtforms.validators import ( URL, DataRequired, diff --git a/ihatemoney/tests/api_test.py b/ihatemoney/tests/api_test.py index 1365fa02b..9a2d2149f 100644 --- a/ihatemoney/tests/api_test.py +++ b/ihatemoney/tests/api_test.py @@ -539,7 +539,7 @@ def test_bills_with_calculation(self): "amount": expected_amount, "date": "2011-08-10", "id": id, - "external_link": "", + "external_link": None, "original_currency": "XXX", "converted_amount": expected_amount, } @@ -834,7 +834,7 @@ def test_weighted_bills(self): "amount": 25.0, "date": "2011-08-10", "id": 1, - "external_link": "", + "external_link": None, "converted_amount": 25.0, "original_currency": "XXX", } diff --git a/setup.cfg b/setup.cfg index 2920691e6..3f6f74a61 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ install_requires = Flask-SQLAlchemy>=2.4,<3 Flask-Talisman>=0.8,<1 Flask-WTF>=0.14.3,<2 - WTForms>=2.3.1,<2.4 + WTForms>=2.3.1,<3.1 Flask>=2,<3 itsdangerous>=2,<3 Jinja2>=3,<4 From fdbc4c044741bc1a0503202f1c069d32fe969ed9 Mon Sep 17 00:00:00 2001 From: Glandos Date: Sat, 13 Nov 2021 21:16:31 +0100 Subject: [PATCH 2/4] default value to None for WTForm backward compatibility --- ihatemoney/forms.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index e303287a0..6800df100 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -325,6 +325,7 @@ class BillForm(FlaskForm): original_currency = SelectField(_("Currency"), validators=[DataRequired()]) external_link = URLField( _("External link"), + default=None, validators=[Optional(), URL()], description=_("A link to an external document, related to this bill"), ) From e861322a568d07832d28f96d1c01265433c1cc80 Mon Sep 17 00:00:00 2001 From: Glandos Date: Sat, 13 Nov 2021 21:35:28 +0100 Subject: [PATCH 3/4] switch back to empty string as default WTForm backward compatibility needs that --- ihatemoney/forms.py | 2 +- ihatemoney/tests/api_test.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index 6800df100..27e438b94 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -325,7 +325,7 @@ class BillForm(FlaskForm): original_currency = SelectField(_("Currency"), validators=[DataRequired()]) external_link = URLField( _("External link"), - default=None, + default="", validators=[Optional(), URL()], description=_("A link to an external document, related to this bill"), ) diff --git a/ihatemoney/tests/api_test.py b/ihatemoney/tests/api_test.py index 9a2d2149f..1365fa02b 100644 --- a/ihatemoney/tests/api_test.py +++ b/ihatemoney/tests/api_test.py @@ -539,7 +539,7 @@ def test_bills_with_calculation(self): "amount": expected_amount, "date": "2011-08-10", "id": id, - "external_link": None, + "external_link": "", "original_currency": "XXX", "converted_amount": expected_amount, } @@ -834,7 +834,7 @@ def test_weighted_bills(self): "amount": 25.0, "date": "2011-08-10", "id": 1, - "external_link": None, + "external_link": "", "converted_amount": 25.0, "original_currency": "XXX", } From 033ade17ea9838fca894546d13ee567f7f46c304 Mon Sep 17 00:00:00 2001 From: Glandos Date: Sat, 13 Nov 2021 21:40:48 +0100 Subject: [PATCH 4/4] format --- ihatemoney/forms.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index 27e438b94..64137eb0d 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -20,6 +20,7 @@ StringField, SubmitField, ) + try: # Compat for WTForms <= 2.3.3 from wtforms.fields.html5 import URLField