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 actions for list collectors and remove old code #239

Merged
merged 14 commits into from
Aug 25, 2020
Merged
8 changes: 4 additions & 4 deletions app/views/handlers/list_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def get_context(self):
}

def handle_post(self):
if (
self.form.data[self.rendered_block["add_answer"]["id"]]
== self.rendered_block["add_answer"]["value"]
):
answer_action = self._get_answer_action()
action_type = answer_action["type"] if answer_action else None

if action_type == "AddAnswerForListItem":
self._is_adding = True
self.questionnaire_store_updater.update_answers(self.form.data)

Expand Down
8 changes: 4 additions & 4 deletions app/views/handlers/list_remove_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def is_location_valid(self):
return True

def handle_post(self):
if (
self.form.data[self.parent_block["remove_answer"]["id"]]
== self.parent_block["remove_answer"]["value"]
):
answer_action = self._get_answer_action()
action_type = answer_action["type"] if answer_action else None

if action_type == "RemoveAnswerForListItem":
list_name = self.parent_block["for_list"]
self.questionnaire_store_updater.remove_list_item_and_answers(
list_name, self._current_location.list_item_id
Expand Down
7 changes: 3 additions & 4 deletions app/views/handlers/primary_person_list_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ def get_next_location_url(self):

def handle_post(self):
list_name = self.rendered_block["for_list"]
answer_action = self._get_answer_action()
action_type = answer_action["type"] if answer_action else None

if (
self.form.data[self.rendered_block["add_or_edit_answer"]["id"]]
== self.rendered_block["add_or_edit_answer"]["value"]
):
if action_type == "AddOrEditAnswerForListItem":
self._is_adding = True
self.questionnaire_store_updater.update_answers(self.form.data)
self._primary_person_id = self.questionnaire_store_updater.add_primary_person(
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_validator.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
tag=latest
tag=add-answer-action-for-lists
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To revert back later

docker pull onsdigital/eq-questionnaire-validator:$tag
docker run -d -p 5001:5000 "onsdigital/eq-questionnaire-validator:$tag"
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@
"id": "anyone-else-live-at",
"type": "ListCollector",
"for_list": "people",
"add_answer": {
"id": "anyone-else-live-at-answer",
"value": "Yes"
},
"remove_answer": {
"id": "remove-confirmation",
"value": "Yes"
},
"question": {
"id": "confirmation-question",
"type": "General",
Expand All @@ -98,7 +90,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "AddAnswerForListItem"
}
},
{
"label": "No",
Expand Down Expand Up @@ -180,7 +175,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "RemoveAnswerForListItem"
}
},
{
"label": "No",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@
"id": "anyone-else-live-at",
"type": "ListCollector",
"for_list": "people",
"add_answer": {
"id": "anyone-else-live-at-answer",
"value": "Yes"
},
"remove_answer": {
"id": "remove-confirmation",
"value": "Yes"
},
"question": {
"id": "confirmation-question",
"type": "General",
Expand All @@ -98,7 +90,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "AddAnswerForListItem"
}
},
{
"label": "No",
Expand Down Expand Up @@ -180,7 +175,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "AddAnswerForListItem"
}
},
{
"label": "No",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@
"id": "list-collector",
"type": "ListCollector",
"for_list": "people",
"add_answer": {
"id": "anyone-else",
"value": "Yes"
},
"remove_answer": {
"id": "remove-confirmation",
"value": "Yes"
},
"question": {
"id": "confirmation-question",
"type": "General",
Expand All @@ -61,7 +53,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "AddAnswerForListItem"
}
},
{
"label": "No",
Expand Down Expand Up @@ -132,7 +127,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "RemoveAnswerForListItem"
}
},
{
"label": "No",
Expand Down
27 changes: 12 additions & 15 deletions test_schemas/en/test_individual_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@
"id": "primary-person-list-collector",
"type": "PrimaryPersonListCollector",
"for_list": "household",
"add_or_edit_answer": {
"id": "you-live-here",
"value": "Yes"
},
"add_or_edit_block": {
"id": "add-or-edit-primary-person",
"type": "PrimaryPersonListAddOrEditQuestion",
Expand Down Expand Up @@ -115,7 +111,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "AddOrEditAnswerForListItem"
}
},
{
"label": "No",
Expand All @@ -130,14 +129,6 @@
"id": "list-collector",
"type": "ListCollector",
"for_list": "household",
"add_answer": {
"id": "anyone-else",
"value": "Yes"
},
"remove_answer": {
"id": "remove-confirmation",
"value": "Yes"
},
"question": {
"id": "confirmation-question",
"type": "General",
Expand All @@ -150,7 +141,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "AddAnswerForListItem"
}
},
{
"label": "No",
Expand Down Expand Up @@ -221,7 +215,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "RemoveAnswerForListItem"
}
},
{
"label": "No",
Expand Down
27 changes: 12 additions & 15 deletions test_schemas/en/test_last_viewed_question_guidance.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@
"id": "primary-person-list-collector",
"type": "PrimaryPersonListCollector",
"for_list": "people",
"add_or_edit_answer": {
"id": "you-live-here",
"value": "Yes"
},
"add_or_edit_block": {
"id": "add-or-edit-primary-person",
"type": "PrimaryPersonListAddOrEditQuestion",
Expand Down Expand Up @@ -123,7 +119,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "AddOrEditAnswerForListItem"
}
},
{
"label": "No",
Expand Down Expand Up @@ -207,14 +206,6 @@
"id": "list-collector",
"type": "ListCollector",
"for_list": "people",
"add_answer": {
"id": "anyone-else",
"value": "Yes"
},
"remove_answer": {
"id": "remove-confirmation",
"value": "Yes"
},
"question": {
"id": "confirmation-question",
"type": "General",
Expand All @@ -227,7 +218,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "AddAnswerForListItem"
}
},
{
"label": "No",
Expand Down Expand Up @@ -316,7 +310,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "RemoveAnswerForListItem"
}
},
{
"label": "No",
Expand Down
27 changes: 12 additions & 15 deletions test_schemas/en/test_list_change_evaluates_sections.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
"id": "primary-person-list-collector",
"type": "PrimaryPersonListCollector",
"for_list": "people",
"add_or_edit_answer": {
"id": "you-live-here",
"value": "Yes"
},
"add_or_edit_block": {
"id": "add-or-edit-primary-person",
"type": "PrimaryPersonListAddOrEditQuestion",
Expand Down Expand Up @@ -76,7 +72,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "AddOrEditAnswerForListItem"
}
},
{
"label": "No",
Expand All @@ -91,14 +90,6 @@
"id": "list-collector",
"type": "ListCollector",
"for_list": "people",
"add_answer": {
"id": "anyone-else",
"value": "Yes"
},
"remove_answer": {
"id": "remove-confirmation",
"value": "Yes"
},
"question": {
"id": "confirmation-question",
"type": "General",
Expand All @@ -111,7 +102,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "AddAnswerForListItem"
}
},
{
"label": "No",
Expand Down Expand Up @@ -182,7 +176,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "RemoveAnswerForListItem"
}
},
{
"label": "No",
Expand Down
Loading