Skip to content

Commit

Permalink
Merge branch 'main' into task/GH-93-GH-142-GH-133-article-list-plugin…
Browse files Browse the repository at this point in the history
…s-and-styles--no-reverts
  • Loading branch information
wesleyboar committed Oct 7, 2021
2 parents 265fec0 + 666bf95 commit 7ffbd47
Show file tree
Hide file tree
Showing 50 changed files with 1,527 additions and 29 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ class OurModelThatUsesXxx(AbstractXxx):
# Replace error
# SEE: https://docs.djangoproject.com/en/2.2/ref/forms/validation/#raising-validationerror

# NOTE: The conditional `pass` is only to skip multi-field errors;
# single-field error skipping is unaffected by this logic;
# so it seems safe to always include this logic block
if len(err.messages) == 0:
pass
else:
if err.messages:
raise err
```

Expand Down
10 changes: 10 additions & 0 deletions taccsite_cms/contrib/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
TEXT_FOR_NESTED_PLUGIN_CONTENT_ADD = '\
<dl>\
<dt>To add {element},</dt>\
<dd>nest "{plugin_name}" plugin inside this plugin.</dd>\
<dt>To edit {element},</dt>\
<dd>edit existing nested "{plugin_name}" plugin.*</dd>\
</dl>\
<br />\
* If the existing content is from a plugin not nested within this one, then you should nest it inside this one instead.'

TEXT_FOR_NESTED_PLUGIN_CONTENT_SWAP = '\
<dl>\
<dt>To add {element},</dt>\
Expand Down
15 changes: 12 additions & 3 deletions taccsite_cms/contrib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ def add_view(self,request, form_url='', extra_context=None):
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _



# SEE: https://github.com/django-cms/djangocms-link/blob/3.0.0/djangocms_link/models.py#L48
def clean_for_abstract_link(model, self):
"""
Expand Down Expand Up @@ -235,7 +237,14 @@ def clean(self):
err.error_dict[field] = ValidationError(
_('Only one of External link or Internal link may be given.'), code='invalid')

if len(err.messages) == 0:
pass
else:
if len(err.messages):
raise err



# Get name of field from a given model
# SEE: https://stackoverflow.com/a/14498938/11817077
def get_model_field_name(model, field_name):
model_field_name = model._meta.get_field(field_name).verbose_name.title()

return model_field_name
Empty file.
66 changes: 66 additions & 0 deletions taccsite_cms/contrib/taccsite_blockquote/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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_offset.cms_plugins import get_direction_classname

from .models import TaccsiteBlockquote

@plugin_pool.register_plugin
class TaccsiteBlockquotePlugin(CMSPluginBase):
"""
Components > "Blockquote" Plugin
https://confluence.tacc.utexas.edu/x/FIEjCQ
"""
module = 'TACC Site'
model = TaccsiteBlockquote
name = _('Blockquote')
render_template = 'blockquote.html'

cache = True
text_enabled = True
allow_children = False

fieldsets = [
(None, {
'fields': (
'text',
'origin',
'use_cite',
)
}),
(_('Citation'), {
'classes': ('collapse',),
'fields': (
'cite_person',
('cite_text', 'cite_url'),
)
}),
(_('Layout'), {
'fields': (
'offset',
)
}),
(_('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([
's-blockquote',
get_direction_classname(instance.offset),
instance.attributes.get('class'),
])
instance.attributes['class'] = classes

return context
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 2.2.16 on 2021-06-22 14:09

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='TaccsiteBlockquote',
fields=[
('cmsplugin_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='taccsite_blockquote_taccsiteblockquote', serialize=False, to='cms.CMSPlugin')),
('text', models.TextField(default='', null=True, verbose_name='Quote')),
('origin', models.CharField(blank=True, help_text='The origin of the quote (i.e. citation, attribution) (e.g. author, source). This value is ignored if "Advanced origin" fields have data.', max_length=100)),
('use_cite', models.BooleanField(default=False, verbose_name='Use the "Citation" fields')),
('cite_person', models.CharField(blank=True, help_text='The author or speaker of the quote.', max_length=50, verbose_name='Author / Speaker')),
('cite_text', models.CharField(blank=True, help_text='Text for the source of the quote.', max_length=50, verbose_name='Source Text')),
('cite_url', models.CharField(blank=True, help_text='URL for the source of the quote.', max_length=255, verbose_name='Source URL')),
('offset', models.CharField(blank=True, choices=[('left', 'Left'), ('right', 'Right')], max_length=255)),
('attributes', djangocms_attributes_field.fields.AttributesField(default=dict)),
],
options={
'abstract': False,
},
bases=('cms.cmsplugin',),
),
]
Empty file.
59 changes: 59 additions & 0 deletions taccsite_cms/contrib/taccsite_blockquote/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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

from taccsite_cms.contrib.taccsite_offset.models import DIRECTION_CHOICES

class TaccsiteBlockquote(CMSPlugin):
"""
Components > "Blockquote" Model
https://confluence.tacc.utexas.edu/x/FIEjCQ
"""
text = models.TextField(
verbose_name=_('Quote'),
null=True,
default='',
)

origin = models.CharField(
help_text=_('The origin of the quote (i.e. citation, attribution) (e.g. author, source). This value is ignored if "Advanced origin" fields have data.'),
blank=True,
max_length=100,
)

use_cite = models.BooleanField(
verbose_name=_('Use the "Citation" fields'),
default=False,
)
cite_person = models.CharField(
verbose_name=_('Author / Speaker'),
help_text='The author or speaker of the quote.',
blank=True,
max_length=50,
)
cite_text = models.CharField(
verbose_name=_('Source Text'),
help_text=_('Text for the source of the quote.'),
blank=True,
max_length=50,
)
cite_url = models.CharField(
verbose_name=_('Source URL'),
help_text=_('URL for the source of the quote.'),
blank=True,
max_length=255,
)

offset = models.CharField(
choices=DIRECTION_CHOICES,
blank=True,
max_length=255,
)

attributes = fields.AttributesField()

def get_short_description(self):
return self.text
29 changes: 29 additions & 0 deletions taccsite_cms/contrib/taccsite_blockquote/templates/blockquote.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<figure {# class="s-blockquote" #}{{ instance.attributes_str }}>
<blockquote cite="{{ instance.cite_url }}">
<p>{{ instance.text }}</p>
</blockquote>
{% if instance.use_cite %}
<figcaption>

{% if instance.cite_person %}
{{ instance.cite_person }}{% if instance.cite_text %},{% endif %}
{% endif %}

{% if instance.cite_text and instance.cite_url %}
<cite><a href="{{ instance.cite_url }}" target="_blank">
{{ instance.cite_text }}
</a></cite>
{% endif %}
{% if instance.cite_text and not instance.cite_url %}
<cite>
{{ instance.cite_text }}
</cite>
{% endif %}

</figcaption>
{% elif instance.origin %}

<figcaption>{{ instance.origin }}</figcaption>

{% endif %}
</figure>
Empty file.
108 changes: 108 additions & 0 deletions taccsite_cms/contrib/taccsite_callout/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from django.utils.translation import gettext_lazy as _

from djangocms_link.cms_plugins import LinkPlugin

from taccsite_cms.contrib.helpers import (
concat_classnames,
get_model_field_name
)
from taccsite_cms.contrib.constants import TEXT_FOR_NESTED_PLUGIN_CONTENT_SWAP

from .models import TaccsiteCallout




# Constants

RESIZE_FIGURE_FIELD_NAME = get_model_field_name(TaccsiteCallout, 'resize_figure_to_fit')



# Plugin

@plugin_pool.register_plugin
class TaccsiteCalloutPlugin(LinkPlugin):
"""
Components > "Callout" Plugin
https://confluence.tacc.utexas.edu/x/EiIFDg
"""
module = 'TACC Site'
model = TaccsiteCallout
name = _('Callout')
render_template = 'callout.html'
def get_render_template(self, context, instance, placeholder):
return self.render_template

cache = True
text_enabled = False
allow_children = True
# GH-91: Enable this limitation
# parent_classes = [
# 'SectionPlugin'
# ]
child_classes = [
'PicturePlugin'
]
max_children = 1

fieldsets = [
(None, {
'fields': (
'title', 'description',
),
}),
(_('Link'), {
'fields': (
('external_link', 'internal_link'),
('anchor', 'target'),
)
}),
(_('Image'), {
'classes': ('collapse',),
'description': TEXT_FOR_NESTED_PLUGIN_CONTENT_SWAP.format(
element='an image',
plugin_name='Image'
) + '\
<br />\
If image disappears while editing, then reload the page to reload the image.',
'fields': (),
}),
(_('Advanced settings'), {
'classes': ('collapse',),
'description': 'Only use the "' + RESIZE_FIGURE_FIELD_NAME + '" in emergencies. It is preferable to resize the image. <small>When the "Advanced settings" field "' + RESIZE_FIGURE_FIELD_NAME + '" is checked, the image may disappear after saving this plugin (because of a JavaScript race condition). Using a server-side solution would eliminate this caveat.</small>',
'fields': (
'resize_figure_to_fit',
'attributes',
)
}),
]

# Render

def render(self, context, instance, placeholder):
context = super().render(context, instance, placeholder)
request = context['request']
has_child_plugin = {}

# To identify child plugins
for plugin_instance in instance.child_plugin_instances:
if (type(plugin_instance).__name__ == 'Picture'):
has_child_plugin['image'] = True
context.update({ 'image_plugin': plugin_instance })

classes = concat_classnames([
'c-callout',
'c-callout--has-figure' if has_child_plugin.get('image') else '',
'c-callout--is-link' if instance.get_link() else '',
instance.attributes.get('class'),
])
instance.attributes['class'] = classes

context.update({
'link_url': instance.get_link(),
'link_target': instance.target
})
return context
Loading

0 comments on commit 7ffbd47

Please sign in to comment.