Skip to content

Commit

Permalink
Request IR by text message (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
iwootten authored Aug 28, 2020
1 parent cb57c9d commit 908c6d1
Show file tree
Hide file tree
Showing 11 changed files with 809 additions and 317 deletions.
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ flask-login = "*"
"flask-themes2" = "*"
flask-wtf = "*"
gevent = {version = "*",platform_python_implementation = "=='CPython'"}
google-cloud-datastore = "*"
google-cloud-datastore = "==1.14"
grpcio = "*"
gunicorn = "*"
newrelic = "*"
Expand All @@ -60,6 +60,7 @@ flask-compress = "*"
htmlmin = "*"
coloredlogs = "*"
uwsgi = "*"
itsdangerous = "*"

[requires]
python_version = "3.8"
Expand Down
574 changes: 292 additions & 282 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/forms/field_handlers/field_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(
self.metadata = metadata or {}
self.location = location
self.disable_validation = disable_validation
self.question_title = question_title
self.question_title = str(question_title)
self.validation_messages = self.answer_schema.get("validation", {}).get(
"messages", {}
)
Expand Down
94 changes: 92 additions & 2 deletions app/routes/individual_response.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask import Blueprint, g, redirect, request, url_for
from flask import Blueprint, g, redirect, request, url_for, current_app
from flask_login import current_user, login_required
from itsdangerous import URLSafeSerializer
from structlog import get_logger

from app.authentication.no_token_exception import NoTokenException
Expand All @@ -15,6 +16,8 @@
IndividualResponsePostAddressConfirmHandler,
IndividualResponseChangeHandler,
IndividualResponseWhoHandler,
IndividualResponseTextConfirmHandler,
IndividualResponseTextHandler,
)

logger = get_logger()
Expand Down Expand Up @@ -159,7 +162,7 @@ def get_individual_response_post_address_confirmation(schema, questionnaire_stor
return redirect(url_for("questionnaire.get_questionnaire"))

return render_template(
template="individual_response/confirmation",
template="individual_response/confirmation-post",
display_address=questionnaire_store.metadata.get("display_address"),
)

Expand All @@ -183,3 +186,90 @@ def get_individual_response_who(schema, questionnaire_store):
return individual_response_handler.handle_post()

return individual_response_handler.handle_get()


@individual_response_blueprint.route(
"/<list_item_id>/text/enter-number", methods=["GET", "POST"]
)
@login_required
@with_questionnaire_store
@with_schema
def get_individual_response_text_message(schema, questionnaire_store, list_item_id):
language_code = get_session_store().session_data.language_code
url_param_salt = current_app.eq["secret_store"].get_secret_by_name(
"EQ_URL_PARAM_SALT"
)
individual_response_handler = IndividualResponseTextHandler(
schema=schema,
questionnaire_store=questionnaire_store,
language=language_code,
request_args=request.args,
form_data=request.form,
list_item_id=list_item_id,
url_param_salt=url_param_salt,
)

if request.method == "POST" and individual_response_handler.form.validate():
return individual_response_handler.handle_post()

return individual_response_handler.handle_get()


@individual_response_blueprint.route(
"/<list_item_id>/text/confirm-number", methods=["GET", "POST"]
)
@login_required
@with_questionnaire_store
@with_schema
def get_individual_response_text_message_confirm(
schema, questionnaire_store, list_item_id
):
language_code = get_session_store().session_data.language_code
url_param_salt = current_app.eq["secret_store"].get_secret_by_name(
"EQ_URL_PARAM_SALT"
)
individual_response_handler = IndividualResponseTextConfirmHandler(
schema=schema,
questionnaire_store=questionnaire_store,
language=language_code,
request_args=request.args,
form_data=request.form,
list_item_id=list_item_id,
url_param_salt=url_param_salt,
)

if request.method == "POST" and individual_response_handler.form.validate():
return individual_response_handler.handle_post()

return individual_response_handler.handle_get()


@individual_response_blueprint.route("/text/confirmation", methods=["GET", "POST"])
@login_required
@with_questionnaire_store
@with_schema
def get_individual_response_text_message_confirmation(schema, questionnaire_store):
language_code = get_session_store().session_data.language_code
IndividualResponseHandler(
block_definition=None,
schema=schema,
questionnaire_store=questionnaire_store,
language=language_code,
request_args=request.args,
form_data=request.form,
list_item_id=None,
)

if request.method == "POST":
return redirect(url_for("questionnaire.get_questionnaire"))

url_param_salt = current_app.eq["secret_store"].get_secret_by_name(
"EQ_URL_PARAM_SALT"
)
url_serializer = URLSafeSerializer(url_param_salt)
mobile_number = url_serializer.loads(request.args.get("mobile_number"))

return render_template(
template="individual_response/confirmation-text-message",
mobile_number=mobile_number,
)
1 change: 1 addition & 0 deletions app/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"EQ_SERVER_SIDE_STORAGE_USER_IK_SALT",
"EQ_SERVER_SIDE_STORAGE_ENCRYPTION_USER_PEPPER",
"EQ_SECRET_KEY",
"EQ_URL_PARAM_SALT",
"EQ_RABBITMQ_USERNAME",
"EQ_RABBITMQ_PASSWORD",
]
Expand Down
91 changes: 67 additions & 24 deletions app/translations/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2020-08-24 10:48+0100\n"
"POT-Creation-Date: 2020-08-27 12:31+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -272,7 +272,8 @@ msgid "Choose another section to complete"
msgstr ""

#: app/views/contexts/hub_context.py:60
#: templates/individual_response/confirmation.html:19
#: templates/individual_response/confirmation-post.html:19
#: templates/individual_response/confirmation-text-message.html:19
#: templates/individual_response/question.html:5 templates/interstitial.html:8
#: templates/sectionsummary.html:11 templates/sectionsummary.html:53
msgid "Continue"
Expand All @@ -282,74 +283,110 @@ msgstr ""
msgid " (You)"
msgstr ""

#: app/views/handlers/individual_response.py:198
#: app/views/handlers/individual_response.py:208
msgid "How would you like <em>{person_name}</em> to receive a separate census?"
msgstr ""

#: app/views/handlers/individual_response.py:204
#: app/views/handlers/individual_response.py:214
msgid ""
"For someone to complete a separate census, we need to send them an "
"individual access code."
msgstr ""

#: app/views/handlers/individual_response.py:207
#: app/views/handlers/individual_response.py:217
msgid "Select how to send access code"
msgstr ""

#: app/views/handlers/individual_response.py:217
#: app/views/handlers/individual_response.py:227
msgid "Text message"
msgstr ""

#: app/views/handlers/individual_response.py:229
msgid "We will need their mobile number for this"
msgstr ""

#: app/views/handlers/individual_response.py:234
msgid "Post"
msgstr ""

#: app/views/handlers/individual_response.py:219
#: app/views/handlers/individual_response.py:236
msgid ""
"We can only send this to an unnamed resident at the registered household "
"address"
msgstr ""

#: app/views/handlers/individual_response.py:300
#: app/views/handlers/individual_response.py:336
msgid "How would you like to answer <em>{person_name_possessive}</em> questions?"
msgstr ""

#: app/views/handlers/individual_response.py:313
#: app/views/handlers/individual_response.py:349
msgid "I would like to request a separate census for them to complete"
msgstr ""

#: app/views/handlers/individual_response.py:319
#: app/views/handlers/individual_response.py:355
msgid "I will ask them to answer their own questions"
msgstr ""

#: app/views/handlers/individual_response.py:323
#: app/views/handlers/individual_response.py:359
msgid "They will need the household access code from the letter we sent you"
msgstr ""

#: app/views/handlers/individual_response.py:329
#: app/views/handlers/individual_response.py:365
msgid "I will answer for {person_name}"
msgstr ""

#: app/views/handlers/individual_response.py:441
#: app/views/handlers/individual_response.py:477
msgid "Do you want to send an individual access code for {person_name} by post?"
msgstr ""

#: app/views/handlers/individual_response.py:447
#: app/views/handlers/individual_response.py:483
msgid ""
"A letter with an individual access code will be sent to your registered "
"household address"
msgstr ""

#: app/views/handlers/individual_response.py:454
#: app/views/handlers/individual_response.py:490
msgid ""
"The letter will be addressed to <strong>Individual Resident</strong> "
"instead of the name provided"
msgstr ""

#: app/views/handlers/individual_response.py:467
#: app/views/handlers/individual_response.py:503
msgid "Yes, send the access code by post"
msgstr ""

#: app/views/handlers/individual_response.py:471
#: app/views/handlers/individual_response.py:507
msgid "No, send it another way"
msgstr ""

#: app/views/handlers/individual_response.py:622
msgid "Who do you need to request a separate census for?"
msgstr ""

#: app/views/handlers/individual_response.py:672
msgid "What is <em>{person_name_possessive}</em> mobile number?"
msgstr ""

#: app/views/handlers/individual_response.py:682
msgid "UK mobile number"
msgstr ""

#: app/views/handlers/individual_response.py:683
msgid "This will not be stored and only used once to send the access code"
msgstr ""

#: app/views/handlers/individual_response.py:784
msgid "Is this mobile number correct?"
msgstr ""

#: app/views/handlers/individual_response.py:793
msgid "Yes, send the text"
msgstr ""

#: app/views/handlers/individual_response.py:797
msgid "No, I need to change it"
msgstr ""

#: app/views/handlers/question.py:133
msgid "Error: {page_title}"
msgstr ""
Expand Down Expand Up @@ -415,7 +452,7 @@ msgstr ""
msgid "If you can’t answer someone else’s questions"
msgstr ""

#: templates/interstitial.html:23
#: templates/interstitial.html:23 templates/partials/question.html:25
msgid "If you can’t answer questions for this person"
msgstr ""

Expand Down Expand Up @@ -607,12 +644,18 @@ msgid ""
"the survey again."
msgstr ""

#: templates/individual_response/confirmation.html:15
#: templates/individual_response/confirmation-post.html:15
msgid ""
"The letter with an individual access code should arrive soon for them to "
"complete their own census"
msgstr ""

#: templates/individual_response/confirmation-text-message.html:15
msgid ""
"The text message with an individual access code should arrive soon for "
"them to complete their own census"
msgstr ""

#: templates/individual_response/interstitial.html:11
#: templates/layouts/_questionnaire.html:14
msgid "Previous"
Expand Down Expand Up @@ -732,23 +775,23 @@ msgid ""
" of the section</a>"
msgstr ""

#: templates/partials/question.html:53
#: templates/partials/question.html:60
msgid "Selecting this will clear your answer"
msgstr ""

#: templates/partials/question.html:54
#: templates/partials/question.html:61
msgid "cleared"
msgstr ""

#: templates/partials/question.html:57
#: templates/partials/question.html:64
msgid "Selecting this will deselect any selected options"
msgstr ""

#: templates/partials/question.html:58 templates/partials/question.html:66
#: templates/partials/question.html:65 templates/partials/question.html:73
msgid "deselected"
msgstr ""

#: templates/partials/question.html:62
#: templates/partials/question.html:69
msgid "Or"
msgstr ""

Expand Down
Loading

0 comments on commit 908c6d1

Please sign in to comment.