wcs: custom title for cards cell (#54549)
gitea-wip/combo/pipeline/head Build started... Details
gitea/combo/pipeline/head Build started... Details

This commit is contained in:
Lauréline Guérin 2021-06-08 15:17:39 +02:00
parent ec1b6ec146
commit 48591c00cc
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
4 changed files with 28 additions and 2 deletions

View File

@ -51,7 +51,7 @@ class WcsCardsCellForm(forms.ModelForm):
class Meta:
model = WcsCardsCell
fields = ('carddef_reference', 'only_for_user')
fields = ('carddef_reference', 'custom_title', 'only_for_user')
def __init__(self, *args, **kwargs):
instance = kwargs['instance']

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('wcs', '0028_wcscardscell_without_user'),
]
operations = [
migrations.AddField(
model_name='wcscardscell',
name='custom_title',
field=models.CharField(blank=True, max_length=150, verbose_name='Custom Title'),
),
]

View File

@ -775,6 +775,7 @@ class CardMixin(object):
class WcsCardsCell(CardMixin, WcsBlurpMixin, CellBase):
carddef_reference = models.CharField(_('Card Model'), max_length=150)
cached_title = models.CharField(_('Title'), max_length=150)
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)
@ -857,7 +858,7 @@ class WcsCardsCell(CardMixin, WcsBlurpMixin, CellBase):
def get_cell_extra_context(self, context):
extra_context = super().get_cell_extra_context(context)
extra_context['title'] = self.cached_title
extra_context['title'] = self.custom_title or self.cached_title
pages_with_sub_slug = Page.objects.exclude(sub_slug='')
card_id = '%s_id' % self.carddef_reference.split(':')[1]

View File

@ -1439,6 +1439,12 @@ def test_cards_cell_render(mock_send, context):
assert requests_get.call_args_list[0][0][0] == '/api/cards/card_model_1/list/foo'
assert requests_get.call_args_list[0][1]['remote_service']['url'] == 'http://127.0.0.1:8999/'
cell.custom_title = 'Foo bar'
cell.save()
result = cell.render(context)
assert '<h2>Card Model 1 - bar</h2>' not in result
assert '<h2>Foo bar</h2>' in result
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
def test_cards_cell_only_for_user(mock_send, context):