Skip to content

Commit

Permalink
refactor: store config column names in constants
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Jul 5, 2023
1 parent f786744 commit 9960f0f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions eox_tenant/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 4 additions & 2 deletions eox_tenant/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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]),
}
Expand Down
1 change: 1 addition & 0 deletions eox_tenant/receivers_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions eox_tenant/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -162,15 +163,15 @@ 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
"""
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):
Expand Down Expand Up @@ -239,15 +240,15 @@ 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
"""
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):
Expand Down

0 comments on commit 9960f0f

Please sign in to comment.