MCPcopy Create free account
hub / github.com/datapane/datapane / PreProcessView

Class PreProcessView

python-client/src/datapane/processors/processors.py:32–65  ·  view source on GitHub ↗

Optimisations to improve the layout of the view using the Block-API

Source from the content-addressed store, hash-verified

30
31
32class PreProcessView(BaseProcessor):
33 """Optimisations to improve the layout of the view using the Block-API"""
34
35 def __init__(self, *, is_finalised: bool = True) -> None:
36 self.is_finalised = is_finalised
37 super().__init__()
38
39 def __call__(self, _: t.Any) -> None:
40 # AST checks
41 if len(self.s.blocks.blocks) == 0:
42 raise InvalidReportError("Empty blocks object - must contain at least one block")
43
44 # convert Page -> Select + Group
45 v = copy(self.s.blocks)
46 if all(isinstance(blk, b.Page) for blk in v.blocks):
47 # convert to top-level Select
48 p: b.Page # noqa: F842
49 v.blocks = [
50 b.Select(
51 blocks=[b.Group(blocks=p.blocks, label=p.title, name=p.name) for p in v.blocks],
52 type=b.SelectType.TABS,
53 )
54 ]
55
56 # Block-API visitors
57 pp = PreProcess(is_finalised=self.is_finalised)
58 v.accept(pp)
59 v1 = pp.root
60 # v1 = copy(v)
61
62 # update the processor state
63 self.s.blocks = v1
64
65 return None
66
67
68class ConvertXML(BaseProcessor):

Callers 4

_view_to_xml_and_filesFunction · 0.90
build_reportFunction · 0.85
save_reportFunction · 0.85
stringify_reportFunction · 0.85

Calls

no outgoing calls

Tested by 1

_view_to_xml_and_filesFunction · 0.72