Skip to content

Commit

Permalink
Remove parent block resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
petechd committed Jun 10, 2024
1 parent 4cedbf2 commit 1844db8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
17 changes: 0 additions & 17 deletions app/validators/questionnaire_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,23 +675,6 @@ def get_list_collector_block_id_for_repeating_blocks(self, block_id) -> dict | N
if repeating_block["id"] == block_id:
return block["id"]

def resolve_parent_block_index_for_source(self, parent_block_id: str) -> int:
if (
self.block_ids.index(parent_block_id)
or self.block_ids.index(parent_block_id) == 0
):
return self.block_ids.index(parent_block_id)

if list_collector_id := self.get_list_collector_block_id_for_add_block(
parent_block_id
):
return self.block_ids.index(list_collector_id)

list_collector_with_repeating_blocks_id = (
self.get_list_collector_block_id_for_repeating_blocks(parent_block_id)
)
return self.block_ids.index(list_collector_with_repeating_blocks_id)

def get_section_index_for_section_id(self, section_id: str) -> int:
for index, section in enumerate(self.sections):
if section["id"] == section_id:
Expand Down
8 changes: 3 additions & 5 deletions app/validators/questionnaire_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,10 @@ def validate_list_references(self):
if identifier_reference["source"] == "list":
list_identifier = identifier_reference["identifier"]
if parent_block:
# Parent block might not always be top level "Block" so we need to resolve it below
parent_block_index = self.questionnaire_schema.resolve_parent_block_index_for_source(
parent_block["id"]
)
if (
parent_block_index
self.questionnaire_schema.block_ids.index(
parent_block["id"]
)
< lists_with_context[list_identifier]["block_index"]
):
self.add_error(
Expand Down

0 comments on commit 1844db8

Please sign in to comment.