Skip to content

Commit

Permalink
GH-75: Data List - Plugin: Support Label Link
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleyboar committed Aug 6, 2021
1 parent 459f839 commit 1f1c4ec
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion taccsite_cms/contrib/taccsite_data_list/TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# To Do

- [ ] Add missing link feature to "Data List Item" plugin.
- [ ] Support label that is link within text. → GH-306
11 changes: 9 additions & 2 deletions taccsite_cms/contrib/taccsite_data_list/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from taccsite_cms.contrib.helpers import concat_classnames
from taccsite_cms.contrib.taccsite_offset.cms_plugins import get_direction_classname

from taccsite_cms.contrib.helpers import AbstractMaxChildrenPlugin

from .models import TaccsiteDataList, TaccsiteDataListItem
from .constants import ORIENTATION_DICT, TYPE_STYLE_DICT, DENSITY_DICT

Expand All @@ -21,7 +23,7 @@ def get_classname(dict, value):
# Plugins

@plugin_pool.register_plugin
class TaccsiteDataListPlugin(CMSPluginBase):
class TaccsiteDataListPlugin(CMSPluginBase, AbstractMaxChildrenPlugin):
"""
Components > "Data List" Plugin
https://confluence.tacc.utexas.edu/x/EiIFDg
Expand Down Expand Up @@ -91,12 +93,17 @@ class TaccsiteDataListItemPlugin(CMSPluginBase):

cache = True
text_enabled = False
allow_children = False
allow_children = True
child_classes = [
'LinkPlugin'
]
max_children = 1 # Only a label until we know what value will need

fieldsets = [
(None, {
'fields': (
('key', 'value'),
('use_plugin_as_key'),
)
})
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.16 on 2021-08-06 04:17
# Generated by Django 2.2.16 on 2021-08-06 20:17

from django.db import migrations, models
import django.db.models.deletion
Expand Down Expand Up @@ -33,8 +33,9 @@ class Migration(migrations.Migration):
name='TaccsiteDataListItem',
fields=[
('cmsplugin_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='taccsite_data_list_taccsitedatalistitem', serialize=False, to='cms.CMSPlugin')),
('key', models.CharField(help_text='The label for the item value.', max_length=50, verbose_name='Label')),
('key', models.CharField(help_text='A label for the data value. To create a link, add a child plugin.', max_length=50, verbose_name='Label')),
('value', models.CharField(help_text='The data value.', max_length=100, verbose_name='Value')),
('use_plugin_as_key', models.BooleanField(default=True, help_text='If a child plugin is added, and this option is checked, then the child plugin will be used (not the Label field text).', verbose_name='Support child plugin for Label')),
('attributes', djangocms_attributes_field.fields.AttributesField(default=dict)),
],
options={
Expand Down
7 changes: 6 additions & 1 deletion taccsite_cms/contrib/taccsite_data_list/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TaccsiteDataListItem(CMSPlugin):
"""
key = models.CharField(
verbose_name=_('Label'),
help_text=_('The label for the item value.'),
help_text=_('A label for the data value. To create a link, add a child plugin.'),
blank=False,
max_length=50,
)
Expand All @@ -77,6 +77,11 @@ class TaccsiteDataListItem(CMSPlugin):
blank=False,
max_length=100,
)
use_plugin_as_key = models.BooleanField(
verbose_name=_('Support child plugin for Label'),
help_text=_('If a child plugin is added, and this option is checked, then the child plugin will be used (not the Label field text).'),
default=True,
)

attributes = fields.AttributesField()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{% load cms_tags %}

{% if parent_plugin_instance.type_style == 'dlist' %}

<dt class="c-data-list__key">{{ instance.key }}</dt>
<dt class="c-data-list__key">
{% include "./data_list_item_key.html" %}
</dt>
<dd class="c-data-list__value">{{ instance.value }}</dd>

{% elif parent_plugin_instance.type_style == 'table' %}

<tr>
<th class="c-data-list__key">{{ instance.key }}</th>
<th class="c-data-list__key">
{% include "./data_list_item_key.html" %}
</th>
<td class="c-data-list__value">{{ instance.value }}</td>
</tr>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% load cms_tags %}

{% if instance.use_plugin_as_key and instance.child_plugin_instances|length %}
{% for plugin_instance in instance.child_plugin_instances %}
{% render_plugin plugin_instance %}
{% endfor %}
{% else %}
{{ instance.key }}
{% endif %}

0 comments on commit 1f1c4ec

Please sign in to comment.