wcs: add cache_duration advanced option to "forms in your care" cell (#63390)

This commit is contained in:
Frédéric Péters 2022-04-11 15:59:03 +02:00
parent 2ba7eb256e
commit 6a33066ac9
3 changed files with 57 additions and 1 deletions

View File

@ -0,0 +1,20 @@
# Generated by Django 2.2.27 on 2022-04-11 13:26
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('wcs', '0044_related_card_path'),
]
operations = [
migrations.AddField(
model_name='wcscareformscell',
name='cache_duration',
field=models.PositiveIntegerField(
default=120, help_text='In seconds.', verbose_name='Cache duration'
),
),
]

View File

@ -726,7 +726,7 @@ class WcsCareFormsCell(CategoriesAndWcsSiteValidityMixin, CategoriesFilteringMix
api_url = '/api/forms/?limit=10'
variable_name = 'care_forms'
default_template_name = 'combo/wcs/care_forms.html'
cache_duration = 120
cache_duration = models.PositiveIntegerField(_('Cache duration'), default=120, help_text=_('In seconds.'))
user_dependant = True
class Meta:
@ -737,6 +737,18 @@ class WcsCareFormsCell(CategoriesAndWcsSiteValidityMixin, CategoriesFilteringMix
return WcsCareFormsCellForm
def get_manager_tabs(self):
tabs = super().get_manager_tabs()
tabs.insert(
1,
{
'slug': 'advanced',
'name': _('Advanced'),
'fields': ['cache_duration'],
},
)
return tabs
def get_cell_extra_context(self, context):
context = super().get_cell_extra_context(context)
context['is_portal_agent'] = is_portal_agent()

View File

@ -1583,6 +1583,30 @@ def test_manager_current_forms(mock_send, settings, app, admin_user):
assert resp.form['c%s-wcs_site' % cells[0].get_reference()].attrs['type'] == 'hidden'
@mock.patch('combo.apps.wcs.utils.requests.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('combo.apps.wcs.utils.requests.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')