controllers: use ACSV to import groupe instructeurs
Unlike `CSV`, `ACSV` auto-detect the file encoding and separator type.
This commit is contained in:
parent
dee536fca1
commit
f854e3af63
3 changed files with 4 additions and 1 deletions
1
Gemfile
1
Gemfile
|
@ -1,6 +1,7 @@
|
||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
gem 'aasm'
|
gem 'aasm'
|
||||||
|
gem 'acsv'
|
||||||
gem 'active_link_to' # Automatically set a class on active links
|
gem 'active_link_to' # Automatically set a class on active links
|
||||||
gem 'active_model_serializers'
|
gem 'active_model_serializers'
|
||||||
gem 'activestorage-openstack'
|
gem 'activestorage-openstack'
|
||||||
|
|
|
@ -20,6 +20,7 @@ GEM
|
||||||
specs:
|
specs:
|
||||||
aasm (5.1.1)
|
aasm (5.1.1)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
|
acsv (0.0.1)
|
||||||
actioncable (6.1.4.1)
|
actioncable (6.1.4.1)
|
||||||
actionpack (= 6.1.4.1)
|
actionpack (= 6.1.4.1)
|
||||||
activesupport (= 6.1.4.1)
|
activesupport (= 6.1.4.1)
|
||||||
|
@ -779,6 +780,7 @@ PLATFORMS
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
aasm
|
aasm
|
||||||
|
acsv
|
||||||
active_link_to
|
active_link_to
|
||||||
active_model_serializers
|
active_model_serializers
|
||||||
active_storage_validations
|
active_storage_validations
|
||||||
|
|
|
@ -215,7 +215,7 @@ module NewAdministrateur
|
||||||
else
|
else
|
||||||
file = group_csv_file.read
|
file = group_csv_file.read
|
||||||
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 = ACSV::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') }
|
||||||
|
|
||||||
groupes_emails_has_keys = groupes_emails.first.has_key?("groupe") && groupes_emails.first.has_key?("email")
|
groupes_emails_has_keys = groupes_emails.first.has_key?("groupe") && groupes_emails.first.has_key?("email")
|
||||||
|
|
Loading…
Reference in a new issue