applications: weekly agenda cell dependencies to card models (#86520)

This commit is contained in:
Lauréline Guérin 2024-02-06 09:58:23 +01:00
parent ea3d41d222
commit 995e3773cf
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 51 additions and 0 deletions

View File

@ -18,6 +18,7 @@ from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _
from combo.apps.wcs.utils import get_wcs_dependencies_from_template
from combo.data.library import register_cell_class
from combo.data.models import JsonCellBase, django_template_validator
from combo.utils import get_templated_url
@ -112,3 +113,15 @@ class WeeklyAgendaCell(JsonCellBase):
from .forms import WeeklyAgendaCellForm
return WeeklyAgendaCellForm
def get_dependencies(self):
yield from super().get_dependencies()
fields = [
'agenda_references_template',
'agenda_categories',
'start_date_filter',
'end_date_filter',
'user_external_template',
]
for field in fields:
yield from get_wcs_dependencies_from_template(getattr(self, field))

View File

@ -15,6 +15,7 @@ from django.core.files import File
from django.core.files.storage import default_storage
from combo.apps.export_import.models import Application, ApplicationAsyncJob, ApplicationElement
from combo.apps.family.models import WeeklyAgendaCell
from combo.apps.search.models import SearchCell
from combo.apps.wcs.models import WcsCardCell, WcsCategoryCell, WcsFormCell
from combo.data.models import LinkCell, LinkListCell, Page, PageSnapshot, TextCell
@ -802,6 +803,43 @@ def test_page_dependencies_search_cell(mock_send):
assert card_dep not in page.get_dependencies()
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
def test_page_dependencies_weekly_agenda_cell(mock_send):
page = Page.objects.create(title='Family', slug='family', template_name='standard')
cell = WeeklyAgendaCell.objects.create(
page=page,
placeholder='content',
order=0,
)
fields = [
'agenda_references_template',
'agenda_categories',
'start_date_filter',
'end_date_filter',
'user_external_template',
]
for field in fields:
cell.mark_as_valid()
for f in fields:
setattr(cell, f, '')
setattr(cell, field, '{{ cards|objects:"card_model_1" }}')
cell.save()
card_dep = {
'type': 'cards',
'id': 'card_model_1',
'text': 'Card Model 1',
'urls': {
'export': 'http://127.0.0.1:8999/api/export-import/cards/card_model_1/',
'dependencies': 'http://127.0.0.1:8999/api/export-import/cards/card_model_1/dependencies/',
'redirect': 'http://127.0.0.1:8999/api/export-import/cards/card_model_1/redirect/',
},
}
assert card_dep in page.get_dependencies()
cell.mark_as_invalid(reason_code='foobar')
assert card_dep not in page.get_dependencies()
def test_hourly(freezer):
job = ApplicationAsyncJob.objects.create(action='foo', bundle=File(io.BytesIO(b'test'), 'test.tar'))
ApplicationAsyncJob.objects.create(