applications: don't import get_wcs_dependencies_from_template everywhere (#86520)

This commit is contained in:
Lauréline Guérin 2024-02-06 10:19:58 +01:00
parent c1b431922f
commit fd0d9c6fb7
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
4 changed files with 20 additions and 19 deletions

View File

@ -18,7 +18,6 @@ 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
@ -114,8 +113,8 @@ class WeeklyAgendaCell(JsonCellBase):
return WeeklyAgendaCellForm
def get_dependencies(self):
yield from super().get_dependencies()
def get_computed_strings(self):
yield from super().get_computed_strings()
fields = [
'agenda_references_template',
'agenda_categories',
@ -123,5 +122,4 @@ class WeeklyAgendaCell(JsonCellBase):
'end_date_filter',
'user_external_template',
]
for field in fields:
yield from get_wcs_dependencies_from_template(getattr(self, field))
yield from [getattr(self, f) for f in fields]

View File

@ -49,7 +49,6 @@ from django.utils.translation import pgettext_lazy
from requests import RequestException
from combo.apps.notifications.models import Notification
from combo.apps.wcs.utils import get_wcs_dependencies_from_template
from combo.data.fields import RichTextField
from combo.data.library import register_cell_class
from combo.data.models import CellBase
@ -1577,9 +1576,9 @@ class InvoicesCell(RegieElementsMixin, CellBase):
raise NothingInCacheException()
return super().render(context)
def get_dependencies(self):
yield from super().get_dependencies()
yield from get_wcs_dependencies_from_template(self.payer_external_id_template)
def get_computed_strings(self):
yield from super().get_computed_strings()
yield self.payer_external_id_template
class LingoElementsMixin:
@ -1621,9 +1620,9 @@ class LingoElementsMixin:
)
return ctx
def get_dependencies(self):
yield from super().get_dependencies()
yield from get_wcs_dependencies_from_template(self.payer_external_id_template)
def get_computed_strings(self):
yield from super().get_computed_strings()
yield self.payer_external_id_template
@register_cell_class

View File

@ -45,7 +45,6 @@ from combo.utils.requests_wrapper import WaitForCacheException
from .utils import (
get_matching_pages_from_card_slug,
get_wcs_dependencies_from_template,
get_wcs_dependency_from_carddef_reference,
get_wcs_json,
get_wcs_matching_card_model,
@ -1079,16 +1078,17 @@ class WcsCardCell(CardMixin, CellBase):
return False
return super().is_visible(request, **kwargs)
def get_computed_strings(self):
yield from super().get_computed_strings()
yield self.card_ids
for cell in self.get_custom_schema().get('cells') or []:
yield from [str(v) for v in cell.values() if v]
def get_dependencies(self):
yield from super().get_dependencies()
if self.carddef_reference:
yield get_wcs_dependency_from_carddef_reference(self.carddef_reference, self.cached_title)
yield from get_wcs_dependencies_from_template(self.card_ids)
for cell in self.get_custom_schema().get('cells') or []:
for value in cell.values():
if not value:
continue
yield from get_wcs_dependencies_from_template(str(value))
if cell.get('page') not in ['', None]:
try:
yield Page.objects.get(pk=cell['page'])

View File

@ -1270,9 +1270,13 @@ class CellBase(models.Model, metaclass=CellMeta):
def get_label(self):
return self.get_verbose_name()
def get_computed_strings(self):
yield self.condition
def get_dependencies(self):
yield from self.groups.all()
yield from get_wcs_dependencies_from_template(self.condition)
for string in self.get_computed_strings():
yield from get_wcs_dependencies_from_template(string)
def get_manager_tabs(self):
from combo.manager.forms import CellVisibilityForm