coleifer / flask-peewee

flask integration for peewee, including admin, authentication, rest api and more
http://flask-peewee.readthedocs.org/
MIT License
776 stars 181 forks source link

Compatibility with WTForms 3.0 #188

Closed mcepl closed 2 years ago

mcepl commented 2 years ago

While packaging for openSUSE, I found that various tests are not compatible with the current WTForms 3.0. In order to make this happen I had to add this patch:

---
 flask_peewee/auth.py        |    6 +++---
 flask_peewee/filters.py     |    2 +-
 flask_peewee/tests/admin.py |    6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

--- a/flask_peewee/auth.py
+++ b/flask_peewee/auth.py
@@ -13,7 +13,7 @@ from flask import url_for
 from peewee import *
 from wtforms import Form
 from wtforms import PasswordField
-from wtforms import TextField
+from wtforms import StringField
 from wtforms import validators

 from flask_peewee.utils import check_password
@@ -26,8 +26,8 @@ current_dir = os.path.dirname(__file__)

 class LoginForm(Form):
-    username = TextField('Username', validators=[validators.Required()])
-    password = PasswordField('Password', validators=[validators.Required()])
+    username = StringField('Username', validators=[validators.DataRequired()])
+    password = PasswordField('Password', validators=[validators.DataRequired()])

 class BaseUser(object):
--- a/flask_peewee/filters.py
+++ b/flask_peewee/filters.py
@@ -387,5 +387,5 @@ class FilterModelConverter(BaseModelConv
     def __init__(self, *args, **kwargs):
         super(FilterModelConverter, self).__init__(*args, **kwargs)
         self.defaults = dict(self.defaults)
-        self.defaults[TextField] = fields.TextField
+        self.defaults[TextField] = fields.StringField
         self.defaults[DateTimeField] = fields.DateTimeField
--- a/flask_peewee/tests/admin.py
+++ b/flask_peewee/tests/admin.py
@@ -47,7 +47,7 @@ class AdminTestCase(BaseAdminTestCase):
         # check login redirect
         resp = self.app.get('/admin/')
         self.assertEqual(resp.status_code, 302)
-        self.assertEqual(resp.headers['location'], 'http://localhost/accounts/login/?next=%2Fadmin%2F')
+        self.assertEqual(resp.headers['location'], '/accounts/login/?next=%2Fadmin%2F')

         # try logging in as a normal user, get a 403 forbidden
         resp = self.app.post('/accounts/login/', data={
@@ -56,7 +56,7 @@ class AdminTestCase(BaseAdminTestCase):
             'next': '/admin/',
         })
         self.assertEqual(resp.status_code, 302)
-        self.assertEqual(resp.headers['location'], 'http://localhost/admin/')
+        self.assertEqual(resp.headers['location'], '/admin/')

         resp = self.app.get('/admin/')
         self.assertEqual(resp.status_code, 403)
@@ -71,7 +71,7 @@ class AdminTestCase(BaseAdminTestCase):
             'next': '/admin/',
         })
         self.assertEqual(resp.status_code, 302)
-        self.assertEqual(resp.headers['location'], 'http://localhost/admin/')
+        self.assertEqual(resp.headers['location'], '/admin/')

         resp = self.app.get('/admin/')
         self.assertEqual(resp.status_code, 200)
coleifer commented 2 years ago

https://github.com/coleifer/flask-peewee/commit/1db1eabd642001fc6f56bd58b628facd1856f579

Thank you very much for posting this. I've tagged and released 3.0.5 which contains the above fix.