wcs: pagination configuration for cards cell (#57322)
This commit is contained in:
parent
013248d96e
commit
5c566a3b0d
|
@ -48,7 +48,7 @@ class WcsCardsCellForm(forms.ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = WcsCardsCell
|
||||
fields = ('carddef_reference', 'custom_title', 'only_for_user')
|
||||
fields = ('carddef_reference', 'custom_title', 'limit', 'only_for_user')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
instance = kwargs['instance']
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wcs', '0039_card_title_type'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='wcscardscell',
|
||||
name='limit',
|
||||
field=models.PositiveSmallIntegerField(
|
||||
blank=True, null=True, verbose_name='Number of cards per page (default 10)'
|
||||
),
|
||||
),
|
||||
]
|
|
@ -780,6 +780,9 @@ class WcsCardsCell(CardMixin, WcsBlurpMixin, CellBase):
|
|||
custom_title = models.CharField(_('Custom Title'), max_length=150, blank=True)
|
||||
only_for_user = models.BooleanField(_('Limit to cards linked to the logged-in user'), default=False)
|
||||
without_user = models.BooleanField(_('Ignore the logged-in user'), default=False)
|
||||
limit = models.PositiveSmallIntegerField(
|
||||
_('Number of cards per page (default 10)'), null=True, blank=True
|
||||
)
|
||||
|
||||
default_template_name = 'combo/wcs/cards.html'
|
||||
variable_name = 'cards'
|
||||
|
@ -863,6 +866,7 @@ class WcsCardsCell(CardMixin, WcsBlurpMixin, CellBase):
|
|||
|
||||
def get_cell_extra_context(self, context):
|
||||
extra_context = super().get_cell_extra_context(context)
|
||||
extra_context['paginate_by'] = self.limit or 10
|
||||
extra_context['title'] = self.custom_title or self.cached_title
|
||||
|
||||
pages_with_sub_slug = Page.objects.exclude(sub_slug='')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% load static %}
|
||||
<div class="cell-items-pagination" data-paginate-by="10" hidden>
|
||||
<div class="cell-items-pagination" data-paginate-by="{{ paginate_by|default:10 }}" hidden>
|
||||
<button class="cell-items-pagination-prev" disabled>←</a>
|
||||
<button class="cell-items-pagination-next" disabled>→</a>
|
||||
</div>
|
||||
|
|
|
@ -1518,6 +1518,7 @@ def test_cards_cell_render(mock_send, context):
|
|||
'<a href="http://127.0.0.1:8999/backoffice/data/card_model_1/13/"><span class="card-title">cc</span></a>'
|
||||
in result
|
||||
)
|
||||
assert 'data-paginate-by="10"' in result
|
||||
|
||||
# create a page with the correct subslug
|
||||
page = Page.objects.create(slug='foo', title='Foo', sub_slug='(?P<card_model_1_id>[a-z0-9]+)')
|
||||
|
@ -1529,6 +1530,7 @@ def test_cards_cell_render(mock_send, context):
|
|||
assert '<a href="/foo/13"><span class="card-title">cc</span></a>' in result
|
||||
|
||||
cell.carddef_reference = 'default:card_model_1:foo'
|
||||
cell.limit = 42
|
||||
cell.save()
|
||||
page.sub_slug = 'card_model_1_id'
|
||||
page.save()
|
||||
|
@ -1538,6 +1540,7 @@ def test_cards_cell_render(mock_send, context):
|
|||
assert '<a href="/foo/11"><span class="card-title">aa</span></a>' in result
|
||||
assert '<a href="/foo/12"><span class="card-title">bb</span></a>' in result
|
||||
assert '<a href="/foo/13"><span class="card-title">cc</span></a>' not in result
|
||||
assert 'data-paginate-by="42"' in result
|
||||
|
||||
with mock.patch('combo.apps.wcs.models.requests.get') as requests_get:
|
||||
mock_json = mock.Mock(status_code=200)
|
||||
|
|
Loading…
Reference in New Issue