add windows content type to avoid errors
This commit is contained in:
parent
ebf0b5ce8f
commit
c731f8cf1f
1 changed files with 5 additions and 2 deletions
|
@ -3,6 +3,10 @@ module NewAdministrateur
|
||||||
include ActiveSupport::NumberHelper
|
include ActiveSupport::NumberHelper
|
||||||
ITEMS_PER_PAGE = 25
|
ITEMS_PER_PAGE = 25
|
||||||
CSV_MAX_SIZE = 1.megabytes
|
CSV_MAX_SIZE = 1.megabytes
|
||||||
|
CSV_ACCEPTED_CONTENT_TYPES = [
|
||||||
|
"text/csv",
|
||||||
|
"application/vnd.ms-excel"
|
||||||
|
]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@procedure = procedure
|
@procedure = procedure
|
||||||
|
@ -161,7 +165,7 @@ module NewAdministrateur
|
||||||
end
|
end
|
||||||
|
|
||||||
def import
|
def import
|
||||||
if (group_csv_file.content_type != "text/csv") && (marcel_content_type != "text/csv")
|
if !CSV_ACCEPTED_CONTENT_TYPES.include?(group_csv_file.content_type) && !CSV_ACCEPTED_CONTENT_TYPES.include?(marcel_content_type)
|
||||||
flash[:alert] = "Importation impossible : veuillez importer un fichier CSV"
|
flash[:alert] = "Importation impossible : veuillez importer un fichier CSV"
|
||||||
redirect_to admin_procedure_groupe_instructeurs_path(procedure)
|
redirect_to admin_procedure_groupe_instructeurs_path(procedure)
|
||||||
|
|
||||||
|
@ -171,7 +175,6 @@ module NewAdministrateur
|
||||||
|
|
||||||
else
|
else
|
||||||
file = group_csv_file.read
|
file = group_csv_file.read
|
||||||
# find the original encoding to avoid encoding errors
|
|
||||||
base_encoding = CharlockHolmes::EncodingDetector.detect(file)
|
base_encoding = CharlockHolmes::EncodingDetector.detect(file)
|
||||||
groupes_emails = CSV.new(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true, header_converters: :downcase)
|
groupes_emails = CSV.new(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true, header_converters: :downcase)
|
||||||
.map { |r| r.to_h.slice('groupe', 'email') }
|
.map { |r| r.to_h.slice('groupe', 'email') }
|
||||||
|
|
Loading…
Add table
Reference in a new issue