Model 1C modules as object parts
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-05-17 18:43:43 +03:00
parent 1ad103b6dc
commit 35dd134ebc
7 changed files with 298 additions and 32 deletions
@@ -18,6 +18,7 @@ _HTML5_OBJECT_CONTEXT_KINDS = {
NodeKind.ENUM.value,
NodeKind.REPORT.value,
NodeKind.DATA_PROCESSOR.value,
NodeKind.FORM.value,
NodeKind.CHART_OF_CHARACTERISTIC_TYPES.value,
NodeKind.CHART_OF_ACCOUNTS.value,
NodeKind.CHART_OF_CALCULATION_TYPES.value,
@@ -512,17 +513,7 @@ def _object_action_links(
quoted_project = quote(project_id)
quoted_object = quote(object_name, safe="")
lineage = str(lineage_id or "")
first_module = next(iter(modules), None)
module_lineage = str(getattr(first_module, "lineage_id", "") or "")
source_link = (
f'<a class="button" href="/html5/projects/{quoted_project}/source/{quote(module_lineage, safe="")}" '
'hx-get="/html5/projects/{project}/source/{module}" hx-target="[data-html5-source]" hx-swap="outerHTML">Source</a>'.format(
project=quoted_project,
module=quote(module_lineage, safe=""),
)
if module_lineage
else ""
)
module_links = "".join(_module_action_link(quoted_project, module) for module in _sorted_object_modules(modules))
symbol_link = (
f'<a class="button" href="/html5/projects/{quoted_project}/symbols/{quote(lineage, safe="")}/detail" '
'hx-get="/html5/projects/{project}/symbols/{lineage}/detail" hx-target="[data-html5-symbol-detail]" hx-swap="outerHTML">Symbol</a>'.format(
@@ -576,12 +567,68 @@ def _object_action_links(
hx-target="[data-html5-flowchart]"
hx-swap="outerHTML"
>Flowchart</a>
{source_link}
{module_links}
{symbol_link}
</nav>
"""
def _sorted_object_modules(modules: Iterable[object]) -> list[object]:
priority = {
"OBJECT_MODULE": 0,
"MANAGER_MODULE": 1,
"RECORD_SET_MODULE": 2,
"FORM_MODULE": 3,
"MODULE": 9,
}
return sorted(
list(modules),
key=lambda module: (
priority.get(_module_role(module), 8),
str((getattr(module, "attributes", {}) or {}).get("form_name") or ""),
str(getattr(module, "qualified_name", "") or getattr(module, "name", "")),
),
)
def _module_action_link(quoted_project: str, module: object) -> str:
lineage = str(getattr(module, "lineage_id", "") or "")
if not lineage:
return ""
quoted_lineage = quote(lineage, safe="")
label = _module_action_label(module)
return f"""
<a
class="button"
href="/html5/projects/{quoted_project}/source/{quoted_lineage}"
hx-get="/html5/projects/{quoted_project}/source/{quoted_lineage}"
hx-target="[data-html5-source]"
hx-swap="outerHTML"
data-html5-module-action="{escape(_module_role(module))}"
>{escape(label)}</a>
"""
def _module_action_label(module: object) -> str:
attributes = getattr(module, "attributes", {}) or {}
role = _module_role(module)
if role == "OBJECT_MODULE":
return "Модуль объекта"
if role == "MANAGER_MODULE":
return "Модуль менеджера"
if role == "RECORD_SET_MODULE":
return "Модуль набора"
if role == "FORM_MODULE":
form_name = str(attributes.get("form_name") or "")
return f"Модуль формы {form_name}" if form_name else "Модуль формы"
return str(getattr(module, "name", None) or "Модуль")
def _module_role(module: object) -> str:
attributes = getattr(module, "attributes", {}) or {}
return str(attributes.get("module_role") or attributes.get("role") or getattr(module, "module_role", "") or "MODULE")
def _tabular_section_item(section: object) -> str:
tabular_section = getattr(section, "tabular_section", None)
columns = getattr(section, "columns", []) or []