From 37228adb554157ed6b3070a382e6bc7e3b8c79aa Mon Sep 17 00:00:00 2001 From: Wesley Bomar Date: Tue, 22 Jun 2021 20:19:16 -0500 Subject: [PATCH 01/56] GH-93: Article List Plugin --- .../contrib/taccsite_article_list/__init__.py | 0 .../taccsite_article_list/cms_plugins.py | 69 ++++++++++++ .../migrations/0001_initial.py | 33 ++++++ .../migrations/__init__.py | 0 .../contrib/taccsite_article_list/models.py | 104 ++++++++++++++++++ .../templates/article_list.html | 19 ++++ taccsite_cms/settings.py | 1 + 7 files changed, 226 insertions(+) create mode 100644 taccsite_cms/contrib/taccsite_article_list/__init__.py create mode 100644 taccsite_cms/contrib/taccsite_article_list/cms_plugins.py create mode 100644 taccsite_cms/contrib/taccsite_article_list/migrations/0001_initial.py create mode 100644 taccsite_cms/contrib/taccsite_article_list/migrations/__init__.py create mode 100644 taccsite_cms/contrib/taccsite_article_list/models.py create mode 100644 taccsite_cms/contrib/taccsite_article_list/templates/article_list.html diff --git a/taccsite_cms/contrib/taccsite_article_list/__init__.py b/taccsite_cms/contrib/taccsite_article_list/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/taccsite_cms/contrib/taccsite_article_list/cms_plugins.py b/taccsite_cms/contrib/taccsite_article_list/cms_plugins.py new file mode 100644 index 000000000..4156971f9 --- /dev/null +++ b/taccsite_cms/contrib/taccsite_article_list/cms_plugins.py @@ -0,0 +1,69 @@ +from cms.plugin_base import CMSPluginBase +from cms.plugin_pool import plugin_pool +from django.utils.translation import gettext_lazy as _ + +from taccsite_cms.contrib.helpers import concat_classnames + +from taccsite_cms.contrib.taccsite_article_list.models import ( + get_layout_classname, get_content_classname, get_style_classname +) + +from .models import TaccsiteArticleList + +@plugin_pool.register_plugin +class TaccsiteArticleListPlugin(CMSPluginBase): + """ + Components > "Article List" Plugin + https://confluence.tacc.utexas.edu/x/FIEjCQ + """ + module = 'TACC Site' + model = TaccsiteArticleList + name = _('Article List') + render_template = 'article_list.html' + + cache = True + text_enabled = False + allow_children = True + # TODO: Create taccsite_article_preview + # child_classes = ['TaccsiteArticlePreviewPlugin'] + + fieldsets = [ + (None, { + 'fields': ( + 'header_title_text', + 'footer_link_text', + ) + }), + (_('Options'), { + 'fields': ( + 'content_type', + ('layout_type', 'style_type') + ) + }), + (_('Advanced settings'), { + 'classes': ('collapse',), + 'fields': ( + 'attributes', + ) + }), + ] + + # Render + + def render(self, context, instance, placeholder): + context = super().render(context, instance, placeholder) + request = context['request'] + + classes = concat_classnames([ + 'c-article-list', + get_layout_classname(instance.layout_type), + get_content_classname(instance.content_type), + get_style_classname(instance.style_type), + instance.attributes.get('class'), + ]) + instance.attributes['class'] = classes + + # for plugin_instance in instance.child_plugin_instances: + # plugin_instance.attributes['class'] += 'c-article-list__item' + + return context diff --git a/taccsite_cms/contrib/taccsite_article_list/migrations/0001_initial.py b/taccsite_cms/contrib/taccsite_article_list/migrations/0001_initial.py new file mode 100644 index 000000000..bf7f26a50 --- /dev/null +++ b/taccsite_cms/contrib/taccsite_article_list/migrations/0001_initial.py @@ -0,0 +1,33 @@ +# Generated by Django 2.2.16 on 2021-06-23 01:21 + +from django.db import migrations, models +import django.db.models.deletion +import djangocms_attributes_field.fields + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('cms', '0022_auto_20180620_1551'), + ] + + operations = [ + migrations.CreateModel( + name='TaccsiteArticleList', + fields=[ + ('cmsplugin_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='taccsite_article_list_taccsitearticlelist', serialize=False, to='cms.CMSPlugin')), + ('header_title_text', models.CharField(blank=True, help_text='The title at the top of the list.', max_length=100)), + ('footer_link_text', models.CharField(blank=True, help_text='The "See All ..." link at the bottom of the list.', max_length=100)), + ('content_type', models.CharField(blank=True, choices=[('news', 'News'), ('docs', 'Documents'), ('allocs', 'Allocations'), ('events', 'Events')], max_length=255)), + ('layout_type', models.CharField(blank=True, choices=[('always-rows-N--even', '(always) N Even Rows'), ('widest-cols-2--even', '(at widest) 2 Equal Columns'), ('widest-cols-2--wide-narr', '(at widest) 2 Cols: 1 Wide, 1 Narrow'), ('widest-cols-2--narr-wide', '(at widest) 2 Cols: 1 Narrow, 1 Wide'), ('widest-cols-3--even', '(at widest) 3 Equal Columns')], default='always-rows-N--even', max_length=255)), + ('style_type', models.CharField(blank=True, choices=[('divided', 'Dividers Between Articles')], max_length=255)), + ('attributes', djangocms_attributes_field.fields.AttributesField(default=dict)), + ], + options={ + 'abstract': False, + }, + bases=('cms.cmsplugin',), + ), + ] diff --git a/taccsite_cms/contrib/taccsite_article_list/migrations/__init__.py b/taccsite_cms/contrib/taccsite_article_list/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/taccsite_cms/contrib/taccsite_article_list/models.py b/taccsite_cms/contrib/taccsite_article_list/models.py new file mode 100644 index 000000000..5383e7c5f --- /dev/null +++ b/taccsite_cms/contrib/taccsite_article_list/models.py @@ -0,0 +1,104 @@ +from cms.models.pluginmodel import CMSPlugin +from django.utils.translation import gettext_lazy as _ + +from django.db import models + +from djangocms_attributes_field import fields + +# Constants + +CONTENT_CHOICES = ( + ('news', _('News')), + ('docs', _('Documents')), + ('allocs', _('Allocations')), + ('events', _('Events')), +) +LAYOUT_CHOICES = ( + ('always-rows-N--even', _('(always) N Even Rows')), + ('widest-cols-2--even', _('(at widest) 2 Equal Columns')), + ('widest-cols-2--wide-narr', _('(at widest) 2 Cols: 1 Wide, 1 Narrow')), + ('widest-cols-2--narr-wide', _('(at widest) 2 Cols: 1 Narrow, 1 Wide')), + ('widest-cols-3--even', _('(at widest) 3 Equal Columns')), +) +STYLE_CHOICES = ( + ('divided', _('Dividers Between Articles')), +) + +# Helpers + +def get_content_classname(value): + """Get content class based on value.""" + + # TODO: Couple this map to TYPE_CHOICES + switcher = { + 'news': 's-article-list--news', + 'docs': 's-article-list--links', + 'allocs': 's-article-list--allocations', + 'events': 's-article-list--events', + } + + return switcher.get(value, '') + +def get_layout_classname(value): + """Get layout class based on value.""" + + # TODO: Couple this map to LAYOUT_CHOICES + switcher = { + 'widest-cols-2--even': 'c-article-list--layout-a', + 'widest-cols-2--wide-narr': 'c-article-list--layout-b', + 'widest-cols-2--narr-wide': 'c-article-list--layout-c', + 'widest-cols-3--even': 'c-article-list--layout-d', + 'always-rows-N--even': 'c-article-list--layout-e', + } + + return switcher.get(value, '') + +def get_style_classname(value): + """Get style class based on value.""" + + # TODO: Couple this map to STYLE_CHOICES + switcher = { + 'divided': 'c-article-list--style-divided', + } + + return switcher.get(value, '') + +# Models + +class TaccsiteArticleList(CMSPlugin): + """ + Components > "Article List" Model + https://confluence.tacc.utexas.edu/x/FIEjCQ + """ + header_title_text = models.CharField( + help_text='The title at the top of the list.', + blank=True, + max_length=100, + ) + footer_link_text = models.CharField( + help_text='The "See All ..." link at the bottom of the list.', + blank=True, + max_length=100, + ) + + content_type = models.CharField( + choices=CONTENT_CHOICES, + blank=True, + max_length=255, + ) + layout_type = models.CharField( + choices=LAYOUT_CHOICES, + default=LAYOUT_CHOICES[0][0], + blank=True, + max_length=255, + ) + style_type = models.CharField( + choices=STYLE_CHOICES, + blank=True, + max_length=255, + ) + + attributes = fields.AttributesField() + + def get_short_description(self): + return self.header_title_text diff --git a/taccsite_cms/contrib/taccsite_article_list/templates/article_list.html b/taccsite_cms/contrib/taccsite_article_list/templates/article_list.html new file mode 100644 index 000000000..7fa55bc3e --- /dev/null +++ b/taccsite_cms/contrib/taccsite_article_list/templates/article_list.html @@ -0,0 +1,19 @@ +{% load cms_tags %} + +
+

