Commit b913318a authored by Rafael Ravedutti's avatar Rafael Ravedutti

Adjust CSV log file and include example file routes

Signed-off-by: Rafael Ravedutti's avatarRafael Ravedutti <rrlmachado@inf.ufpr.br>
parent 239bb842
Pipeline #16864 passed with stages
in 4 minutes and 35 seconds
......@@ -144,6 +144,22 @@ module Api::V1
def destroy
end
# GET /citizen_uploads/example_file_xls
def example_xls
filename = "#{Rails.root.to_s}/public/citizen_upload_example.xls"
content_type = "application/xls"
send_file filename, :type => content_type, :x_sendfile => true
end
# GET /citizen_uploads/example_file_ods
def example_ods
filename = "#{Rails.root.to_s}/public/citizen_upload_example.ods"
content_type = "application/vnd.oasis.opendocument.spreadsheet"
send_file filename, :type => content_type, :x_sendfile => true
end
private
# Use callbacks to share common setup or constraints between actions.
......
......@@ -108,7 +108,6 @@ class CitizenUploadWorker
if permission != "adm_c3sl" and citizen.city_id != city_id
# If there was a permission error, store it in the errors hash
errors.push([
line_number,
citizen_params[:name],
citizen_params[:cpf],
citizen_params[:rg],
......@@ -121,6 +120,7 @@ class CitizenUploadWorker
citizen_params[:email],
citizen_params[:pcd],
citizen_params[:note],
line_number,
"Permission denied for this city"
])
......@@ -159,11 +159,22 @@ class CitizenUploadWorker
end
else
# Full messages string
full_messages_string = nil
# Go through error messages
citizen.errors.full_messages.each do |message|
# Add current error in the list of errors
if full_messages_string.present?
full_messages_string = "#{full_messages_string} / #{message}"
else
full_messages_string = message
end
end
# If there are errors, insert them into the log
if full_messages_string.present?
# Add current citizen in the list of errors
errors.push([
line_number,
citizen_params[:name],
citizen_params[:cpf],
citizen_params[:rg],
......@@ -176,7 +187,8 @@ class CitizenUploadWorker
citizen_params[:email],
citizen_params[:pcd],
citizen_params[:note],
message
line_number,
full_messages_string
])
end
end
......@@ -249,9 +261,9 @@ class CitizenUploadWorker
CSV.open(path, "wb") do |csv|
# Add headers to log
csv << [
"Linha", "Nome", "CPF", "RG", "Data de Nascimento", "CEP",
"Nome", "CPF", "RG", "Data de Nascimento", "CEP",
"Numero", "Complemento", "Telefone 1", "Telefone 2", "E-mail",
"Deficiencia", "Observacao", "Erro"
"Deficiencia", "Observacao", "Linha", "Erros"
]
# Go through the errors to add them into the log
......
......@@ -36,6 +36,9 @@ Rails.application.routes.draw do
end
end
get "citizen_uploads/example_ods" => "citizen_uploads#example_ods"
get "citizen_uploads/example_xls" => "citizen_uploads#example_xls"
resources :citizen_uploads
resources :occupations
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment