Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list collector content pages #1156

Merged
merged 107 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
98962e7
Update Prepop branch with changes from main (#1117)
berroar May 30, 2023
3e45486
Update Prepop branch with changes from main (#1119)
berroar Jun 1, 2023
ab062a5
Update Prepop branch with changes from main (#1126)
katie-gardner Jun 5, 2023
920c541
Update Prepop branch with the latest changes from main (#1129)
petechd Jun 7, 2023
3f5ac90
Integrate with SDS endpoint to support loading Prepop data (#1114)
berroar Jun 9, 2023
f8e254b
Update Prepop branch with the latest changes from main (#1136)
petechd Jun 12, 2023
4a13163
Support optional question guidance and descriptions (#1122)
berroar Jun 13, 2023
1a48972
Add validation of calculated sum of dynamic answers (#1120)
petechd Jun 14, 2023
679c304
Update Prepop with Latest Main (#1141)
kylelawsonAND Jun 16, 2023
4a085d7
Feat looping 4.5 (#1128)
katie-gardner Jun 23, 2023
4671845
Looping 2.5 | Repeating Blocks for List Items (#1106)
kylelawsonAND Jun 26, 2023
30b36e0
Initial changes
berroar Jun 27, 2023
ad65fd2
Add changes
berroar Jun 27, 2023
23d214d
Fix schema
berroar Jun 28, 2023
c1043d0
Remove update_section_completeness call in list actions (#1149)
petechd Jun 29, 2023
f1ba0d2
Fix routing
berroar Jun 29, 2023
3c39a05
Lint
berroar Jun 29, 2023
bcb453c
Loading of supplementary data (#1145)
katie-gardner Jun 29, 2023
45f4d2b
Fix logic
berroar Jun 29, 2023
ed5ce70
Integrate sds with launcher (#1147)
kylelawsonAND Jun 30, 2023
f6a1146
Fix summary rendering
berroar Jun 30, 2023
13fb447
Remove unused var
berroar Jun 30, 2023
e054281
Fix list item templates
petechd Jul 3, 2023
0344ea5
Add editable list items
petechd Jul 3, 2023
eefcaf7
Fix schema and linting
petechd Jul 3, 2023
e0467a9
Cleanup and integration test
petechd Jul 4, 2023
755c737
Remove for_list_item_ids call and formatting, cleanup
petechd Jul 4, 2023
3a3031d
Merge main into feature-prepop
MebinAbraham Jul 4, 2023
8fcc75f
Fix hub, router and add new helper method in schemas
petechd Jul 4, 2023
ae7e45b
Merge remote-tracking branch 'origin/main' into merge-main-into-featu…
MebinAbraham Jul 5, 2023
ff223e4
Add functional and refactor generate_pages to support LCC
petechd Jul 5, 2023
3ba2e54
Remove extra fields from schema and use validator branch
petechd Jul 5, 2023
bfaf732
Update Prepop branch with changes from main (#1153)
MebinAbraham Jul 5, 2023
bb620dd
Rename items in test
petechd Jul 5, 2023
af75af1
Merge branch 'feature-prepop' into list-collector-content-pages
petechd Jul 5, 2023
8fd1330
Add some review fixes
petechd Jul 7, 2023
608db74
Add extra content test and remove duplicated list context class
petechd Jul 7, 2023
685b0a9
Remove duplication in summary group
petechd Jul 7, 2023
65e1c7f
Create base class for LC and LCC summary blocks, remove repetition an…
petechd Jul 7, 2023
56eb247
Update LCC completeness check
petechd Jul 7, 2023
51b485c
Decrypt Supplementary Data form SDS API (#1152)
kylelawsonAND Jul 11, 2023
be4494a
Use contents partial and remove duplication in group
petechd Jul 12, 2023
8a8a58d
Remove duplication in template logic
petechd Jul 12, 2023
6589b75
Inherit from LC instead of Question block
petechd Jul 12, 2023
8d99f29
Merge branch 'feature-prepop' into list-collector-content-pages
petechd Jul 13, 2023
38a5f67
Remove title heading block in question template
petechd Jul 13, 2023
7357138
Add extra assertion in func
petechd Jul 13, 2023
ca1ac5d
Remove hub context logic
petechd Jul 13, 2023
468b2b3
Rename method and force key value args
petechd Jul 13, 2023
426ceec
Add multiple review changes
petechd Jul 13, 2023
2fc975f
Add list context changes
petechd Jul 13, 2023
1729efe
Fix unit tests
petechd Jul 13, 2023
e529fb1
Simplify content class, reduce code overwrites
petechd Jul 17, 2023
f576e21
Fix block check in question
petechd Jul 17, 2023
d60cc8a
Remove content from list context
petechd Jul 17, 2023
8720916
Add get_answer_action graceful handling
petechd Jul 17, 2023
9eee605
Remove duplicated is collector complete method
petechd Jul 17, 2023
1765298
Summary groups refactor
petechd Jul 17, 2023
942a4a5
Add inheritance in LC blocks on summary
petechd Jul 17, 2023
6f2bb0c
Fix enabled sections keys population
petechd Jul 17, 2023
ce9a271
Remove extra method
petechd Jul 17, 2023
cdd089f
Fix templates
petechd Jul 17, 2023
86fd9b3
Revert check for listcollectorcontent type in router
berroar Jul 18, 2023
fcb93f8
Remove unneeded check from get enabled section keys
berroar Jul 18, 2023
3960bbc
Remove extra method and add item label
petechd Jul 18, 2023
380bc67
Use identifier rather than unit_id for supplementary data (#1164)
berroar Jul 18, 2023
7a30e2c
Looping 4 - Calculated Summary with repeating blocks (#1157)
katie-gardner Jul 19, 2023
db68222
Solve conflicts after merge
petechd Jul 19, 2023
6bb2afe
Remove /v1/unit_data from SDS_API_BASE_URL (#1168)
kylelawsonAND Jul 21, 2023
d90687c
Update Prepop branch with changes from main (#1167)
MebinAbraham Jul 21, 2023
9c04096
Retry flaky functional tests (#1170)
MebinAbraham Jul 24, 2023
c8e5dad
Resolve conflicts from main
MebinAbraham Jul 24, 2023
453ad02
Merge branch 'feature-prepop' into list-collector-content-pages
petechd Jul 31, 2023
edbd548
Fix linting after merging prepop
petechd Jul 31, 2023
8c9e960
Add code fixes post merge
petechd Jul 31, 2023
37a9298
Add review changes
petechd Jul 31, 2023
ebc053e
Reduce nesting in question get_answer_action
petechd Jul 31, 2023
f68f7bd
Remove duplication in handle post
petechd Jul 31, 2023
3bdb16d
Add list collector const and list collector content check in answer c…
petechd Aug 1, 2023
0ccce2c
Fix functional test
petechd Aug 1, 2023
8810396
Move edit block logic in previous location url logic, fix tests white…
petechd Aug 1, 2023
6421611
Add list collector content repeating in calc summaries
petechd Aug 1, 2023
a16c6d7
Fixes after changing base branch and merging main
petechd Aug 3, 2023
27e0c3b
Add review fixes
petechd Aug 3, 2023
81f02a3
Remove hardcoded return_to, fix nesting for edit block
petechd Aug 3, 2023
7913cde
Remove post merge issues
petechd Aug 3, 2023
5294b5d
Make some changes to handlers on handle post
petechd Aug 4, 2023
2ece67f
Add some extra logic in repeating blocks handle post
petechd Aug 4, 2023
cdf501a
Merge branch 'main' into list-collector-content-pages
petechd Aug 4, 2023
aae122b
Fix schema linting
petechd Aug 4, 2023
0ea13af
Align content list collector logic with standard list collector
petechd Aug 10, 2023
f2918ca
Merge branch 'main' into list-collector-content-pages
petechd Aug 10, 2023
3725185
Fix schema
petechd Aug 10, 2023
f17ee79
Add minor fixes
petechd Aug 16, 2023
cef03e1
Merge branch 'main' into list-collector-content-pages
petechd Aug 16, 2023
c582e80
Fix Continue button
petechd Aug 17, 2023
961a1e6
Remove question import and call
petechd Aug 17, 2023
162354a
Remove partial
petechd Aug 17, 2023
f0a98fc
Remove repetition from generate_pages
petechd Aug 17, 2023
92c81ec
Add contents items and expand test
petechd Aug 17, 2023
8e9bb77
Add comments in question class
petechd Aug 17, 2023
7b4c2f4
Fix type hint LocationType
petechd Aug 17, 2023
92376f2
Merge branch 'main' into list-collector-content-pages
petechd Aug 23, 2023
55165cd
Fix merge conflicts
petechd Aug 25, 2023
1073bd6
Merge branch 'main' into list-collector-content-pages
petechd Aug 29, 2023
558e631
Revert validator
petechd Aug 30, 2023
15a2e38
Merge branch 'main' into list-collector-content-pages
petechd Aug 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/forms/questionnaire_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def _get_value_source_resolver(list_item: str | None = None) -> ValueSourceResol
question_title = question.get("title")

value_source_resolved_for_location = _get_value_source_resolver(list_item_id)
for answer in question["answers"]:
for answer in question.get("answers", []):
if "list_item_id" in answer:
value_source_resolver = _get_value_source_resolver(answer["list_item_id"])
else:
Expand Down
6 changes: 4 additions & 2 deletions app/jinja_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ def map_summary_item_config(
else:
list_collector_rows = map_list_collector_config(
list_items=block["list"]["list_items"],
editable=block["list"]["editable"],
edit_link_text=edit_link_text,
edit_link_aria_label=edit_link_aria_label,
remove_link_text=remove_link_text,
Expand All @@ -654,6 +655,7 @@ def map_summary_item_config_processor() -> dict[str, Callable]:
@blueprint.app_template_filter() # type: ignore
def map_list_collector_config(
list_items: list[dict[str, str | int]],
editable: bool = True,
render_icon: bool = False,
edit_link_text: str = "",
edit_link_aria_label: str = "",
Expand All @@ -672,7 +674,7 @@ def map_list_collector_config(
edit_link_aria_label_text = None
remove_link_aria_label_text = None

if edit_link_text:
if edit_link_text and editable:
url = (
f'{list_item.get("edit_link")}{item_anchor}'
if item_anchor
Expand All @@ -694,7 +696,7 @@ def map_list_collector_config(

actions.append(edit_link)

if not list_item.get("primary_person") and remove_link_text:
if not list_item.get("primary_person") and remove_link_text and editable:
if remove_link_aria_label:
remove_link_aria_label_text = remove_link_aria_label.format(
item_name=item_name
Expand Down
63 changes: 38 additions & 25 deletions app/questionnaire/questionnaire_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

DEFAULT_LANGUAGE_CODE = "en"

LIST_COLLECTORS_WITH_REPEATING_BLOCKS = {"ListCollector", "ListCollectorContent"}

LIST_COLLECTOR_CHILDREN = [
"ListAddQuestion",
"ListEditQuestion",
Expand Down Expand Up @@ -354,11 +356,12 @@ def _get_blocks_by_id(self) -> dict[str, ImmutableDict]:
self._parent_id_map[block_id] = group["id"]

blocks[block_id] = block
if block["type"] in (
if block["type"] in {
"ListCollector",
"ListCollectorContent",
"PrimaryPersonListCollector",
"RelationshipCollector",
):
}:
self._list_collector_section_ids_by_list_name[
block["for_list"]
].append(self._parent_id_map[group["id"]])
Expand Down Expand Up @@ -619,25 +622,26 @@ def _update_answer_dependencies_for_list_source(
)

for list_collector in list_collectors:
add_block_question = self.get_add_block_for_list_collector(
list_collector["id"] # type: ignore
)["question"]
answer_ids_for_block = list(
self.get_answers_for_question_by_id(add_block_question)
)
for block_answer_id in answer_ids_for_block:
self._answer_dependencies_map[block_answer_id] |= {
self._get_answer_dependent_for_block_id(
block_id=block_id, for_list=list_name
)
if self.is_block_in_repeating_section(block_id)
# non-repeating blocks such as dynamic-answers could depend on the list
else self._get_answer_dependent_for_block_id(block_id=block_id)
}
self._list_dependent_block_additional_dependencies[block_id] = set(
answer_ids_for_block
)
# removing an item from a list will require any dependent calculated summaries to be re-confirmed, so cache dependencies
if add_block := self.get_add_block_for_list_collector( # type: ignore
list_collector["id"]
):
add_block_question = add_block["question"]
answer_ids_for_block = list(
self.get_answers_for_question_by_id(add_block_question)
)
for block_answer_id in answer_ids_for_block:
self._answer_dependencies_map[block_answer_id] |= {
self._get_answer_dependent_for_block_id(
block_id=block_id, for_list=list_name
)
if self.is_block_in_repeating_section(block_id)
# non-repeating blocks such as dynamic-answers could depend on the list
else self._get_answer_dependent_for_block_id(block_id=block_id)
}
self._list_dependent_block_additional_dependencies[block_id] = set(
answer_ids_for_block
)
# removing an item from a list will require any dependent calculated summaries to be re-confirmed, so cache dependencies
if remove_block_id := self.get_remove_block_id_for_list(list_name):
self._list_dependent_block_additional_dependencies[block_id].update(
self.get_answer_ids_for_block(remove_block_id)
Expand Down Expand Up @@ -759,7 +763,10 @@ def get_driving_question_for_list(

def get_remove_block_id_for_list(self, list_name: str) -> str | None:
for block in self.get_blocks():
if block["type"] == "ListCollector" and block["for_list"] == list_name:
if (
is_list_collector_block_editable(block)
katie-gardner marked this conversation as resolved.
Show resolved Hide resolved
and block["for_list"] == list_name
):
remove_block_id: str = block["remove_block"]["id"]
return remove_block_id

Expand Down Expand Up @@ -970,13 +977,15 @@ def get_list_collectors_for_list_for_sections(
for section_id in sections:
if section := self.get_section(section_id):
collector_type = (
"PrimaryPersonListCollector" if primary else "ListCollector"
{"PrimaryPersonListCollector"}
if primary
else LIST_COLLECTORS_WITH_REPEATING_BLOCKS
)

blocks.extend(
block
for block in self.get_blocks_for_section(section)
if block["type"] == collector_type and block["for_list"] == for_list
if block["type"] in collector_type and block["for_list"] == for_list
)

return blocks
Expand Down Expand Up @@ -1171,7 +1180,7 @@ def _block_for_answer(self, answer_id: str) -> ImmutableDict | None:

if (
parent_block
and parent_block["type"] == "ListCollector"
and parent_block["type"] in LIST_COLLECTORS_WITH_REPEATING_BLOCKS
and block_id not in self.list_collector_repeating_block_ids
):
return parent_block
Expand Down Expand Up @@ -1530,3 +1539,7 @@ def get_calculation_block_ids_for_grand_calculated_summary(
calculation_block=grand_calculated_summary_block,
source_type="calculated_summary",
)


def is_list_collector_block_editable(block: Mapping) -> bool:
return bool(block["type"] == "ListCollector")
6 changes: 3 additions & 3 deletions app/questionnaire/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,9 @@ def _get_enabled_section_keys(
self,
) -> Generator[SectionKey, None, None]:
for section_id in self.enabled_section_ids:
repeating_list = self._schema.get_repeating_list_for_section(section_id)

if repeating_list:
if repeating_list := self._schema.get_repeating_list_for_section(
section_id
):
for list_item_id in self._list_store[repeating_list]:
section_key = SectionKey(section_id, list_item_id)
yield section_key
Expand Down
2 changes: 1 addition & 1 deletion app/views/contexts/list_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __call__(
"list": {
"list_items": list_items,
"editable": any([edit_block_id, remove_block_id]),
}
},
}

# pylint: disable=too-many-locals
Expand Down
8 changes: 4 additions & 4 deletions app/views/contexts/section_summary_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
ProgressStore,
SupplementaryDataStore,
)
from app.questionnaire import QuestionnaireSchema
from app.questionnaire import Location, QuestionnaireSchema
from app.questionnaire.questionnaire_schema import LIST_COLLECTORS_WITH_REPEATING_BLOCKS
from app.questionnaire.routing_path import RoutingPath
from app.utilities import safe_content

from ...data_models.metadata_proxy import MetadataProxy
from ...utilities.types import LocationType
from .context import Context
from .summary import Group
from .summary.list_collector_block import ListCollectorBlock
Expand All @@ -31,7 +31,7 @@ def __init__(
metadata: Optional[MetadataProxy],
response_metadata: MutableMapping,
routing_path: RoutingPath,
current_location: LocationType,
current_location: Location,
supplementary_data_store: SupplementaryDataStore,
) -> None:
super().__init__(
Expand Down Expand Up @@ -212,7 +212,7 @@ def _get_refactored_groups(original_groups: dict) -> list[dict[str, Any]]:
non_list_collector_blocks: list[dict[str, str]] = []
list_collector_blocks: list[dict[str, str]] = []
for block in group["blocks"]:
if block["type"] == "ListCollector":
if block["type"] in LIST_COLLECTORS_WITH_REPEATING_BLOCKS:
# if list collector block encountered, close the previously started non list collector blocks list if exists
if non_list_collector_blocks:
previously_started_group = {
Expand Down
38 changes: 32 additions & 6 deletions app/views/contexts/summary/group.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Iterable, Mapping, MutableMapping
from typing import Iterable, Mapping, MutableMapping, Type

from werkzeug.datastructures import ImmutableDict

Expand All @@ -11,11 +11,18 @@
from app.data_models.metadata_proxy import MetadataProxy
from app.questionnaire import QuestionnaireSchema
from app.questionnaire.placeholder_renderer import PlaceholderRenderer
from app.questionnaire.questionnaire_schema import (
LIST_COLLECTORS_WITH_REPEATING_BLOCKS,
is_list_collector_block_editable,
)
from app.survey_config.link import Link
from app.utilities.types import LocationType
from app.views.contexts.summary.block import Block
from app.views.contexts.summary.calculated_summary_block import CalculatedSummaryBlock
from app.views.contexts.summary.list_collector_block import ListCollectorBlock
from app.views.contexts.summary.list_collector_content_block import (
ListCollectorContentBlock,
)


class Group:
katie-gardner marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -107,7 +114,18 @@ def _build_blocks_and_links(
if parent_list_collector_block_id not in routing_path_block_ids:
continue

list_collector_block = ListCollectorBlock(
list_collector_block_class: Type[
ListCollectorBlock | ListCollectorContentBlock
katie-gardner marked this conversation as resolved.
Show resolved Hide resolved
] = (
ListCollectorBlock
if is_list_collector_block_editable(
# Type ignore: return types differ
schema.get_block(parent_list_collector_block_id) # type: ignore
)
else ListCollectorContentBlock
)

list_collector_block = list_collector_block_class(
routing_path_block_ids=routing_path_block_ids,
answer_store=answer_store,
list_store=list_store,
Expand Down Expand Up @@ -174,7 +192,7 @@ def _build_blocks_and_links(
]
)

elif block["type"] == "ListCollector":
elif block["type"] in LIST_COLLECTORS_WITH_REPEATING_BLOCKS:
section: ImmutableDict | None = schema.get_section(location.section_id)

summary_item: ImmutableDict | None
Expand All @@ -183,7 +201,12 @@ def _build_blocks_and_links(
section_id=section["id"], # type: ignore
list_name=block["for_list"],
):
list_collector_block = ListCollectorBlock(
list_collector_block_class = (
ListCollectorBlock
if is_list_collector_block_editable(block)
else ListCollectorContentBlock
)
list_collector_block = list_collector_block_class(
routing_path_block_ids=routing_path_block_ids,
answer_store=answer_store,
list_store=list_store,
Expand All @@ -195,14 +218,17 @@ def _build_blocks_and_links(
language=language,
return_to=return_to,
supplementary_data_store=supplementary_data_store,
return_to_block_id=return_to_block_id,
)

list_summary_element = list_collector_block.list_summary_element(
summary_item
)
blocks.extend([list_summary_element])

if not view_submitted_response:
if (
not view_submitted_response
and is_list_collector_block_editable(block)
):
self.links["add_link"] = Link(
target="_self",
text=list_summary_element["add_link_text"],
Expand Down
Loading