wcs: custom title for card cell (#55335)
This commit is contained in:
parent
64859f4837
commit
22ce180d68
|
@ -73,7 +73,7 @@ class WcsCardInfoCellForm(forms.ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = WcsCardInfosCell
|
||||
fields = ('carddef_reference', 'card_id')
|
||||
fields = ('carddef_reference', 'custom_title', 'card_id')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
instance = kwargs['instance']
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wcs', '0029_cards_custom_title'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='wcscardinfoscell',
|
||||
name='custom_title',
|
||||
field=models.CharField(blank=True, max_length=150, verbose_name='Custom Title'),
|
||||
),
|
||||
]
|
|
@ -897,6 +897,7 @@ class WcsCardInfosCell(CardMixin, CellBase):
|
|||
without_user = models.BooleanField(_('Ignore the logged-in user'), default=False)
|
||||
|
||||
cached_title = models.CharField(_('Title'), max_length=150)
|
||||
custom_title = models.CharField(_('Custom Title'), max_length=150, blank=True)
|
||||
cached_json = JSONField(blank=True, default=dict)
|
||||
|
||||
is_enabled = classmethod(is_wcs_enabled)
|
||||
|
@ -964,7 +965,7 @@ class WcsCardInfosCell(CardMixin, 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
|
||||
extra_context['schema'] = self.cached_json
|
||||
|
||||
card_id = self.get_card_id(context)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<div class="card">
|
||||
{% block cell-header %}
|
||||
<h2>{{ title }}{% if card %} - {{ card.text }}{% endif %}</h2>
|
||||
<h2>{{ title }}</h2>
|
||||
{% include "combo/asset_picture_fragment.html" %}
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -1695,7 +1695,7 @@ def test_card_cell_render(mock_send, context):
|
|||
|
||||
mock_send.reset_mock()
|
||||
result = cell.render(context)
|
||||
assert '<h2>Card Model 1 - aa</h2>' in result
|
||||
assert '<h2>Card Model 1</h2>' in result
|
||||
assert '<span class="label">Field A</span>\n \n <span class="value">a</span>' in result
|
||||
assert '<span class="label">Field B</span>\n \n <span class="value">yes</span>' in result
|
||||
assert '<span class="label">Field C</span>\n \n <span class="value">Sept. 28, 2020</span>' in result
|
||||
|
@ -1704,6 +1704,12 @@ def test_card_cell_render(mock_send, context):
|
|||
assert 'related_structured' not in result
|
||||
assert 'Field D' not in result
|
||||
|
||||
cell.custom_title = 'Foo bar'
|
||||
cell.save()
|
||||
result = cell.render(context)
|
||||
assert '<h2>Card Model 1</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_card_cell_render_identifier(mock_send, context, nocache):
|
||||
|
|
Loading…
Reference in New Issue