def send_test(service_id, template_id): file_name = current_app.config['TEST_MESSAGE_FILENAME'] template = Template(service_api_client.get_service_template( service_id, template_id)['data'], prefix=current_service['name'], sms_sender=current_service['sms_sender']) if len(template.placeholders) == 0 or request.method == 'POST': upload_id = s3upload( service_id, { 'file_name': file_name, 'data': Spreadsheet.from_rows([ [first_column_heading[template.template_type]] + list(template.placeholders), get_example_csv_rows(template, use_example_as_example=False, submitted_fields=request.form) ]).as_csv_data }, current_app.config['AWS_REGION']) session['upload_data'] = { "template_id": template_id, "original_file_name": file_name } return redirect( url_for('.check_messages', upload_id=upload_id, service_id=service_id, template_type=template.template_type, from_test=True, help=2 if request.args.get('help') else 0)) return render_template( 'views/send-test.html', template=template, recipient_column=first_column_heading[template.template_type], example=[get_example_csv_rows(template, use_example_as_example=False)], help=get_help_argument())
def send_test(service_id, template_id): file_name = current_app.config['TEST_MESSAGE_FILENAME'] template = Template( service_api_client.get_service_template(service_id, template_id)['data'], prefix=current_service['name'] ) if len(template.placeholders) == 0 or request.method == 'POST': upload_id = s3upload( service_id, { 'file_name': file_name, 'data': Spreadsheet.from_rows([ [first_column_heading[template.template_type]] + list(template.placeholders), get_example_csv_rows(template, use_example_as_example=False, submitted_fields=request.form) ]).as_csv_data }, current_app.config['AWS_REGION'] ) session['upload_data'] = { "template_id": template_id, "original_file_name": file_name } return redirect(url_for( '.check_messages', upload_id=upload_id, service_id=service_id, template_type=template.template_type, from_test=True, help=2 if request.args.get('help') else 0 )) return render_template( 'views/send-test.html', template=template, recipient_column=first_column_heading[template.template_type], example=[get_example_csv_rows(template, use_example_as_example=False)], help=get_help_argument() )
def send_messages(service_id, template_id): template = Template( service_api_client.get_service_template(service_id, template_id)['data'], prefix=current_service['name'] ) form = CsvUploadForm() if form.validate_on_submit(): try: upload_id = s3upload( service_id, Spreadsheet.from_file(form.file.data, filename=form.file.data.filename).as_dict, current_app.config['AWS_REGION'] ) session['upload_data'] = { "template_id": template_id, "original_file_name": form.file.data.filename } return redirect(url_for('.check_messages', service_id=service_id, upload_id=upload_id, template_type=template.template_type)) except (UnicodeDecodeError, BadZipFile, XLRDError): flash('Couldn’t read {}. Try using a different file format.'.format( form.file.data.filename )) return render_template( 'views/send.html', template=template, column_headings=list(ascii_uppercase[:len(template.placeholders) + 1]), example=[ [first_column_heading[template.template_type]] + list(template.placeholders), get_example_csv_rows(template) ], form=form )
def send_messages(service_id, template_id): template = Template(service_api_client.get_service_template( service_id, template_id)['data'], prefix=current_service['name'], sms_sender=current_service['sms_sender']) form = CsvUploadForm() if form.validate_on_submit(): try: upload_id = s3upload( service_id, Spreadsheet.from_file( form.file.data, filename=form.file.data.filename).as_dict, current_app.config['AWS_REGION']) session['upload_data'] = { "template_id": template_id, "original_file_name": form.file.data.filename } return redirect( url_for('.check_messages', service_id=service_id, upload_id=upload_id, template_type=template.template_type)) except (UnicodeDecodeError, BadZipFile, XLRDError): flash( 'Couldn’t read {}. Try using a different file format.'.format( form.file.data.filename)) return render_template( 'views/send.html', template=template, column_headings=list(ascii_uppercase[:len(template.placeholders) + 1]), example=[[first_column_heading[template.template_type]] + list(template.placeholders), get_example_csv_rows(template)], form=form)