Skip to content

Commit

Permalink
Merge branch 'task/GH-83-callout-element' into site/frontera/task/GH-…
Browse files Browse the repository at this point in the history
…83-callout-element--GH-321-resize-callout-image
  • Loading branch information
wesleyboar committed Aug 24, 2021
2 parents ab13f49 + 5059e02 commit c1f01ee
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 14 deletions.
10 changes: 10 additions & 0 deletions taccsite_cms/contrib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,13 @@ def clean(self):
pass
else:
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
24 changes: 19 additions & 5 deletions taccsite_cms/contrib/taccsite_callout/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@

from djangocms_link.cms_plugins import LinkPlugin

from taccsite_cms.contrib.helpers import concat_classnames
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):
"""
Expand Down Expand Up @@ -53,14 +67,14 @@ def get_render_template(self, context, instance, placeholder):
plugin_name='Image'
) + '\
<br />\
When the image resize field is checked, the image may disappear after saving this plugin. Reload the page to reload the image.',
'fields': (
'resize_figure_to_fit',
),
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',
)
}),
Expand Down
19 changes: 16 additions & 3 deletions taccsite_cms/contrib/taccsite_callout/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
# Generated by Django 2.2.16 on 2021-08-20 23:53
# Generated by Django 2.2.16 on 2021-08-24 13:03

from django.db import migrations, models
import django.db.models.deletion
import djangocms_attributes_field.fields
import djangocms_link.validators
import filer.fields.file


class Migration(migrations.Migration):

initial = True
replaces = [('taccsite_callout', '0001_initial'), ('taccsite_callout', '0003_auto_20210823_1902')]

dependencies = [
('filer', '0012_file_mime_type'),
('cms', '0022_auto_20180620_1551'),
]

operations = [
migrations.CreateModel(
name='TaccsiteCallout',
fields=[
('cmsplugin_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='taccsite_callout_taccsitecallout', serialize=False, to='cms.CMSPlugin')),
('cmsplugin_ptr', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='taccsite_callout_taccsitecallout', serialize=False, to='cms.CMSPlugin')),
('title', models.CharField(blank=True, help_text='A heading for the callout.', max_length=100, verbose_name='Title')),
('description', models.CharField(blank=True, help_text='A paragraph for the callout.', max_length=200, verbose_name='Description')),
('resize_figure_to_fit', models.BooleanField(default=True, help_text='Make image shorter or taller to match the height of text beside it.', verbose_name='Resize any image to fit')),
('attributes', djangocms_attributes_field.fields.AttributesField(default=dict)),
('anchor', models.CharField(blank=True, help_text='Appends the value only after the internal or external link. Do <em>not</em> include a preceding "#" symbol.', max_length=255, verbose_name='Anchor')),
('external_link', models.CharField(blank=True, help_text='Provide a link to an external source.', max_length=2040, validators=[djangocms_link.validators.IntranetURLValidator(intranet_host_re=None)], verbose_name='External link')),
('file_link', filer.fields.file.FilerFileField(blank=True, help_text='If provided links a file from the filer app.', null=True, on_delete=django.db.models.deletion.SET_NULL, to='filer.File', verbose_name='File link')),
('internal_link', models.ForeignKey(blank=True, help_text='If provided, overrides the external link.', null=True, on_delete=django.db.models.deletion.SET_NULL, to='cms.Page', verbose_name='Internal link')),
('mailto', models.EmailField(blank=True, max_length=255, verbose_name='Email address')),
('name', models.CharField(blank=True, max_length=255, verbose_name='Display name')),
('phone', models.CharField(blank=True, max_length=255, verbose_name='Phone')),
('target', models.CharField(blank=True, choices=[('_blank', 'Open in new window'), ('_self', 'Open in same window'), ('_parent', 'Delegate to parent'), ('_top', 'Delegate to top')], max_length=255, verbose_name='Target')),
('template', models.CharField(choices=[('default', 'Default')], default='default', max_length=255, verbose_name='Template')),
],
options={
'abstract': False,
Expand Down
8 changes: 4 additions & 4 deletions taccsite_cms/contrib/taccsite_callout/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ class TaccsiteCallout(AbstractLink):
title = models.CharField(
verbose_name=_('Title'),
help_text=_('A heading for the callout.'),
blank=True,
blank=False,
max_length=100,
)
description = models.CharField(
verbose_name=_('Description'),
help_text=_('A paragraph for the callout.'),
blank=True,
blank=False,
max_length=200,
)

resize_figure_to_fit = models.BooleanField(
verbose_name=_('Resize any image to fit'),
help_text=_('Make image shorter or taller to match the height of text beside it.'),
blank=False,
default=True
default=False
)

attributes = fields.AttributesField()
Expand All @@ -41,7 +41,7 @@ def get_short_description(self):

# Parent

link_is_optional = True
link_is_optional = False

class Meta:
abstract = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ Styles that allow visible link hover for article lists.
%x-article-link-stretch - Stretch link to cover container
%x-article-link-hover - Give link a hover state
%x-article-link-hover--gapless - Make link hover state fix gapless layout
%x-article-link-active - Give link an active (click, enter) state
Styleguide Tools.ExtendsAndMixins.ArticleLink
*/

/* WARNING: A link ancestor must have its `position` set (not to static) */

/* Expand link to cover container */
/* To expand link to cover container */
.x-article-link-stretch,
%x-article-link-stretch {
position: absolute;
height: 100%;
Expand All @@ -26,7 +28,8 @@ Styleguide Tools.ExtendsAndMixins.ArticleLink
overflow: hidden;
}

/* To give link hover state feedback */
/* To give link state (pseudo-class) feedback */
.x-article-link-hover,
%x-article-link-hover {
outline: 1px solid var(--global-color-accent--normal);
}
Expand All @@ -35,3 +38,8 @@ Styleguide Tools.ExtendsAndMixins.ArticleLink
%x-article-link-active {
outline: 1px dotted var(--global-color-accent--normal);
}

/* To give link active state feedback */
%x-article-link-active {
outline: 1px dotted var(--global-color-accent--normal);
}

0 comments on commit c1f01ee

Please sign in to comment.