0001-wcs-pagination-configuration-for-cards-cell-57322.patch
combo/apps/wcs/forms.py | ||
---|---|---|
48 | 48 | |
49 | 49 |
class Meta: |
50 | 50 |
model = WcsCardsCell |
51 |
fields = ('carddef_reference', 'custom_title', 'only_for_user') |
|
51 |
fields = ('carddef_reference', 'custom_title', 'limit', 'only_for_user')
|
|
52 | 52 | |
53 | 53 |
def __init__(self, *args, **kwargs): |
54 | 54 |
instance = kwargs['instance'] |
combo/apps/wcs/migrations/0040_cards_limit.py | ||
---|---|---|
1 |
from django.db import migrations, models |
|
2 | ||
3 | ||
4 |
class Migration(migrations.Migration): |
|
5 | ||
6 |
dependencies = [ |
|
7 |
('wcs', '0039_card_title_type'), |
|
8 |
] |
|
9 | ||
10 |
operations = [ |
|
11 |
migrations.AddField( |
|
12 |
model_name='wcscardscell', |
|
13 |
name='limit', |
|
14 |
field=models.PositiveSmallIntegerField( |
|
15 |
blank=True, null=True, verbose_name='Number of cards per page (default 10)' |
|
16 |
), |
|
17 |
), |
|
18 |
] |
combo/apps/wcs/models.py | ||
---|---|---|
780 | 780 |
custom_title = models.CharField(_('Custom Title'), max_length=150, blank=True) |
781 | 781 |
only_for_user = models.BooleanField(_('Limit to cards linked to the logged-in user'), default=False) |
782 | 782 |
without_user = models.BooleanField(_('Ignore the logged-in user'), default=False) |
783 |
limit = models.PositiveSmallIntegerField( |
|
784 |
_('Number of cards per page (default 10)'), null=True, blank=True |
|
785 |
) |
|
783 | 786 | |
784 | 787 |
default_template_name = 'combo/wcs/cards.html' |
785 | 788 |
variable_name = 'cards' |
... | ... | |
863 | 866 | |
864 | 867 |
def get_cell_extra_context(self, context): |
865 | 868 |
extra_context = super().get_cell_extra_context(context) |
869 |
extra_context['paginate_by'] = self.limit or 10 |
|
866 | 870 |
extra_context['title'] = self.custom_title or self.cached_title |
867 | 871 | |
868 | 872 |
pages_with_sub_slug = Page.objects.exclude(sub_slug='') |
combo/public/templates/combo/pagination.html | ||
---|---|---|
1 | 1 |
{% load static %} |
2 |
<div class="cell-items-pagination" data-paginate-by="10" hidden>
|
|
2 |
<div class="cell-items-pagination" data-paginate-by="{{ paginate_by|default:10 }}" hidden>
|
|
3 | 3 |
<button class="cell-items-pagination-prev" disabled>←</a> |
4 | 4 |
<button class="cell-items-pagination-next" disabled>→</a> |
5 | 5 |
</div> |
tests/test_wcs.py | ||
---|---|---|
1518 | 1518 |
'<a href="http://127.0.0.1:8999/backoffice/data/card_model_1/13/"><span class="card-title">cc</span></a>' |
1519 | 1519 |
in result |
1520 | 1520 |
) |
1521 |
assert 'data-paginate-by="10"' in result |
|
1521 | 1522 | |
1522 | 1523 |
# create a page with the correct subslug |
1523 | 1524 |
page = Page.objects.create(slug='foo', title='Foo', sub_slug='(?P<card_model_1_id>[a-z0-9]+)') |
... | ... | |
1529 | 1530 |
assert '<a href="/foo/13"><span class="card-title">cc</span></a>' in result |
1530 | 1531 | |
1531 | 1532 |
cell.carddef_reference = 'default:card_model_1:foo' |
1533 |
cell.limit = 42 |
|
1532 | 1534 |
cell.save() |
1533 | 1535 |
page.sub_slug = 'card_model_1_id' |
1534 | 1536 |
page.save() |
... | ... | |
1538 | 1540 |
assert '<a href="/foo/11"><span class="card-title">aa</span></a>' in result |
1539 | 1541 |
assert '<a href="/foo/12"><span class="card-title">bb</span></a>' in result |
1540 | 1542 |
assert '<a href="/foo/13"><span class="card-title">cc</span></a>' not in result |
1543 |
assert 'data-paginate-by="42"' in result |
|
1541 | 1544 | |
1542 | 1545 |
with mock.patch('combo.apps.wcs.models.requests.get') as requests_get: |
1543 | 1546 |
mock_json = mock.Mock(status_code=200) |
1544 |
- |