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

Non existent exclude master #56

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions wtforms_alchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from wtforms_components import (
DateRange,
Email,
NumberRangeField,
PhoneNumberField,
SelectField,
SelectMultipleField,
Expand Down Expand Up @@ -40,7 +39,6 @@
InvalidAttributeException,
ModelFieldList,
ModelFormField,
NumberRangeField,
PhoneNumberField,
SelectField,
SelectMultipleField,
Expand Down Expand Up @@ -207,6 +205,11 @@ class Meta:
#: List of fields to only include in the generated form.
only = defaults.pop('only', [])

#: Silently ignore exclude elements which aren't mapped
#:
#: By Default silently ignores missing elements
silent_exclude = defaults.pop('silent_exclude', True)

def __init__(self, *args, **kwargs):
"""Sets object as form attribute."""

Expand Down
7 changes: 4 additions & 3 deletions wtforms_alchemy/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
DecimalField,
EmailField,
IntegerField,
NumberRangeField,
PhoneNumberField,
SelectField,
StringField,
Expand Down Expand Up @@ -88,7 +87,6 @@ class FormGenerator(object):
(types.ChoiceType, SelectField),
(types.ColorType, ColorField),
(types.EmailType, EmailField),
(types.NumberRangeType, NumberRangeField),
(types.PasswordType, PasswordField),
(types.PhoneNumberType, PhoneNumberField),
(types.ScalarListType, StringField),
Expand Down Expand Up @@ -163,7 +161,10 @@ def filter_attributes(self, attrs):

if self.meta.exclude:
for key in self.meta.exclude:
del attrs[key]
if self.meta.silent_exclude and not key in attrs:
continue
else:
del attrs[key]
return attrs

def validate_attribute(self, attr_name):
Expand Down