Skip to content

Commit

Permalink
Fix compatibility with WTForms 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Oct 18, 2023
1 parent 7c5bd30 commit 44dfd48
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ dependencies = [
'typing_extensions',
'werkzeug',
'WTForms-SQLAlchemy',
'WTForms>=3.0',
'WTForms>=3.1',

]

Expand Down
12 changes: 6 additions & 6 deletions src/baseframe/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def iter_choices(self) -> ReturnIterChoices:
"""Iterate over choices."""
if self.data:
for user in self.data:
yield (user.userid, user.pickername, True)
yield (user.userid, user.pickername, True, {})

def process_formdata(self, valuelist: t.List[str]) -> None:
"""Process incoming data from request form."""
Expand Down Expand Up @@ -503,7 +503,7 @@ def _value(self) -> str:
def iter_choices(self) -> ReturnIterChoices:
"""Iterate over choices."""
if self.data:
yield (self.data.userid, self.data.pickername, True)
yield (self.data.userid, self.data.pickername, True, {})

def process_formdata(self, valuelist: t.List[str]) -> None:
"""Process incoming data from request form."""
Expand Down Expand Up @@ -546,7 +546,7 @@ def iter_choices(self) -> ReturnIterChoices:
"""Iterate over choices."""
if self.data:
for user in self.data:
yield (str(user), str(user), True)
yield (str(user), str(user), True, {})

def process_formdata(self, valuelist: t.List[str]) -> None:
"""Process incoming data from request form."""
Expand Down Expand Up @@ -616,10 +616,10 @@ def iter_choices(self) -> ReturnIterChoices:
"""Iterate over choices."""
if self.data:
if isinstance(self.data, (str, GeonameidProtocol)):
yield (str(self.data), str(self.data), True)
yield (str(self.data), str(self.data), True, {})
else:
for item in self.data:
yield (str(item), str(item), True)
yield (str(item), str(item), True, {})

def process_formdata(self, valuelist: t.List[str]) -> None:
"""Process incoming data from request form."""
Expand Down Expand Up @@ -883,7 +883,7 @@ def iter_choices(self) -> ReturnIterChoices:
"""Iterate over choices."""
selected_name = self.lenum[self.data].name if self.data is not None else None
for name, title in self.choices:
yield (name, title, name == selected_name)
yield (name, title, name == selected_name, {})

def process_data(self, value: t.Any) -> None:
"""Process incoming data from Python."""
Expand Down
4 changes: 3 additions & 1 deletion src/baseframe/forms/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

FilterCallable: te.TypeAlias = t.Callable[[t.Any], t.Any]
FilterList: te.TypeAlias = t.Iterable[FilterCallable]
ReturnIterChoices: te.TypeAlias = t.Generator[t.Tuple[str, str, bool], None, None]
ReturnIterChoices: te.TypeAlias = t.Generator[
t.Tuple[str, str, bool, t.Dict[str, t.Any]], None, None
]
ValidatorCallable: te.TypeAlias = t.Callable[[WTForm, WTField], None]
ValidatorList: te.TypeAlias = t.Sequence[ValidatorCallable]
ValidatorConstructor: te.TypeAlias = t.Callable[..., ValidatorCallable]
Expand Down
4 changes: 2 additions & 2 deletions src/baseframe/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def __call__(self, field: WTField, **kwargs: t.Any) -> Markup:
kwargs['class'] = 'select2'
html = [f'<select {html_params(name=field.name, **kwargs)}>']
if field.iter_choices():
for val, label, selected in field.iter_choices():
html.append(self.render_option(val, label, selected))
for val, label, selected, render_kw in field.iter_choices():
html.append(self.render_option(val, label, selected, **render_kw))
html.append('</select>')
return Markup(''.join(html))

Expand Down

0 comments on commit 44dfd48

Please sign in to comment.