Skip to content

Commit 14b0a3e

Browse files
committed
backend/sdoc: REQ_PREFIX->PREFIX for composite [[NODE]]
1 parent 70e7e25 commit 14b0a3e

File tree

52 files changed

+1207
-54
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1207
-54
lines changed

strictdoc/backend/excel/import_/excel_to_sdoc_converter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def create_document(
152152
parent=None,
153153
tag="REQUIREMENT",
154154
property_is_composite="",
155+
property_prefix="",
155156
property_view_style="",
156157
fields=fields,
157158
relations=[],

strictdoc/backend/reqif/p01_sdoc/reqif_to_sdoc_converter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ def create_grammar_element_from_spec_object_type(
319319
# FIXME: MERGE NODES
320320
# When the migration is done, make the nodes to be always recursive.
321321
property_is_composite="",
322+
property_prefix="",
322323
property_view_style="",
323324
fields=fields,
324325
relations=[],

strictdoc/backend/sdoc/grammar/grammar_grammar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
(
1919
' PROPERTIES:' '\n'
2020
(' IS_COMPOSITE: ' property_is_composite=/(True|False)/ '\n' )?
21+
(' PREFIX: ' property_prefix=/.*/ '\n' )?
2122
(' VIEW_STYLE: ' property_view_style=/(Plain|Simple|Inline|Narrative|Table|Zebra)/ '\n')?
2223
)?
2324
' FIELDS:' '\n'

strictdoc/backend/sdoc/models/document.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,22 @@ def ng_resolved_custom_level(self) -> Optional[str]:
177177

178178
@property
179179
def requirement_prefix(self) -> str:
180-
return self.get_requirement_prefix()
180+
return self.get_prefix()
181181

182-
def get_requirement_prefix(self) -> str:
183-
return self.config.get_requirement_prefix()
182+
def get_prefix(self) -> str:
183+
return self.config.get_prefix()
184+
185+
def get_prefix_for_new_node(self, node_type: str) -> Optional[str]:
186+
assert isinstance(node_type, str) and len(node_type), node_type
187+
188+
grammar: DocumentGrammar = assert_cast(self.grammar, DocumentGrammar)
189+
element: GrammarElement = grammar.elements_by_type[node_type]
190+
if (element_prefix := element.property_prefix) is not None:
191+
if element_prefix == "None":
192+
return None
193+
return element_prefix
194+
195+
return self.get_prefix()
184196

185197
def enumerate_meta_field_titles(self) -> Generator[str, None, None]:
186198
assert self.grammar is not None

strictdoc/backend/sdoc/models/document_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def is_requirement_in_toc(self) -> bool:
142142
self.requirement_in_toc is None or self.requirement_in_toc == "True"
143143
)
144144

145-
def get_requirement_prefix(self) -> str:
145+
def get_prefix(self) -> str:
146146
if self.requirement_prefix is not None:
147147
return self.requirement_prefix
148148
return "REQ-"

strictdoc/backend/sdoc/models/document_grammar.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def __init__(
2525
parent: Optional["DocumentGrammar"],
2626
tag: str,
2727
property_is_composite: str,
28+
property_prefix: str,
2829
property_view_style: str,
2930
fields: List[
3031
Union[
@@ -45,6 +46,10 @@ def __init__(
4546
else (property_is_composite == "True")
4647
)
4748

49+
self.property_prefix: Optional[str] = (
50+
property_prefix if property_prefix not in (None, "") else None
51+
)
52+
4853
assert property_view_style in (
4954
"",
5055
"Plain",
@@ -129,6 +134,7 @@ def create_default(tag: str) -> "GrammarElement":
129134
parent=None,
130135
tag=tag,
131136
property_is_composite="",
137+
property_prefix="",
132138
property_view_style="",
133139
fields=[
134140
GrammarElementFieldString(
@@ -346,6 +352,7 @@ def create_default(
346352
parent=None,
347353
tag="REQUIREMENT",
348354
property_is_composite="",
355+
property_prefix="",
349356
property_view_style="",
350357
fields=fields,
351358
relations=[],
@@ -436,6 +443,7 @@ def create_for_test_report(parent: SDocDocumentIF) -> "DocumentGrammar":
436443
parent=None,
437444
tag="TEST_RESULT",
438445
property_is_composite="",
446+
property_prefix="",
439447
property_view_style="",
440448
fields=fields,
441449
relations=[],
@@ -537,6 +545,7 @@ def create_default_text_element(
537545
parent=parent,
538546
tag="TEXT",
539547
property_is_composite="",
548+
property_prefix="",
540549
property_view_style="",
541550
fields=fields,
542551
relations=[],
@@ -583,6 +592,7 @@ def create_default_section_element(
583592
parent=parent,
584593
tag="SECTION",
585594
property_is_composite="True",
595+
property_prefix="",
586596
property_view_style="",
587597
fields=fields,
588598
relations=[],

strictdoc/backend/sdoc/models/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_parent_or_including_document(self) -> "SDocDocumentIF":
3939
raise NotImplementedError # pragma: no cover
4040

4141
@abstractmethod
42-
def get_requirement_prefix(self) -> str:
42+
def get_prefix(self) -> Optional[str]:
4343
raise NotImplementedError # pragma: no cover
4444

4545

@@ -57,7 +57,7 @@ def get_document(self) -> Optional["SDocDocumentIF"]:
5757
raise NotImplementedError # pragma: no cover
5858

5959
@abstractmethod
60-
def get_requirement_prefix(self) -> str:
60+
def get_prefix(self) -> str:
6161
raise NotImplementedError # pragma: no cover
6262

6363
@abstractmethod
@@ -82,7 +82,7 @@ class SDocDocumentIF(ABC):
8282
is_bundle_document: bool
8383

8484
@abstractmethod
85-
def get_requirement_prefix(self) -> str:
85+
def get_prefix(self) -> str:
8686
raise NotImplementedError # pragma: no cover
8787

8888
@abstractmethod

strictdoc/backend/sdoc/models/node.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,14 +531,52 @@ def get_field_human_title_for_statement(self) -> str:
531531
field_human_title = element.fields_map[element.content_field[0]]
532532
return field_human_title.get_field_human_name()
533533

534-
def get_requirement_prefix(self) -> str:
534+
def get_prefix(self) -> Optional[str]:
535+
if (
536+
own_prefix := self._get_cached_field(
537+
RequirementFieldName.PREFIX, singleline_only=True
538+
)
539+
) is not None:
540+
if own_prefix == "None":
541+
return None
542+
return own_prefix
543+
544+
document: SDocDocumentIF = assert_cast(
545+
self.get_document(), SDocDocumentIF
546+
)
547+
grammar: DocumentGrammar = assert_cast(
548+
document.grammar, DocumentGrammar
549+
)
550+
element: GrammarElement = grammar.elements_by_type[self.node_type]
551+
if (element_prefix := element.property_prefix) is not None:
552+
if element_prefix == "None":
553+
return None
554+
return element_prefix
555+
535556
parent: Union[
536557
SDocDocumentIF, SDocSectionIF, SDocNodeIF, SDocCompositeNodeIF
537558
] = assert_cast(
538559
self.parent,
539560
(SDocDocumentIF, SDocSectionIF, SDocNodeIF, SDocCompositeNodeIF),
540561
)
541-
return parent.get_requirement_prefix()
562+
return parent.get_prefix()
563+
564+
def get_prefix_for_new_node(self, node_type: str) -> Optional[str]:
565+
assert isinstance(node_type, str) and len(node_type), node_type
566+
567+
document: SDocDocumentIF = assert_cast(
568+
self.get_document(), SDocDocumentIF
569+
)
570+
grammar: DocumentGrammar = assert_cast(
571+
document.grammar, DocumentGrammar
572+
)
573+
element: GrammarElement = grammar.elements_by_type[node_type]
574+
if (element_prefix := element.property_prefix) is not None:
575+
if element_prefix == "None":
576+
return None
577+
return element_prefix
578+
579+
return self.get_prefix()
542580

543581
def dump_fields_as_parsed(self) -> str:
544582
# FIXME:

strictdoc/backend/sdoc/models/section.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
from typing import List, Optional, Union
77

88
from strictdoc.backend.sdoc.document_reference import DocumentReference
9+
from strictdoc.backend.sdoc.models.document_grammar import (
10+
DocumentGrammar,
11+
GrammarElement,
12+
)
913
from strictdoc.backend.sdoc.models.model import (
1014
SDocDocumentIF,
1115
SDocSectionContentIF,
@@ -137,11 +141,28 @@ def is_root(self) -> bool:
137141
)
138142
return document.config.root is True
139143

140-
def get_requirement_prefix(self) -> str:
144+
def get_prefix(self) -> str:
141145
if self.requirement_prefix is not None:
142146
return self.requirement_prefix
143147
parent: Union[SDocSectionIF, SDocDocumentIF] = self.parent
144-
return parent.get_requirement_prefix()
148+
return parent.get_prefix()
149+
150+
def get_prefix_for_new_node(self, node_type: str) -> Optional[str]:
151+
assert isinstance(node_type, str) and len(node_type), node_type
152+
153+
document: SDocDocumentIF = assert_cast(
154+
self.get_document(), SDocDocumentIF
155+
)
156+
grammar: DocumentGrammar = assert_cast(
157+
document.grammar, DocumentGrammar
158+
)
159+
element: GrammarElement = grammar.elements_by_type[node_type]
160+
if (element_prefix := element.property_prefix) is not None:
161+
if element_prefix == "None":
162+
return None
163+
return element_prefix
164+
165+
return self.get_prefix()
145166

146167
def blacklist_if_needed(self) -> None:
147168
for node_ in self.section_contents:

strictdoc/backend/sdoc/models/type_system.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
class RequirementFieldName:
99
MID = "MID"
1010
UID = "UID"
11+
PREFIX = "PREFIX"
1112
LEVEL = "LEVEL"
1213
STATUS = "STATUS"
1314
TAGS = "TAGS"

0 commit comments

Comments
 (0)