Coverage for backend/django/flowsheetInternals/unitops/services/edit_operations/context.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2026-07-22 05:22 +0000

1from __future__ import annotations 

2 

3from contextvars import ContextVar 

4from typing import TYPE_CHECKING 

5 

6if TYPE_CHECKING: 

7 from .recorder import FlowsheetChangeRecorder 

8 

9 

10active_recorder: ContextVar[FlowsheetChangeRecorder | None] = ContextVar( 

11 "flowsheet_edit_recorder", 

12 default=None, 

13) 

14replay_in_progress: ContextVar[bool] = ContextVar( 

15 "flowsheet_edit_replay", 

16 default=False, 

17) 

18 

19 

20def get_active_recorder() -> FlowsheetChangeRecorder | None: 

21 """Return the current outer flowsheet operation recorder, if any.""" 

22 if replay_in_progress.get(): 

23 return None 

24 return active_recorder.get() 

25 

26 

27def history_transition_in_progress() -> bool: 

28 """Return whether a recorded edit or its replay owns content bookkeeping.""" 

29 return active_recorder.get() is not None or replay_in_progress.get()