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

Use isinstance instead of comparing class type #2393

Merged
merged 1 commit into from
Oct 15, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions flask_admin/contrib/mongoengine/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,13 @@ def scaffold_list_columns(self):
columns = []

for n, f in self._get_model_fields():
# Verify type
field_class = type(f)

if (field_class == mongoengine.ListField and
isinstance(f.field, mongoengine.EmbeddedDocumentField)):
if isinstance(f, mongoengine.ListField) and isinstance(f.field, mongoengine.EmbeddedDocumentField):
continue

if field_class == mongoengine.EmbeddedDocumentField:
if isinstance(f, mongoengine.EmbeddedDocumentField):
continue

if self.column_display_pk or field_class != mongoengine.ObjectIdField:
if self.column_display_pk or not isinstance(f, mongoengine.ObjectIdField):
columns.append(n)

return columns
Expand All @@ -343,7 +339,7 @@ def scaffold_sortable_columns(self):

for n, f in self._get_model_fields():
if type(f) in SORTABLE_FIELDS:
if self.column_display_pk or type(f) != mongoengine.ObjectIdField:
if self.column_display_pk or not isinstance(f, mongoengine.ObjectIdField):
columns[n] = f

return columns
Expand Down Expand Up @@ -467,7 +463,7 @@ def _search(self, query, search_term):
criteria = None

for field in self._search_fields:
if type(field) == mongoengine.ReferenceField:
if isinstance(field, mongoengine.ReferenceField):
import re
regex = re.compile('.*%s.*' % term)
else:
Expand Down
9 changes: 3 additions & 6 deletions flask_admin/contrib/peewee/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,9 @@ def scaffold_list_columns(self):
columns = []

for n, f in self._get_model_fields():
# Verify type
field_class = type(f)

if field_class == ForeignKeyField:
if isinstance(f, ForeignKeyField):
columns.append(n)
elif self.column_display_pk or field_class != PrimaryKeyField:
elif self.column_display_pk or not isinstance(f, PrimaryKeyField):
columns.append(n)

return columns
Expand All @@ -208,7 +205,7 @@ def scaffold_sortable_columns(self):
columns = dict()

for n, f in self._get_model_fields():
if self.column_display_pk or type(f) != PrimaryKeyField:
if self.column_display_pk or not isinstance(f, PrimaryKeyField):
columns[n] = f

return columns
Expand Down