Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with missed link attributes for 2 version #407

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmsplugin_cascade/generic/text_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ class TextImagePlugin(LinkPluginBase):
allow_children = False
require_parent = False
form = type('TextImageForm', (LinkFormMixin, TextImageFormMixin), {'require_link': False})
html_tag_attributes = LinkPluginBase.html_tag_attributes
html_tag_attributes.update({'image_title': 'title', 'alt_tag': 'alt'})
html_tag_attributes = {'image_title': 'title', 'alt_tag': 'alt'}

class Media:
js = ['admin/js/jquery.init.js', 'cascade/js/admin/textimageplugin.js']
Expand Down
2 changes: 1 addition & 1 deletion cmsplugin_cascade/link/plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LinkPluginBase(CascadePluginBase):
require_parent = False
ring_plugin = 'LinkPluginBase'
raw_id_fields = ['download_file']
html_tag_attributes = {'title': 'title', 'target': 'target'}
html_tag_attributes = {'link_title': 'title', 'link_target': 'target'}

class Media:
css = {'all': ['cascade/css/admin/linkplugin.css']}
Expand Down
4 changes: 2 additions & 2 deletions cmsplugin_cascade/templates/cascade/plugins/simpleicon.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
{% spaceless %}
{% with instance_link=instance.link tag_type=instance.tag_type css_classes=instance.css_classes inline_styles=instance.inline_styles %}
{% if instance_link %}
<a href="{{ instance_link }}" {{ link_html_tag_attributes }}{% if css_classes %} class="{{ css_classes }}"{% endif %}{% if inline_styles %} style="{{ inline_styles }}"{% endif %}>
<a href="{{ instance_link }}"{{ instance.html_tag_attributes }}{% if css_classes %} class="{{ css_classes }}"{% endif %}{% if inline_styles %} style="{{ inline_styles }}"{% endif %}>
{% elif css_classes or inline_styles %}
<span {% if css_classes %} class="{{ css_classes }}"{% endif %}{% if inline_styles %} style="{{ inline_styles }}"{% endif %}>
{% endif %}
<i class="{{ icon_font_class }}"></i>
{% if instance_link %}</a>{% elif css_classes or inline_styles %}</span>{% endif %}
{% endwith %}
{% endspaceless %}
{% endspaceless %}
8 changes: 5 additions & 3 deletions tests/test_iconfont.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from cmsplugin_cascade.models import CascadeElement, IconFont
from cmsplugin_cascade.icon.forms import IconFormMixin
from cmsplugin_cascade.icon.simpleicon import SimpleIconPlugin
from cmsplugin_cascade.link.forms import LinkForm
from .conftest import UserFactory


Expand Down Expand Up @@ -82,7 +83,7 @@ def test_iconfont_change_view(admin_client, icon_font):
@pytest.mark.django_db
def simple_icon(admin_site, cms_placeholder, icon_font):
"""Create and edit a SimpleIconPlugin"""
class IconFontForm(IconFormMixin, ModelForm):
class IconFontForm(IconFormMixin, LinkForm, ModelForm):
class Meta(IconFormMixin.Meta):
model = CascadeElement

Expand All @@ -91,7 +92,8 @@ class Meta(IconFormMixin.Meta):
assert isinstance(simple_icon_model, CascadeElement)

# edit simple icon plugin
data = {'icon_font': str(icon_font.id), 'symbol': 'icon-skiing'}
data = {'icon_font': str(icon_font.id), 'symbol': 'icon-skiing',
'link_type': 'exturl', 'ext_url': 'http://test.ru/test', 'link_target': '_blank', 'link_title': 'test title'}
form = IconFontForm(data=data, instance=simple_icon_model)
assert form.is_valid()
simple_icon_model = form.save()
Expand All @@ -110,4 +112,4 @@ def test_simple_icon(rf, simple_icon):
context = RequestContext(request)
content_renderer = ContentRenderer(request)
html = content_renderer.render_plugin(simple_icon_model, context).strip()
assert html == '<i class="icon-icon-skiing"></i>'
assert html == '<a href="http://test.ru/test" title="test title" target="_blank"><i class="icon-icon-skiing"></i></a>'
41 changes: 41 additions & 0 deletions tests/test_text_link_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest
from django.forms.models import ModelForm
from django.template.context import RequestContext
from cms.api import add_plugin
from cms.plugin_rendering import ContentRenderer
from cmsplugin_cascade.models import CascadeElement
from cmsplugin_cascade.link.forms import LinkForm
from cmsplugin_cascade.link.cms_plugins import TextLinkPlugin


@pytest.fixture
@pytest.mark.django_db
def link(admin_site, cms_placeholder):
"""Create and edit a TextLinkPlugin"""
class LinkModelForm(LinkForm, ModelForm):
class Meta(LinkForm.Meta):
model = CascadeElement

# add text link plugin
link_model = add_plugin(cms_placeholder, TextLinkPlugin, 'en')
assert isinstance(link_model, CascadeElement)

# edit text link plugin
data = {'link_type': 'exturl', 'ext_url': 'http://test.ru/test', 'link_target': '_blank', 'link_title': 'test title'}
form = LinkModelForm(data=data, instance=link_model)
assert form.is_valid()
link_model = form.save()
link_plugin = link_model.get_plugin_class_instance(admin_site)
assert isinstance(link_plugin, TextLinkPlugin)
return link_plugin, link_model


@pytest.mark.django_db
def test_link_plugin(rf, link):
"""Render a LinkPluginBase"""
link_plugin, link_model = link
request = rf.get('/')
context = RequestContext(request)
content_renderer = ContentRenderer(request)
html = content_renderer.render_plugin(link_model, context).strip()
assert html == '<a href="http://test.ru/test" title="test title" target="_blank"></a>'