Skip to content

Commit

Permalink
fix: improve get_member_for_entity helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Nov 14, 2023
1 parent caa6f65 commit 1f9a1a0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apis_core/apis_entities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def get_table(self, **kwargs):
default_cols = entity_settings.get("table_fields", [])
default_cols = default_cols + selected_cols

self.table_class = get_member_for_entity(self.get_model(), suffix="table")
self.table_class = get_member_for_entity(self.get_model(), suffix="Table")
if self.table_class is None:
self.table_class = get_entities_table(class_name, default_cols=default_cols)
table = super(GenericListViewNew, self).get_table()
Expand Down
10 changes: 3 additions & 7 deletions apis_core/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,19 @@ def get_member_for_entity(
module = ct.app_label
model = ct.model.capitalize()
if suffix:
model += suffix.capitalize()
model += suffix
if path:
module += f".{path}"
else:
if suffix:
module += f".{suffix.lower()}s"
logging.debug("Checking if %s.%s exists", module, model)
try:
members = inspect.getmembers(importlib.import_module(module))
members = list(filter(lambda c: c[0] == model, members))
except ModuleNotFoundError:
members = []
if members:
logging.debug(
"Based on path %s and suffix %s using class %s",
path,
suffix,
model,
)
logging.debug("Found %s.%s", module, model)
return members[0][1]
return None

0 comments on commit 1f9a1a0

Please sign in to comment.