Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WTForms 3.0 support #35

Merged
merged 1 commit into from
Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from sqlalchemy.schema import Table
from wtforms import fields
from wtforms import Form
from wtforms.compat import iteritems
from wtforms.compat import text_type
from wtforms.validators import InputRequired
from wtforms.validators import Optional
from wtforms.validators import Regexp
Expand All @@ -36,14 +34,13 @@
class LazySelect:
def __call__(self, field, **kwargs):
return list(
(val, text_type(label), selected)
for val, label, selected in field.iter_choices()
(val, str(label), selected) for val, label, selected in field.iter_choices()
)


class Base:
def __init__(self, **kwargs):
for k, v in iteritems(kwargs):
for k, v in iter(kwargs.items()):
setattr(self, k, v)


Expand Down
8 changes: 3 additions & 5 deletions wtforms_sqlalchemy/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import operator

from wtforms import widgets
from wtforms.compat import string_types
from wtforms.compat import text_type
from wtforms.fields import SelectFieldBase
from wtforms.validators import ValidationError

Expand Down Expand Up @@ -83,7 +81,7 @@ def __init__(

if get_label is None:
self.get_label = lambda x: x
elif isinstance(get_label, string_types):
elif isinstance(get_label, str):
self.get_label = operator.attrgetter(get_label)
else:
self.get_label = get_label
Expand Down Expand Up @@ -111,7 +109,7 @@ def _get_object_list(self):
if self._object_list is None:
query = self.query if self.query is not None else self.query_factory()
get_pk = self.get_pk
self._object_list = list((text_type(get_pk(obj)), obj) for obj in query)
self._object_list = list((str(get_pk(obj)), obj) for obj in query)
return self._object_list

def iter_choices(self):
Expand Down Expand Up @@ -215,4 +213,4 @@ class QueryCheckboxField(QuerySelectMultipleField):

def get_pk_from_identity(obj):
key = identity_key(instance=obj)[1]
return ":".join(text_type(x) for x in key)
return ":".join(str(x) for x in key)