diff --git a/taccsite_cms/contrib/taccsite_offset/cms_plugins.py b/taccsite_cms/contrib/taccsite_offset/cms_plugins.py index a29b4f558..607cb05d8 100644 --- a/taccsite_cms/contrib/taccsite_offset/cms_plugins.py +++ b/taccsite_cms/contrib/taccsite_offset/cms_plugins.py @@ -5,7 +5,17 @@ from taccsite_cms.contrib.helpers import concat_classnames -from .models import TaccsiteOffset, get_direction_classname +from .models import TaccsiteOffset, DIRECTION_DICT + +# Helpers + +# FAQ: This exists to retireve classnames via consistently-named functions +# SEE: taccsite_cms.contrib.taccsite_static_article_list.cms_plugins +def get_direction_classname(value): + """Get direction class based on value.""" + return DIRECTION_DICT.get(value, {}).get('classname') + +# Plugins @plugin_pool.register_plugin class TaccsiteOffsetPlugin(CMSPluginBase): @@ -18,7 +28,7 @@ class TaccsiteOffsetPlugin(CMSPluginBase): name = _('Offset Content') render_template = 'offset.html' - cache = False + cache = True text_enabled = False allow_children = True @@ -37,7 +47,6 @@ class TaccsiteOffsetPlugin(CMSPluginBase): ] # Render - def render(self, context, instance, placeholder): context = super().render(context, instance, placeholder) request = context['request'] diff --git a/taccsite_cms/contrib/taccsite_offset/models.py b/taccsite_cms/contrib/taccsite_offset/models.py index 3904e601a..ccf4abc6d 100644 --- a/taccsite_cms/contrib/taccsite_offset/models.py +++ b/taccsite_cms/contrib/taccsite_offset/models.py @@ -5,30 +5,24 @@ from djangocms_attributes_field import fields - - -# Constants - -DIRECTION_CHOICES = ( - ('left', _('Left')), - # ('center', _('Center')), # GH-66: Support centered offset content - ('right', _('Right')), -) +from taccsite_cms.contrib.helpers import get_choices -# Helpers - -def get_direction_classname(offset): - """Get offset content class based on standard offset value.""" - - # HELP: Should we limit input by coupling this map to DIRECTION_CHOICES? - switcher = { - 'right': 'o-offset-content--right', - 'left': 'o-offset-content--left' - } +# Constants - return switcher.get(offset, '') +# TODO: Consider using an Enum (and an Abstract Enum with `get_choices` method) +DIRECTION_DICT = { + 'left': { + 'classname': 'o-offset-content--left', + 'description': 'Left', + }, + 'right': { + 'classname': 'o-offset-content--right', + 'description': 'Right', + }, +} +DIRECTION_CHOICES = get_choices(DIRECTION_DICT) diff --git a/taccsite_cms/contrib/taccsite_offset/templates/offset.html b/taccsite_cms/contrib/taccsite_offset/templates/offset.html index 98edf0c42..583ca7ad0 100644 --- a/taccsite_cms/contrib/taccsite_offset/templates/offset.html +++ b/taccsite_cms/contrib/taccsite_offset/templates/offset.html @@ -1,7 +1,7 @@ {% load cms_tags %} -{{ instance.text }}