Portal/rsconcept/backend/apps/oss/models/PropagationFacade.py

43 lines
1.7 KiB
Python
Raw Normal View History

2024-08-11 00:10:27 +03:00
''' Models: Change propagation facade - managing all changes in OSS. '''
from apps.library.models import LibraryItem
from apps.rsform.models import Constituenta, RSForm
from .ChangeManager import ChangeManager
def _get_oss_hosts(item: LibraryItem) -> list[LibraryItem]:
''' Get all hosts for LibraryItem. '''
return list(LibraryItem.objects.filter(operations__result=item).only('pk'))
class PropagationFacade:
''' Change propagation API. '''
@classmethod
def on_create_cst(cls, new_cst: Constituenta, source: RSForm) -> None:
''' Trigger cascade resolutions when new constituent is created. '''
hosts = _get_oss_hosts(source.model)
for host in hosts:
ChangeManager(host).on_create_cst(new_cst, source)
@classmethod
def on_change_cst_type(cls, target: Constituenta, source: RSForm) -> None:
''' Trigger cascade resolutions when constituenta type is changed. '''
hosts = _get_oss_hosts(source.model)
for host in hosts:
ChangeManager(host).on_change_cst_type(target, source)
@classmethod
def on_update_cst(cls, target: Constituenta, data: dict, old_data: dict, source: RSForm) -> None:
''' Trigger cascade resolutions when constituenta data is changed. '''
hosts = _get_oss_hosts(source.model)
for host in hosts:
ChangeManager(host).on_update_cst(target, data, old_data, source)
@classmethod
2024-08-11 12:37:18 +03:00
def before_delete(cls, target: list[Constituenta], source: RSForm) -> None:
2024-08-11 00:10:27 +03:00
''' Trigger cascade resolutions before constituents are deleted. '''
2024-08-11 12:37:18 +03:00
hosts = _get_oss_hosts(source.model)
for host in hosts:
ChangeManager(host).before_delete(target, source)