wcs: custom title for cards cell (#54549)
This commit is contained in:
parent
ec1b6ec146
commit
48591c00cc
|
@ -51,7 +51,7 @@ class WcsCardsCellForm(forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = WcsCardsCell
|
model = WcsCardsCell
|
||||||
fields = ('carddef_reference', 'only_for_user')
|
fields = ('carddef_reference', 'custom_title', 'only_for_user')
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
instance = kwargs['instance']
|
instance = kwargs['instance']
|
||||||
|
|
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -775,6 +775,7 @@ class CardMixin(object):
|
||||||
class WcsCardsCell(CardMixin, WcsBlurpMixin, CellBase):
|
class WcsCardsCell(CardMixin, WcsBlurpMixin, CellBase):
|
||||||
carddef_reference = models.CharField(_('Card Model'), max_length=150)
|
carddef_reference = models.CharField(_('Card Model'), max_length=150)
|
||||||
cached_title = models.CharField(_('Title'), 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)
|
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)
|
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):
|
def get_cell_extra_context(self, context):
|
||||||
extra_context = super().get_cell_extra_context(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='')
|
pages_with_sub_slug = Page.objects.exclude(sub_slug='')
|
||||||
card_id = '%s_id' % self.carddef_reference.split(':')[1]
|
card_id = '%s_id' % self.carddef_reference.split(':')[1]
|
||||||
|
|
|
@ -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][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/'
|
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)
|
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
|
||||||
def test_cards_cell_only_for_user(mock_send, context):
|
def test_cards_cell_only_for_user(mock_send, context):
|
||||||
|
|
Loading…
Reference in New Issue