12
12
from app .globals import get_metadata , get_session_store , get_session_timeout_in_seconds
13
13
from app .helpers .language_helper import handle_language
14
14
from app .helpers .schema_helpers import with_schema
15
- from app .helpers .session_helpers import with_questionnaire_store
15
+ from app .helpers .session_helpers import with_questionnaire_store , with_session_store
16
16
from app .helpers .template_helpers import get_census_base_url , render_template
17
17
from app .helpers .url_param_serializer import URLParamSerializer
18
18
from app .questionnaire .location import InvalidLocationException
26
26
)
27
27
from app .views .handlers .feedback import (
28
28
Feedback ,
29
- FeedbackAlreadySent ,
29
+ FeedbackLimitReached ,
30
30
FeedbackNotEnabled ,
31
31
)
32
32
from app .views .handlers .section import SectionHandler
@@ -72,7 +72,10 @@ def before_questionnaire_request():
72
72
@post_submission_blueprint .before_request
73
73
@login_required
74
74
def before_post_submission_request ():
75
- session_data = get_session_store ().session_data
75
+ session_store = get_session_store ()
76
+ session_data = session_store .session_data
77
+ if not session_data .submitted_time :
78
+ raise NotFound
76
79
77
80
handle_language ()
78
81
@@ -277,9 +280,10 @@ def relationships(
277
280
278
281
279
282
@post_submission_blueprint .route ("thank-you/" , methods = ["GET" , "POST" ])
283
+ @with_session_store
280
284
@with_schema
281
- def get_thank_you (schema ):
282
- thank_you = ThankYou (schema )
285
+ def get_thank_you (schema , session_store ):
286
+ thank_you = ThankYou (schema , session_store )
283
287
284
288
if request .method == "POST" :
285
289
if not thank_you .confirmation_email :
@@ -288,37 +292,48 @@ def get_thank_you(schema):
288
292
confirmation_email = thank_you .confirmation_email
289
293
290
294
if confirmation_email .form .validate ():
291
- confirmation_email .handle_post ()
295
+ confirmation_email .handle_post (session_store )
292
296
return redirect (
293
297
url_for (
294
- "post_submission .get_confirmation_email_sent" ,
298
+ ".get_confirmation_email_sent" ,
295
299
email = confirmation_email .get_url_safe_serialized_email (),
296
300
)
297
301
)
298
302
303
+ show_feedback_call_to_action = True
304
+
305
+ try :
306
+ Feedback (schema , session_store , form_data = request .form )
307
+ except (FeedbackNotEnabled , FeedbackLimitReached ):
308
+ show_feedback_call_to_action = False
309
+
299
310
return render_template (
300
311
template = thank_you .template ,
301
- content = thank_you .get_context (),
312
+ content = {
313
+ ** thank_you .get_context (),
314
+ "show_feedback_call_to_action" : show_feedback_call_to_action ,
315
+ },
302
316
survey_id = schema .json ["survey_id" ],
303
317
page_title = thank_you .get_page_title (),
304
318
)
305
319
306
320
307
321
@post_submission_blueprint .route ("confirmation-email/send" , methods = ["GET" , "POST" ])
308
- def send_confirmation_email ():
309
- if not get_session_store ().session_data .confirmation_email_count :
322
+ @with_session_store
323
+ def send_confirmation_email (session_store ):
324
+ if not session_store .session_data .confirmation_email_count :
310
325
raise NotFound
311
326
312
327
try :
313
328
confirmation_email = ConfirmationEmail ()
314
329
except ConfirmationEmailLimitReached :
315
- return redirect (url_for ("post_submission .get_thank_you" ))
330
+ return redirect (url_for (".get_thank_you" ))
316
331
317
332
if request .method == "POST" and confirmation_email .form .validate ():
318
- confirmation_email .handle_post ()
333
+ confirmation_email .handle_post (session_store )
319
334
return redirect (
320
335
url_for (
321
- "post_submission .get_confirmation_email_sent" ,
336
+ ".get_confirmation_email_sent" ,
322
337
email = confirmation_email .get_url_safe_serialized_email (),
323
338
)
324
339
)
@@ -332,12 +347,21 @@ def send_confirmation_email():
332
347
333
348
334
349
@post_submission_blueprint .route ("confirmation-email/sent" , methods = ["GET" ])
335
- def get_confirmation_email_sent ():
336
- if not get_session_store ().session_data .confirmation_email_count :
350
+ @with_session_store
351
+ @with_schema
352
+ def get_confirmation_email_sent (schema , session_store ):
353
+ if not session_store .session_data .confirmation_email_count :
337
354
raise NotFound
338
355
339
356
email = URLParamSerializer ().loads (request .args .get ("email" ))
340
357
358
+ show_feedback_call_to_action = True
359
+
360
+ try :
361
+ Feedback (schema , session_store , form_data = request .form )
362
+ except (FeedbackNotEnabled , FeedbackLimitReached ):
363
+ show_feedback_call_to_action = False
364
+
341
365
return render_template (
342
366
template = "confirmation-email-sent" ,
343
367
content = {
@@ -348,35 +372,35 @@ def get_confirmation_email_sent():
348
372
"hide_signout_button" : False ,
349
373
"show_send_another_email_guidance" : not ConfirmationEmail .is_limit_reached (),
350
374
"sign_out_url" : url_for ("session.get_sign_out" ),
375
+ "show_feedback_call_to_action" : show_feedback_call_to_action ,
351
376
},
352
377
)
353
378
354
379
355
380
@post_submission_blueprint .route ("feedback/send" , methods = ["GET" , "POST" ])
381
+ @with_session_store
356
382
@with_schema
357
- def send_feedback (schema ):
383
+ def send_feedback (schema , session_store ):
358
384
try :
359
- feedback = Feedback (schema , form_data = request .form )
385
+ feedback = Feedback (schema , session_store , form_data = request .form )
360
386
except FeedbackNotEnabled :
361
387
raise NotFound
362
- except FeedbackAlreadySent :
363
- return redirect (url_for ("post_submission.get_feedback_sent" ))
364
388
365
389
if request .method == "POST" and feedback .form .validate ():
366
390
feedback .handle_post ()
367
- return redirect (url_for ("post_submission .get_feedback_sent" ))
391
+ return redirect (url_for (".get_feedback_sent" ))
368
392
369
393
return render_template (
370
394
template = "feedback" ,
371
395
content = feedback .get_context (),
372
- previous_location_url = url_for ("post_submission.get_thank_you" ),
373
396
page_title = feedback .get_page_title (),
374
397
)
375
398
376
399
377
400
@post_submission_blueprint .route ("feedback/sent" , methods = ["GET" ])
378
- def get_feedback_sent ():
379
- if not get_session_store ().session_data .feedback_sent :
401
+ @with_session_store
402
+ def get_feedback_sent (session_store ):
403
+ if not session_store .session_data .feedback_count :
380
404
raise NotFound
381
405
382
406
return render_template (
0 commit comments