From a981e49558abcff0b78bfbe216383037acdb6b21 Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Wed, 5 Jul 2023 18:05:47 +0530 Subject: [PATCH] refactor: store config column names in constants --- eox_tenant/constants.py | 2 ++ eox_tenant/models.py | 6 ++++-- eox_tenant/receivers_helpers.py | 1 + eox_tenant/signals.py | 9 +++++---- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/eox_tenant/constants.py b/eox_tenant/constants.py index 7feb4e12..c9dc904b 100644 --- a/eox_tenant/constants.py +++ b/eox_tenant/constants.py @@ -3,3 +3,5 @@ LMS_ENVIRONMENT = getattr(settings, "SERVICE_VARIANT", None) == "lms" CMS_ENVIRONMENT = getattr(settings, "SERVICE_VARIANT", None) == "cms" +LMS_CONFIG_COLUMN = "lms_configs" +CMS_CONFIG_COLUMN = "studio_configs" diff --git a/eox_tenant/models.py b/eox_tenant/models.py index 0c970e01..80bee67c 100644 --- a/eox_tenant/models.py +++ b/eox_tenant/models.py @@ -11,6 +11,8 @@ from django.utils.translation import gettext_lazy as _ from jsonfield.fields import JSONField +from eox_tenant.constants import CMS_CONFIG_COLUMN, LMS_CONFIG_COLUMN + class TenantOrganization(models.Model): """ @@ -140,8 +142,8 @@ def get_configurations(self, domain): configurations = { "id": row[0], "external_key": row[1], - "lms_configs": json.loads(row[2]), - "studio_configs": json.loads(row[3]), + LMS_CONFIG_COLUMN: json.loads(row[2]), + CMS_CONFIG_COLUMN: json.loads(row[3]), "theming_configs": json.loads(row[4]), "meta": json.loads(row[5]), } diff --git a/eox_tenant/receivers_helpers.py b/eox_tenant/receivers_helpers.py index 58f923de..cc126ca0 100644 --- a/eox_tenant/receivers_helpers.py +++ b/eox_tenant/receivers_helpers.py @@ -12,6 +12,7 @@ def get_tenant_config_by_domain(domain, config_key): **Arguments** domain: String parameter. + config_key: Config column name. **Returns** configurations: dict diff --git a/eox_tenant/signals.py b/eox_tenant/signals.py index b37144cf..de419c7e 100644 --- a/eox_tenant/signals.py +++ b/eox_tenant/signals.py @@ -29,6 +29,7 @@ from django.conf import settings as base_settings from eox_tenant.async_utils import AsyncTaskHandler +from eox_tenant.constants import CMS_CONFIG_COLUMN, LMS_CONFIG_COLUMN from eox_tenant.receivers_helpers import get_tenant_config_by_domain from eox_tenant.utils import synchronize_tenant_organizations @@ -162,7 +163,7 @@ def start_lms_tenant(sender, environ, **kwargs): # pylint: disable=unused-argum This function runs every time a request is started in LMS. Read documentation of `_start_tenant` for more details. """ - _start_tenant(environ, "lms_configs") + _start_tenant(environ, LMS_CONFIG_COLUMN) def start_studio_tenant(sender, environ, **kwargs): # pylint: disable=unused-argument @@ -170,7 +171,7 @@ def start_studio_tenant(sender, environ, **kwargs): # pylint: disable=unused-ar This function runs every time a request is started in studio. Read documentation of `_start_tenant` for more details. """ - _start_tenant(environ, "studio_configs") + _start_tenant(environ, CMS_CONFIG_COLUMN) def _start_tenant(environ, config_key): @@ -239,7 +240,7 @@ def start_async_lms_tenant(sender, *args, **kwargs): # pylint: disable=unused-a Receiver that runs on the LMS async process to update the settings accordingly to the tenant. Read documentation of `_start_tenant` for more details. """ - _start_async_tenant(sender, "lms_configs") + _start_async_tenant(sender, LMS_CONFIG_COLUMN) def start_async_studio_tenant(sender, *args, **kwargs): # pylint: disable=unused-argument @@ -247,7 +248,7 @@ def start_async_studio_tenant(sender, *args, **kwargs): # pylint: disable=unuse Receiver that runs on the studio async process to update the settings accordingly to the tenant. Read documentation of `_start_tenant` for more details. """ - _start_async_tenant(sender, "studio_configs") + _start_async_tenant(sender, CMS_CONFIG_COLUMN) def _start_async_tenant(sender, config_key):