+ {{ instance.header_title_text }} +

+ {% for plugin_instance in instance.child_plugin_instances %} + {#
#} + {% render_plugin plugin_instance %} + {% endfor %} + +
diff --git a/taccsite_cms/settings.py b/taccsite_cms/settings.py index 4b548fb00..538fd4672 100644 --- a/taccsite_cms/settings.py +++ b/taccsite_cms/settings.py @@ -243,6 +243,7 @@ def getsecrets(): 'taccsite_cms.contrib.taccsite_sample', 'taccsite_cms.contrib.taccsite_blockquote', 'taccsite_cms.contrib.taccsite_offset', + 'taccsite_cms.contrib.taccsite_article_list', ] # Convert list of paths to list of dotted module names From b510c757342a8d4d978e73a03f6897baf31a41a9 Mon Sep 17 00:00:00 2001 From: Wesley Bomar Date: Tue, 22 Jun 2021 20:20:20 -0500 Subject: [PATCH 02/56] GH-93: Polish Existing Plugins --- .../contrib/taccsite_blockquote/cms_plugins.py | 5 ++--- taccsite_cms/contrib/taccsite_blockquote/models.py | 2 -- .../taccsite_blockquote/templates/blockquote.html | 2 +- taccsite_cms/contrib/taccsite_offset/cms_plugins.py | 4 +--- taccsite_cms/contrib/taccsite_offset/models.py | 10 ++++------ .../contrib/taccsite_offset/templates/offset.html | 6 +++--- taccsite_cms/contrib/taccsite_sample/cms_plugins.py | 1 + 7 files changed, 12 insertions(+), 18 deletions(-) diff --git a/taccsite_cms/contrib/taccsite_blockquote/cms_plugins.py b/taccsite_cms/contrib/taccsite_blockquote/cms_plugins.py index 9a9aef492..83cd1bada 100644 --- a/taccsite_cms/contrib/taccsite_blockquote/cms_plugins.py +++ b/taccsite_cms/contrib/taccsite_blockquote/cms_plugins.py @@ -1,5 +1,3 @@ -# SEE: https://github.com/django-cms/djangocms-bootstrap4/blob/2.0.0/djangocms_bootstrap4/contrib/bootstrap4_content/cms_plugins.py#L41 - from cms.plugin_base import CMSPluginBase from cms.plugin_pool import plugin_pool from django.utils.translation import gettext_lazy as _ @@ -21,8 +19,9 @@ class TaccsiteBlockquotePlugin(CMSPluginBase): name = _('Blockquote') render_template = 'blockquote.html' - cache = False + cache = True text_enabled = True + allow_children = False fieldsets = [ (None, { diff --git a/taccsite_cms/contrib/taccsite_blockquote/models.py b/taccsite_cms/contrib/taccsite_blockquote/models.py index 1345c228d..9313b15fd 100644 --- a/taccsite_cms/contrib/taccsite_blockquote/models.py +++ b/taccsite_cms/contrib/taccsite_blockquote/models.py @@ -1,5 +1,3 @@ -# SEE: https://github.com/django-cms/djangocms-bootstrap4/blob/2.0.0/djangocms_bootstrap4/contrib/bootstrap4_content/models.py - from cms.models.pluginmodel import CMSPlugin from django.utils.translation import gettext_lazy as _ diff --git a/taccsite_cms/contrib/taccsite_blockquote/templates/blockquote.html b/taccsite_cms/contrib/taccsite_blockquote/templates/blockquote.html index 9e66c7622..71fea29cd 100644 --- a/taccsite_cms/contrib/taccsite_blockquote/templates/blockquote.html +++ b/taccsite_cms/contrib/taccsite_blockquote/templates/blockquote.html @@ -1,4 +1,4 @@ -
+

