wcs: custom title for forms in your care cell (#61589)
This commit is contained in:
parent
b5132df5f5
commit
e9d2e6c349
|
@ -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'),
|
||||
),
|
||||
]
|
|
@ -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'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% load i18n combo %}
|
||||
{% block cell-content %}
|
||||
{% for slug, forms in care_forms.items %}
|
||||
<h2>{% trans "Forms to process" %} - {{ forms.title }}</h2>
|
||||
<h2>{% if cell.custom_title %}{{ cell.custom_title }}{% else %}{% trans "Forms to process" %} - {{ forms.title }}{% endif %}</h2>
|
||||
{% if forms.data %}
|
||||
<table id="listing" class="main clickable-rows">
|
||||
<thead>
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue