Skip to content

Commit

Permalink
Merge pull request #35 from azmeuk/wtforms3
Browse files Browse the repository at this point in the history
WTForms 3.0 support
  • Loading branch information
azmeuk committed Nov 6, 2021
2 parents 390fc05 + bd13207 commit 98483f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
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)

0 comments on commit 98483f1

Please sign in to comment.