cells: list of links are foldable and expandable (#40703)

This commit is contained in:
Lauréline Guérin 2020-03-17 11:03:54 +01:00
parent cf47dc1a23
commit 8e7e5cbe3f
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
5 changed files with 46 additions and 2 deletions

View File

@ -52,7 +52,7 @@ class LinkCellForm(forms.ModelForm):
class LinkListCellForm(forms.ModelForm):
class Meta:
model = LinkListCell
fields = ['title']
fields = ['title', 'limit']
def __init__(self, *args, **kwargs):
super(LinkListCellForm, self).__init__(*args, **kwargs)

View File

@ -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'),
),
]

View File

@ -1184,6 +1184,7 @@ class LinkCell(CellBase):
@register_cell_class
class LinkListCell(CellBase):
title = models.CharField(_('Title'), max_length=150, blank=True)
limit = models.PositiveSmallIntegerField(_('Limit'), null=True, blank=True)
template_name = 'combo/link-list-cell.html'
manager_form_template = 'combo/manager/link-list-cell-form.html'
@ -1225,6 +1226,10 @@ class LinkListCell(CellBase):
continue
links.append(cell.get_cell_extra_context(context))
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
return extra_context

View File

@ -1,12 +1,19 @@
{% block cell-content %}
{% spaceless %}
{% if title %}<h2>{{ title }}</h2>{% endif %}
<div class="links-list">
{% if title %}<h2>{{title}}</h2>{% endif %}
{% include "combo/asset_picture_fragment.html" %}
<ul>
{% for link in links %}
<li><a href="{{ link.url }}">{{ link.title }}</a></li>
{% 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>
</div>
{% endspaceless %}

View File

@ -235,6 +235,18 @@ def test_link_list_cell():
item.link_page = None
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():
page = Page.objects.create(title='example page', slug='example-page')