Projet

Général

Profil

0001-wcs-custom-title-for-cards-cell-54549.patch

Lauréline Guérin, 08 juin 2021 15:21

Télécharger (3,59 ko)

Voir les différences:

Subject: [PATCH] wcs: custom title for cards cell (#54549)

 combo/apps/wcs/forms.py                       |  2 +-
 .../wcs/migrations/0029_cards_custom_title.py | 19 +++++++++++++++++++
 combo/apps/wcs/models.py                      |  3 ++-
 tests/test_wcs.py                             |  6 ++++++
 4 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 combo/apps/wcs/migrations/0029_cards_custom_title.py
combo/apps/wcs/forms.py
51 51

  
52 52
    class Meta:
53 53
        model = WcsCardsCell
54
        fields = ('carddef_reference', 'only_for_user')
54
        fields = ('carddef_reference', 'custom_title', 'only_for_user')
55 55

  
56 56
    def __init__(self, *args, **kwargs):
57 57
        instance = kwargs['instance']
combo/apps/wcs/migrations/0029_cards_custom_title.py
1
# -*- coding: utf-8 -*-
2
from __future__ import unicode_literals
3

  
4
from django.db import migrations, models
5

  
6

  
7
class Migration(migrations.Migration):
8

  
9
    dependencies = [
10
        ('wcs', '0028_wcscardscell_without_user'),
11
    ]
12

  
13
    operations = [
14
        migrations.AddField(
15
            model_name='wcscardscell',
16
            name='custom_title',
17
            field=models.CharField(blank=True, max_length=150, verbose_name='Custom Title'),
18
        ),
19
    ]
combo/apps/wcs/models.py
775 775
class WcsCardsCell(CardMixin, WcsBlurpMixin, CellBase):
776 776
    carddef_reference = models.CharField(_('Card Model'), max_length=150)
777 777
    cached_title = models.CharField(_('Title'), max_length=150)
778
    custom_title = models.CharField(_('Custom Title'), max_length=150, blank=True)
778 779
    only_for_user = models.BooleanField(_('Limit to cards linked to the logged-in user'), default=False)
779 780
    without_user = models.BooleanField(_('Ignore the logged-in user'), default=False)
780 781

  
......
857 858

  
858 859
    def get_cell_extra_context(self, context):
859 860
        extra_context = super().get_cell_extra_context(context)
860
        extra_context['title'] = self.cached_title
861
        extra_context['title'] = self.custom_title or self.cached_title
861 862

  
862 863
        pages_with_sub_slug = Page.objects.exclude(sub_slug='')
863 864
        card_id = '%s_id' % self.carddef_reference.split(':')[1]
tests/test_wcs.py
1439 1439
    assert requests_get.call_args_list[0][0][0] == '/api/cards/card_model_1/list/foo'
1440 1440
    assert requests_get.call_args_list[0][1]['remote_service']['url'] == 'http://127.0.0.1:8999/'
1441 1441

  
1442
    cell.custom_title = 'Foo bar'
1443
    cell.save()
1444
    result = cell.render(context)
1445
    assert '<h2>Card Model 1 - bar</h2>' not in result
1446
    assert '<h2>Foo bar</h2>' in result
1447

  
1442 1448

  
1443 1449
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
1444 1450
def test_cards_cell_only_for_user(mock_send, context):
1445
-