Skip to content

Commit

Permalink
chore: quality fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Mar 1, 2024
1 parent 77aba20 commit 834b707
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
4 changes: 1 addition & 3 deletions platform_plugin_aspects/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ class PlatformPluginAspectsConfig(AppConfig):
def ready(self):
"""Load modules of Aspects."""
super().ready()
from platform_plugin_aspects.extensions import filters # pylint: disable=unused-import, import-outside-toplevel

from platform_plugin_aspects import ( # pylint: disable=import-outside-toplevel, unused-import
signals,
sinks,
tasks,
)

from platform_plugin_aspects.extensions import filters # pylint: disable=unused-import, import-outside-toplevel
17 changes: 5 additions & 12 deletions platform_plugin_aspects/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import os
from importlib import import_module

from crum import get_current_user
from django.conf import settings
Expand Down Expand Up @@ -116,39 +117,31 @@ def generate_guest_token(user, course, dashboard_uuid, filters):
logger.error(exc)
return None, exc

"""Utility functions for event_sink_clickhouse."""
import logging
from importlib import import_module

from django.conf import settings

log = logging.getLogger(__name__)


def get_model(model_setting):
"""Load a model from a setting."""
MODEL_CONFIG = getattr(settings, "EVENT_SINK_CLICKHOUSE_MODEL_CONFIG", {})

model_config = MODEL_CONFIG.get(model_setting)
if not model_config:
log.error("Unable to find model config for %s", model_setting)
logger.error("Unable to find model config for %s", model_setting)
return None

module = model_config.get("module")
if not module:
log.error("Module was not specified in %s", model_setting)
logger.error("Module was not specified in %s", model_setting)
return None

model_name = model_config.get("model")
if not model_name:
log.error("Model was not specified in %s", model_setting)
logger.error("Model was not specified in %s", model_setting)
return None

try:
model = getattr(import_module(module), model_name)
return model
except (ImportError, AttributeError, ModuleNotFoundError):
log.error("Unable to load model %s.%s", module, model_name)
logger.error("Unable to load model %s.%s", module, model_name)

return None

Expand Down
2 changes: 1 addition & 1 deletion test_utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TestUtils(unittest.TestCase):
"EVENT_SINK_CLICKHOUSE_MODEL_CONFIG",
{"my_model": {"module": "myapp.models", "model": "MyModel"}},
)
@patch("platform_plugin_aspects.utils.log")
@patch("platform_plugin_aspects.utils.logger")
def test_get_model_success(self, mock_log, mock_import_module):
mock_model = Mock(__name__="MyModel")
mock_import_module.return_value = Mock(MyModel=mock_model)
Expand Down

0 comments on commit 834b707

Please sign in to comment.