Merge pull request #10078 from demarches-simplifiees/add_metadata_to_pdf_generation
Tech: ajoute des informations de debug lors de la generation de pdf utilisant weasyprint
This commit is contained in:
commit
b471cbbcb6
4 changed files with 44 additions and 6 deletions
|
@ -20,11 +20,27 @@ module Administrateurs
|
|||
format.pdf do
|
||||
html = render_to_string('/administrateurs/attestation_template_v2s/show', layout: 'attestation', formats: [:html])
|
||||
|
||||
result = Typhoeus.post(WEASYPRINT_URL,
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: { html: html }.to_json)
|
||||
headers = {
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Request-Id' => Current.request_id
|
||||
}
|
||||
|
||||
send_data(result.body, filename: 'attestation.pdf', type: 'application/pdf', disposition: 'inline')
|
||||
body = {
|
||||
html: html,
|
||||
upstream_context: {
|
||||
procedure_id: @procedure.id,
|
||||
path: request.path,
|
||||
user_id: current_user.id
|
||||
}
|
||||
}.to_json
|
||||
|
||||
response = Typhoeus.post(WEASYPRINT_URL, headers:, body:)
|
||||
|
||||
if response.success?
|
||||
send_data(response.body, filename: 'attestation.pdf', type: 'application/pdf', disposition: 'inline')
|
||||
else
|
||||
raise StandardError.new("PDF Generation failed: #{response.return_code} #{response.status_message}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
- content_for :title, @title
|
||||
- content_for :authors do
|
||||
- @authors&.map do |author|
|
||||
%meta{ name: 'author', content: author }
|
||||
- content_for :description do
|
||||
- if @description.present?
|
||||
%meta{ name: 'description', content: @description }
|
||||
- content_for :keywords do
|
||||
- @keywords&.map do |keyword|
|
||||
%meta{ name: 'keywords', content: keyword }
|
||||
|
||||
.a4-container{ class: class_names("official-layout": @attestation_template.official_layout?) }
|
||||
.content
|
||||
%header.first-header
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
%html
|
||||
%html{ lang: 'fr' }
|
||||
%head
|
||||
= stylesheet_link_tag 'attestation', media: 'all'
|
||||
%title= content_for?(:title) ? yield(:title) : 'Attestation'
|
||||
= yield(:authors)
|
||||
= yield(:keywords)
|
||||
= yield(:description)
|
||||
%meta{ name: 'generator', content: ENV.fetch('APP_HOST') }
|
||||
%meta{ name: 'dcterms.created', content: Time.zone.now.iso8601 }
|
||||
|
||||
%body#attestation
|
||||
= yield
|
||||
|
|
|
@ -65,7 +65,12 @@ describe 'As an administrateur, I want to manage the procedure’s attestation',
|
|||
end
|
||||
|
||||
context 'Update attestation v2' do
|
||||
before { Flipper.enable(:attestation_v2) }
|
||||
before do
|
||||
Flipper.enable(:attestation_v2)
|
||||
|
||||
response = Typhoeus::Response.new(code: 200, body: 'Hello world')
|
||||
Typhoeus.stub(WEASYPRINT_URL).and_return(response)
|
||||
end
|
||||
|
||||
scenario do
|
||||
visit admin_procedure_path(procedure)
|
||||
|
|
Loading…
Reference in a new issue