diff --git a/combo/apps/wcs/migrations/0047_careforms_title.py b/combo/apps/wcs/migrations/0047_careforms_title.py new file mode 100644 index 00000000..47d9904b --- /dev/null +++ b/combo/apps/wcs/migrations/0047_careforms_title.py @@ -0,0 +1,16 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wcs', '0046_display_condition'), + ] + + operations = [ + migrations.AddField( + model_name='wcscareformscell', + name='custom_title', + field=models.CharField(blank=True, max_length=150, verbose_name='Custom Title'), + ), + ] diff --git a/combo/apps/wcs/models.py b/combo/apps/wcs/models.py index 4aa19527..7fa1a4bd 100644 --- a/combo/apps/wcs/models.py +++ b/combo/apps/wcs/models.py @@ -723,6 +723,7 @@ class WcsFormsOfCategoryCell(WcsCommonCategoryCell, WcsBlurpMixin): @register_cell_class class WcsCareFormsCell(CategoriesAndWcsSiteValidityMixin, CategoriesFilteringMixin, WcsDataBaseCell): categories = JSONField(_('Categories'), blank=True, default=dict) + custom_title = models.CharField(_('Custom Title'), max_length=150, blank=True) api_url = '/api/forms/?limit=10' variable_name = 'care_forms' diff --git a/combo/apps/wcs/templates/combo/wcs/care_forms.html b/combo/apps/wcs/templates/combo/wcs/care_forms.html index 00150214..55fa3ed6 100644 --- a/combo/apps/wcs/templates/combo/wcs/care_forms.html +++ b/combo/apps/wcs/templates/combo/wcs/care_forms.html @@ -1,7 +1,7 @@ {% load i18n combo %} {% block cell-content %} {% for slug, forms in care_forms.items %} -

{% trans "Forms to process" %} - {{ forms.title }}

+

{% if cell.custom_title %}{{ cell.custom_title }}{% else %}{% trans "Forms to process" %} - {{ forms.title }}{% endif %}

{% if forms.data %} diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 2e57cbcf..d4757977 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -1009,6 +1009,32 @@ def test_care_forms_cell_setup(): assert cell.get_additional_label() == 'test' +@mock.patch('requests.Session.send', side_effect=mocked_requests_send) +def test_manager_care_forms_cell(mock_send, app, admin_user): + page = Page(title='One', slug='one', template_name='standard') + page.save() + app = login(app) + resp = app.get('/manage/pages/%s/' % page.id) + resp = app.get( + resp.html.find('option', **{'data-add-url': re.compile('wcscareformscell')})['data-add-url'] + ) + + cells = Page.objects.get(id=page.id).get_cells() + assert len(cells) == 1 + assert isinstance(cells[0], WcsCareFormsCell) + + resp = app.get('/manage/pages/%s/' % page.id) + assert not resp.pyquery('[data-tab-slug="general"] input[name$="custom_title"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="custom_title"]') + assert ( + resp.pyquery.find('div.cell [data-tab-slug="advanced"] input[name$="cache_duration"]').val() == '120' + ) + resp.forms[0]['c%s-cache_duration' % cells[0].get_reference()] = '10' + manager_submit_cell(resp.forms[0]) + cells[0].refresh_from_db() + assert cells[0].cache_duration == 10 + + @mock.patch('requests.Session.send', side_effect=mocked_requests_send) def test_care_forms_cell_render(mock_send, context): page = Page(title='xxx', slug='test_care_forms_cell_render', template_name='standard') @@ -1029,19 +1055,26 @@ def test_care_forms_cell_render(mock_send, context): is_portal_agent.return_value = True result = cell.render(context) + assert 'Forms to process - test' in result assert 'http://127.0.0.1:8999/backoffice/management/foobar/1' in result assert 'http://127.0.0.1:8999/backoffice/management/foobar/2' in result assert '"http://127.0.0.1:8999/backoffice/management/listing"' in result + assert 'Forms to process - test2' in result assert 'http://127.0.0.2:8999/backoffice/management/foobar/1' in result assert 'http://127.0.0.2:8999/backoffice/management/foobar/2' in result assert '"http://127.0.0.2:8999/backoffice/management/listing"' in result + cell.custom_title = 'Foo Bar' with mock.patch('combo.apps.wcs.models.is_portal_agent') as is_portal_agent: is_portal_agent.return_value = False result = cell.render(context) + assert 'Forms to process - test' not in result + assert 'Foo Bar' in result assert 'http://127.0.0.1:8999/foobar/1' in result assert 'http://127.0.0.1:8999/foobar/2' in result + assert 'Forms to process - test2' not in result + assert 'Foo Bar' in result assert 'http://127.0.0.2:8999/foobar/1' in result assert 'http://127.0.0.2:8999/foobar/2' in result assert '/listing' not in result @@ -1621,30 +1654,6 @@ def test_manager_current_forms_tabs(app, admin_user): assert resp.pyquery('[data-tab-slug="appearance"] input[name$="custom_title"]') -@mock.patch('requests.Session.send', side_effect=mocked_requests_send) -def test_manager_forms_in_your_care_cell(mock_send, app, admin_user): - page = Page(title='One', slug='one', template_name='standard') - page.save() - app = login(app) - resp = app.get('/manage/pages/%s/' % page.id) - resp = app.get( - resp.html.find('option', **{'data-add-url': re.compile('wcscareformscell')})['data-add-url'] - ) - - cells = Page.objects.get(id=page.id).get_cells() - assert len(cells) == 1 - assert isinstance(cells[0], WcsCareFormsCell) - - resp = app.get('/manage/pages/%s/' % page.id) - assert ( - resp.pyquery.find('div.cell [data-tab-slug="advanced"] input[name$="cache_duration"]').val() == '120' - ) - resp.forms[0]['c%s-cache_duration' % cells[0].get_reference()] = '10' - manager_submit_cell(resp.forms[0]) - cells[0].refresh_from_db() - assert cells[0].cache_duration == 10 - - @mock.patch('requests.Session.send', side_effect=mocked_requests_send) def test_manager_cards_cell(mock_send, app, admin_user): page = Page.objects.create(title='xxx', slug='test_cards_cell_save_cache', template_name='standard')