Extract managed form elements from XML
This commit is contained in:
@@ -171,7 +171,7 @@ def parse_one_c_xml_file(path: str | Path) -> list[OneCXmlObject]:
|
||||
source_path = normalize_source_path(path)
|
||||
root = ET.fromstring(_read_text_file(Path(path)))
|
||||
result: list[OneCXmlObject] = []
|
||||
_walk_xml_objects(source_path, root, result, current_role=None, parent_qualified_name=None)
|
||||
_walk_xml_objects(source_path, root, result, current_role=None, parent_qualified_name=None, parent_object_kind=None)
|
||||
return result
|
||||
|
||||
|
||||
@@ -351,10 +351,12 @@ def _walk_xml_objects(
|
||||
*,
|
||||
current_role: OneCXmlObject | None,
|
||||
parent_qualified_name: str | None,
|
||||
parent_object_kind: str | None,
|
||||
) -> None:
|
||||
role_context = current_role
|
||||
child_parent_qualified_name = parent_qualified_name
|
||||
object_kind = _xml_object_kind(element)
|
||||
child_parent_object_kind = parent_object_kind
|
||||
object_kind = _xml_object_kind(element, parent_object_kind=parent_object_kind)
|
||||
if object_kind == "RIGHT":
|
||||
right = _xml_right_object(source_path, element, role_context)
|
||||
if right is not None:
|
||||
@@ -371,6 +373,7 @@ def _walk_xml_objects(
|
||||
)
|
||||
result.append(xml_object)
|
||||
child_parent_qualified_name = xml_object.qualified_name
|
||||
child_parent_object_kind = object_kind
|
||||
if object_kind == "ROLE":
|
||||
role_context = xml_object
|
||||
|
||||
@@ -381,6 +384,7 @@ def _walk_xml_objects(
|
||||
result,
|
||||
current_role=role_context,
|
||||
parent_qualified_name=child_parent_qualified_name,
|
||||
parent_object_kind=child_parent_object_kind,
|
||||
)
|
||||
|
||||
|
||||
@@ -695,6 +699,25 @@ _OBJECT_KIND_BY_TAG = {
|
||||
"предопределенный": "PREDEFINED",
|
||||
}
|
||||
|
||||
_FORM_ELEMENT_TAGS = {
|
||||
"item",
|
||||
"items",
|
||||
"element",
|
||||
"elements",
|
||||
"formitem",
|
||||
"formitems",
|
||||
"field",
|
||||
"fields",
|
||||
"group",
|
||||
"groups",
|
||||
"table",
|
||||
"tables",
|
||||
"button",
|
||||
"buttons",
|
||||
"page",
|
||||
"pages",
|
||||
}
|
||||
|
||||
|
||||
_QUALIFIED_PREFIX_BY_KIND = {
|
||||
"CATALOG": "Справочник",
|
||||
@@ -1288,8 +1311,10 @@ _PATH_METADATA_ALIASES = {
|
||||
}
|
||||
|
||||
|
||||
def _xml_object_kind(element: ET.Element) -> str | None:
|
||||
def _xml_object_kind(element: ET.Element, *, parent_object_kind: str | None = None) -> str | None:
|
||||
tag = _local_name(element.tag).lower()
|
||||
if parent_object_kind in {"FORM", "ELEMENT"} and tag in _FORM_ELEMENT_TAGS and _xml_name(element):
|
||||
return "ELEMENT"
|
||||
if tag in {"metadataobject", "object"}:
|
||||
type_name = _xml_type_name(element)
|
||||
if type_name:
|
||||
@@ -1384,6 +1409,11 @@ def _xml_qualified_name(
|
||||
|
||||
def _xml_attributes(element: ET.Element) -> dict:
|
||||
attributes = dict(element.attrib)
|
||||
for key, value in element.attrib.items():
|
||||
local_key = _local_name(key)
|
||||
attributes.setdefault(local_key, value)
|
||||
if local_key.lower() == "type":
|
||||
attributes.setdefault("control_kind", value.split(":")[-1].split(".")[-1])
|
||||
attribute_role = _xml_attribute_role(element)
|
||||
if attribute_role:
|
||||
attributes.setdefault("attribute_role", attribute_role)
|
||||
|
||||
Reference in New Issue
Block a user