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
7 changes: 3 additions & 4 deletions app/views/handlers/list_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ 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()

if answer_action and answer_action["type"] == "RedirectToListAddBlock":
self._is_adding = True
self.questionnaire_store_updater.update_answers(self.form.data)

Expand Down
7 changes: 3 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,9 @@ 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()

if answer_action and answer_action["type"] == "RemoveListItemAndAnswers":
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
6 changes: 2 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,9 @@ def get_next_location_url(self):

def handle_post(self):
list_name = self.rendered_block["for_list"]
answer_action = self._get_answer_action()

if (
self.form.data[self.rendered_block["add_or_edit_answer"]["id"]]
== self.rendered_block["add_or_edit_answer"]["value"]
):
if answer_action and answer_action["type"] == "RedirectToListAddBlock":
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 app/views/handlers/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class Question(BlockHandler):
@staticmethod
def _has_redirect_to_list_add_action(answer_action):
return answer_action and answer_action["type"] == "RedirectToListAddQuestion"
return answer_action and answer_action["type"] == "RedirectToListAddBlock"

@cached_property
def form(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"schema_version": "0.0.1",
"data_version": "0.0.3",
"survey_id": "0",
"title": "Test RedirectToListAddQuestion action",
"title": "Test RedirectToListAddBlock action",
"theme": "default",
"description": "A questionnaire to test RedirectToListAddQuestion answer action",
"description": "A questionnaire to test RedirectToListAddBlock answer action",
"metadata": [
{
"name": "user_id",
Expand Down Expand Up @@ -58,7 +58,7 @@
"label": "I think so",
"value": "I think so",
"action": {
"type": "RedirectToListAddQuestion",
"type": "RedirectToListAddBlock",
"params": {
"block_id": "add-person",
"list_name": "people"
Expand All @@ -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": "RedirectToListAddBlock"
}
},
{
"label": "No",
Expand Down Expand Up @@ -180,7 +175,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "RemoveListItemAndAnswers"
}
},
{
"label": "No",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"schema_version": "0.0.1",
"data_version": "0.0.3",
"survey_id": "0",
"title": "Test RedirectToListAddQuestion action",
"title": "Test RedirectToListAddBlock action",
"theme": "default",
"description": "A questionnaire to test RedirectToListAddQuestion answer action",
"description": "A questionnaire to test RedirectToListAddBlock answer action",
"metadata": [
{
"name": "user_id",
Expand Down Expand Up @@ -58,7 +58,7 @@
"label": "Yes",
"value": "Yes",
"action": {
"type": "RedirectToListAddQuestion",
"type": "RedirectToListAddBlock",
"params": {
"block_id": "add-person",
"list_name": "people"
Expand All @@ -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": "RedirectToListAddBlock"
}
},
{
"label": "No",
Expand Down Expand Up @@ -180,7 +175,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "RemoveListItemAndAnswers"
}
},
{
"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": "RedirectToListAddBlock"
}
},
{
"label": "No",
Expand Down Expand Up @@ -132,7 +127,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "RemoveListItemAndAnswers"
}
},
{
"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": "RedirectToListAddBlock"
}
},
{
"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": "RedirectToListAddBlock"
}
},
{
"label": "No",
Expand Down Expand Up @@ -221,7 +215,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "RemoveListItemAndAnswers"
}
},
{
"label": "No",
Expand Down
29 changes: 13 additions & 16 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": "RedirectToListAddBlock"
}
},
{
"label": "No",
Expand All @@ -148,7 +147,7 @@
"block_id": "add-person",
"list_name": "people"
},
"type": "RedirectToListAddQuestion"
"type": "RedirectToListAddBlock"
},
"label": "Yes",
"value": "Yes"
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": "RedirectToListAddBlock"
}
},
{
"label": "No",
Expand Down Expand Up @@ -316,7 +310,10 @@
"options": [
{
"label": "Yes",
"value": "Yes"
"value": "Yes",
"action": {
"type": "RemoveListItemAndAnswers"
}
},
{
"label": "No",
Expand Down
Loading