cells: list of links are foldable and expandable (#40703)
This commit is contained in:
parent
cf47dc1a23
commit
8e7e5cbe3f
|
@ -52,7 +52,7 @@ class LinkCellForm(forms.ModelForm):
|
||||||
class LinkListCellForm(forms.ModelForm):
|
class LinkListCellForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = LinkListCell
|
model = LinkListCell
|
||||||
fields = ['title']
|
fields = ['title', 'limit']
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(LinkListCellForm, self).__init__(*args, **kwargs)
|
super(LinkListCellForm, self).__init__(*args, **kwargs)
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.18 on 2020-03-17 09:34
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('data', '0044_validity_info'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='linklistcell',
|
||||||
|
name='limit',
|
||||||
|
field=models.PositiveSmallIntegerField(blank=True, null=True, verbose_name='Limit'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1184,6 +1184,7 @@ class LinkCell(CellBase):
|
||||||
@register_cell_class
|
@register_cell_class
|
||||||
class LinkListCell(CellBase):
|
class LinkListCell(CellBase):
|
||||||
title = models.CharField(_('Title'), max_length=150, blank=True)
|
title = models.CharField(_('Title'), max_length=150, blank=True)
|
||||||
|
limit = models.PositiveSmallIntegerField(_('Limit'), null=True, blank=True)
|
||||||
|
|
||||||
template_name = 'combo/link-list-cell.html'
|
template_name = 'combo/link-list-cell.html'
|
||||||
manager_form_template = 'combo/manager/link-list-cell-form.html'
|
manager_form_template = 'combo/manager/link-list-cell-form.html'
|
||||||
|
@ -1225,6 +1226,10 @@ class LinkListCell(CellBase):
|
||||||
continue
|
continue
|
||||||
links.append(cell.get_cell_extra_context(context))
|
links.append(cell.get_cell_extra_context(context))
|
||||||
extra_context['links'] = links
|
extra_context['links'] = links
|
||||||
|
extra_context['more_links'] = []
|
||||||
|
if self.limit:
|
||||||
|
extra_context['more_links'] = extra_context['links'][self.limit:]
|
||||||
|
extra_context['links'] = extra_context['links'][:self.limit]
|
||||||
extra_context['title'] = self.title
|
extra_context['title'] = self.title
|
||||||
return extra_context
|
return extra_context
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
{% block cell-content %}
|
{% block cell-content %}
|
||||||
{% spaceless %}
|
{% spaceless %}
|
||||||
|
{% if title %}<h2>{{ title }}</h2>{% endif %}
|
||||||
<div class="links-list">
|
<div class="links-list">
|
||||||
{% if title %}<h2>{{title}}</h2>{% endif %}
|
|
||||||
{% include "combo/asset_picture_fragment.html" %}
|
{% include "combo/asset_picture_fragment.html" %}
|
||||||
<ul>
|
<ul>
|
||||||
{% for link in links %}
|
{% for link in links %}
|
||||||
<li><a href="{{ link.url }}">{{ link.title }}</a></li>
|
<li><a href="{{ link.url }}">{{ link.title }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if more_links %}
|
||||||
|
<li class="more-items"><a>+</a></li>
|
||||||
|
{% for link in more_links %}
|
||||||
|
<li style="display: none" class="additional-links"><a href="{{ link.url }}">{{ link.title }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
{% endspaceless %}
|
{% endspaceless %}
|
||||||
|
|
|
@ -235,6 +235,18 @@ def test_link_list_cell():
|
||||||
item.link_page = None
|
item.link_page = None
|
||||||
assert '<ul><li><a href="http://example.net/#anchor">altertitle</a></li></ul>' in cell.render(ctx)
|
assert '<ul><li><a href="http://example.net/#anchor">altertitle</a></li></ul>' in cell.render(ctx)
|
||||||
|
|
||||||
|
item2 = LinkCell.objects.create(
|
||||||
|
page=page,
|
||||||
|
placeholder=cell.link_placeholder,
|
||||||
|
title='Example Site',
|
||||||
|
url='http://example.net/',
|
||||||
|
order=1,
|
||||||
|
)
|
||||||
|
ctx = {'page_cells': [item, item2]}
|
||||||
|
assert '<li class="more-items"><a>+</a></li>' not in cell.render(ctx)
|
||||||
|
cell.limit = 1
|
||||||
|
assert '<li class="more-items"><a>+</a></li>' in cell.render(ctx)
|
||||||
|
|
||||||
|
|
||||||
def test_link_list_cell_validity():
|
def test_link_list_cell_validity():
|
||||||
page = Page.objects.create(title='example page', slug='example-page')
|
page = Page.objects.create(title='example page', slug='example-page')
|
||||||
|
|
Loading…
Reference in New Issue