{{ instance.text }}

diff --git a/taccsite_cms/contrib/taccsite_offset/cms_plugins.py b/taccsite_cms/contrib/taccsite_offset/cms_plugins.py index d780e9d9d..c2d1da73e 100644 --- a/taccsite_cms/contrib/taccsite_offset/cms_plugins.py +++ b/taccsite_cms/contrib/taccsite_offset/cms_plugins.py @@ -1,5 +1,3 @@ -# SEE: https://github.com/django-cms/djangocms-bootstrap4/blob/2.0.0/djangocms_bootstrap4/contrib/bootstrap4_content/cms_plugins.py#L41 - from cms.plugin_base import CMSPluginBase from cms.plugin_pool import plugin_pool @@ -20,7 +18,7 @@ class TaccsiteOffsetPlugin(CMSPluginBase): name = _('Offset Content') render_template = 'offset.html' - cache = False + cache = True text_enabled = False allow_children = True diff --git a/taccsite_cms/contrib/taccsite_offset/models.py b/taccsite_cms/contrib/taccsite_offset/models.py index beb905351..149941b80 100644 --- a/taccsite_cms/contrib/taccsite_offset/models.py +++ b/taccsite_cms/contrib/taccsite_offset/models.py @@ -1,5 +1,3 @@ -# SEE: https://github.com/django-cms/djangocms-bootstrap4/blob/2.0.0/djangocms_bootstrap4/contrib/bootstrap4_content/models.py - from cms.models.pluginmodel import CMSPlugin from django.db import models @@ -17,16 +15,16 @@ # Helpers -def get_direction_classname(offset): - """Get offset content class based on standard offset value.""" +def get_direction_classname(value): + """Get direction class based on value.""" - # HELP: Should we limit input by coupling this map to DIRECTION_CHOICES? + # TODO: Couple this map to DIRECTION_CHOICES switcher = { 'right': 'o-offset-content--right', 'left': 'o-offset-content--left' } - return switcher.get(offset, '') + return switcher.get(value, '') # Models 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 %} -