wcs: custom title for card cell (#55335)
gitea-wip/combo/pipeline/head There was a failure building this commit Details
gitea/combo/pipeline/head Build started... Details

This commit is contained in:
Lauréline Guérin 2021-07-15 15:37:19 +02:00
parent 64859f4837
commit 22ce180d68
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
5 changed files with 27 additions and 4 deletions

View File

@ -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']

View File

@ -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'),
),
]

View File

@ -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)

View File

@ -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 %}

View File

@ -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):