def letter_template(): branding_style = request.args.get('branding_style') if branding_style == FieldWithNoneOption.NONE_OPTION_VALUE: branding_style = None if branding_style: filename = letter_branding_client.get_letter_branding( branding_style)['filename'] else: filename = 'no-branding' template = {'subject': '', 'content': '', 'template_type': 'letter'} image_url = url_for('no_cookie.letter_branding_preview_image', filename=filename) template_image = str( LetterImageTemplate( template, image_url=image_url, page_count=1, )) resp = make_response( render_template('views/service-settings/letter-preview.html', template=template_image)) resp.headers['X-Frame-Options'] = 'SAMEORIGIN' return resp
def letter_template(): branding_style = request.args.get("branding_style") if branding_style == FieldWithNoneOption.NONE_OPTION_VALUE: branding_style = None if branding_style: filename = letter_branding_client.get_letter_branding(branding_style)["filename"] else: filename = "no-branding" template = {"subject": "", "content": ""} image_url = url_for("main.letter_branding_preview_image", filename=filename) template_image = str( LetterImageTemplate( template, image_url=image_url, page_count=1, ) ) resp = make_response(render_template("views/service-settings/letter-preview.html", template=template_image)) resp.headers["X-Frame-Options"] = "SAMEORIGIN" return resp
def organisation_settings(org_id): email_branding = 'GOV.UK' if current_organisation.email_branding_id: email_branding = email_branding_client.get_email_branding( current_organisation.email_branding_id)['email_branding']['name'] letter_branding = None if current_organisation.letter_branding_id: letter_branding = letter_branding_client.get_letter_branding( current_organisation.letter_branding_id)['name'] return render_template( 'views/organisations/organisation/settings/index.html', email_branding=email_branding, letter_branding=letter_branding, )
def organisation_settings(org_id): email_branding = ('French Government of Canada signature' if current_organisation.default_branding_is_french is True else 'English Government of Canada signature') if current_organisation.email_branding_id: email_branding = email_branding_client.get_email_branding( current_organisation.email_branding_id )['email_branding']['name'] letter_branding = None if current_organisation.letter_branding_id: letter_branding = letter_branding_client.get_letter_branding( current_organisation.letter_branding_id )['name'] return render_template( 'views/organisations/organisation/settings/index.html', email_branding=email_branding, letter_branding=letter_branding, )
def organisation_settings(org_id): email_branding = ( "French Government of Canada signature" if current_organisation.default_branding_is_french is True else "English Government of Canada signature" ) if current_organisation.email_branding_id: email_branding = email_branding_client.get_email_branding(current_organisation.email_branding_id)["email_branding"][ "name" ] letter_branding = None if current_organisation.letter_branding_id: letter_branding = letter_branding_client.get_letter_branding(current_organisation.letter_branding_id)["name"] return render_template( "views/organisations/organisation/settings/index.html", email_branding=email_branding, letter_branding=letter_branding, )
def update_letter_branding(branding_id, logo=None): letter_branding = letter_branding_client.get_letter_branding(branding_id) file_upload_form = SVGFileUpload() letter_branding_details_form = ServiceLetterBrandingDetails( name=letter_branding['name'], ) file_upload_form_submitted = file_upload_form.file.data details_form_submitted = request.form.get( 'operation') == 'branding-details' logo = logo if logo else permanent_letter_logo_name( letter_branding['filename'], 'svg') if file_upload_form_submitted and file_upload_form.validate_on_submit(): upload_filename = upload_letter_temp_logo( file_upload_form.file.data.filename, file_upload_form.file.data, current_app.config['AWS_REGION'], user_id=session["user_id"]) if logo.startswith(LETTER_TEMP_TAG.format(user_id=session['user_id'])): delete_letter_temp_file(logo) return redirect( url_for('.update_letter_branding', branding_id=branding_id, logo=upload_filename)) if details_form_submitted and letter_branding_details_form.validate_on_submit( ): db_filename = letter_filename_for_db(logo, session['user_id']) try: if db_filename == letter_branding['filename']: letter_branding_client.update_letter_branding( branding_id=branding_id, filename=db_filename, name=letter_branding_details_form.name.data, ) return redirect(url_for('main.letter_branding')) else: letter_branding_client.update_letter_branding( branding_id=branding_id, filename=db_filename, name=letter_branding_details_form.name.data, ) upload_letter_svg_logo(logo, db_filename, session['user_id']) return redirect(url_for('main.letter_branding')) except HTTPError as e: if 'name' in e.message: letter_branding_details_form.name.errors.append( e.message['name'][0]) else: raise e except BotoClientError: # we had a problem saving the file - rollback the db changes letter_branding_client.update_letter_branding( branding_id=branding_id, filename=letter_branding['filename'], name=letter_branding['name'], ) file_upload_form.file.errors = [ 'Error saving uploaded file - try uploading again' ] return render_template( 'views/letter-branding/manage-letter-branding.html', file_upload_form=file_upload_form, letter_branding_details_form=letter_branding_details_form, cdn_url=get_logo_cdn_domain(), logo=logo, is_update=True)
def update_letter_branding(branding_id, logo=None): letter_branding = letter_branding_client.get_letter_branding(branding_id) file_upload_form = SVGFileUpload() letter_branding_details_form = ServiceLetterBrandingDetails( name=letter_branding["name"], ) file_upload_form_submitted = file_upload_form.file.data details_form_submitted = request.form.get( "operation") == "branding-details" logo = logo if logo else permanent_letter_logo_name( letter_branding["filename"], "svg") if file_upload_form_submitted and file_upload_form.validate_on_submit(): upload_filename = upload_letter_temp_logo( file_upload_form.file.data.filename, file_upload_form.file.data, current_app.config["AWS_REGION"], user_id=session["user_id"], ) if logo.startswith(LETTER_TEMP_TAG.format(user_id=session["user_id"])): delete_letter_temp_file(logo) return redirect( url_for(".update_letter_branding", branding_id=branding_id, logo=upload_filename)) if details_form_submitted and letter_branding_details_form.validate_on_submit( ): db_filename = letter_filename_for_db(logo, session["user_id"]) try: if db_filename == letter_branding["filename"]: letter_branding_client.update_letter_branding( branding_id=branding_id, filename=db_filename, name=letter_branding_details_form.name.data, ) return redirect(url_for("main.letter_branding")) else: png_file = get_png_file_from_svg(logo) letter_branding_client.update_letter_branding( branding_id=branding_id, filename=db_filename, name=letter_branding_details_form.name.data, ) upload_letter_logos(logo, db_filename, png_file, session["user_id"]) return redirect(url_for("main.letter_branding")) except HTTPError as e: if "name" in e.message: letter_branding_details_form.name.errors.append( e.message["name"][0]) else: raise e except BotoClientError: # we had a problem saving the file - rollback the db changes letter_branding_client.update_letter_branding( branding_id=branding_id, filename=letter_branding["filename"], name=letter_branding["name"], ) file_upload_form.file.errors = [ "Error saving uploaded file - try uploading again" ] return render_template( "views/letter-branding/manage-letter-branding.html", file_upload_form=file_upload_form, letter_branding_details_form=letter_branding_details_form, cdn_url=get_logo_cdn_domain(), logo=logo, is_update=True, )