Skip to content

Commit

Permalink
Remove cache from dynamic_theme_context and edly_app_context (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
burhandodhy authored Jun 11, 2020
1 parent cf61613 commit f1fb578
Showing 1 changed file with 42 additions and 56 deletions.
98 changes: 42 additions & 56 deletions openedx/features/edly/context_processor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from math import floor

from django.conf import settings
from django.core.cache import cache
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers

CACHE_NAME = 'context_processor.dynamic_theming'
EDLY_CACHE_NAME = 'context_processor.edly_app'
DEFAULT_SERVICES_NOTIFICATIONS_COOKIE_EXPIRY = 180 # value in seconds
DEFAULT_EDLY_CACHE_TIMEOUT = 900 # value in seconds
DEFAULT_COLOR_DICT = {
'primary': '#3E99D4',
'secondary': '#1197EA'
Expand All @@ -27,20 +23,16 @@ def dynamic_theming_context(request): # pylint: disable=unused-argument
"""
Context processor responsible for dynamic theming.
"""
theming_context = cache.get(CACHE_NAME)
cache_timeout = configuration_helpers.get_value('EDLY_CACHE_TIMEOUT', DEFAULT_EDLY_CACHE_TIMEOUT)
if not theming_context:
theming_context = {}
theming_context.update(
{'edly_colors_config': get_theme_colors()}
)
theming_context.update(
{'edly_fonts_config': configuration_helpers.get_dict('FONTS', DEFAULT_FONTS_DICT)}
)
theming_context.update(
{'edly_branding_config': configuration_helpers.get_dict('BRANDING', DEFAULT_BRANDING_DICT)}
)
cache.set(CACHE_NAME, theming_context, cache_timeout)
theming_context = {}
theming_context.update(
{'edly_colors_config': get_theme_colors()}
)
theming_context.update(
{'edly_fonts_config': configuration_helpers.get_dict('FONTS', DEFAULT_FONTS_DICT)}
)
theming_context.update(
{'edly_branding_config': configuration_helpers.get_dict('BRANDING', DEFAULT_BRANDING_DICT)}
)

return theming_context

Expand All @@ -49,48 +41,42 @@ def edly_app_context(request): # pylint: disable=unused-argument
"""
Context processor responsible for edly.
"""
edly_context = cache.get(EDLY_CACHE_NAME)
cache_timeout = configuration_helpers.get_value('EDLY_CACHE_TIMEOUT', DEFAULT_EDLY_CACHE_TIMEOUT)

if not edly_context:
edly_context = {}
panel_services_notifications_url = ''
edly_context = {}
panel_services_notifications_url = ''

panel_notifications_base_url = configuration_helpers.get_value('PANEL_NOTIFICATIONS_BASE_URL', '')
if panel_notifications_base_url:
panel_services_notifications_url = '{base_url}/api/v1/all_services_notifications/'.format(
base_url=panel_notifications_base_url
)

edly_context.update(
{
'edly_copyright_text': configuration_helpers.get_value('EDLY_COPYRIGHT_TEXT')
}
panel_notifications_base_url = configuration_helpers.get_value('PANEL_NOTIFICATIONS_BASE_URL', '')
if panel_notifications_base_url:
panel_services_notifications_url = '{base_url}/api/v1/all_services_notifications/'.format(
base_url=panel_notifications_base_url
)

edly_context.update(
{
'services_notifications_url': panel_services_notifications_url
}
)

edly_context.update(
{
'session_cookie_domain': configuration_helpers.get_value(
'SESSION_COOKIE_DOMAIN', settings.SESSION_COOKIE_DOMAIN
)
}
)

edly_context.update(
{
'services_notifications_cookie_expiry': configuration_helpers.get_value(
'SERVICES_NOTIFICATIONS_COOKIE_EXPIRY', DEFAULT_SERVICES_NOTIFICATIONS_COOKIE_EXPIRY
)
}
)
edly_context.update(
{
'edly_copyright_text': configuration_helpers.get_value('EDLY_COPYRIGHT_TEXT')
}
)

edly_context.update(
{
'services_notifications_url': panel_services_notifications_url
}
)

edly_context.update(
{
'session_cookie_domain': configuration_helpers.get_value(
'SESSION_COOKIE_DOMAIN', settings.SESSION_COOKIE_DOMAIN
)
}
)

cache.set(EDLY_CACHE_NAME, edly_context, cache_timeout)
edly_context.update(
{
'services_notifications_cookie_expiry': configuration_helpers.get_value(
'SERVICES_NOTIFICATIONS_COOKIE_EXPIRY', DEFAULT_SERVICES_NOTIFICATIONS_COOKIE_EXPIRY
)
}
)

return edly_context

Expand Down

0 comments on commit f1fb578

Please sign in to comment.