Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update populate to match new interface for upload_user_list

  • Loading branch information...
commit 6685403616cce9785204f99d267b82ff6dd00cb8 1 parent 9cf3ad1
@NelleV NelleV authored
Showing with 9 additions and 4 deletions.
  1. +8 −3 app/models/user.rb
  2. +1 −1  db/populate/02_students.rb
View
11 app/models/user.rb
@@ -144,15 +144,20 @@ def self.upload_user_list(user_class, user_list, encoding)
result[:invalid_lines] = [] # store lines that were not processed
# read each line of the file and update classlist
if encoding != nil
- user_list = StringIO.new(Iconv.iconv('UTF-8', encoding, user_list.read).join)
+ user_list = StringIO.new(Iconv.iconv('UTF-8',
+ encoding,
+ user_list.read).join)
end
User.transaction do
processed_users = []
- FasterCSV.parse(user_list.read, :skip_blanks => true, :row_sep => :auto) do |row|
+ FasterCSV.parse(user_list.read,
+ :skip_blanks => true,
+ :row_sep => :auto) do |row|
# don't know how to fetch line so we concat given array
next if FasterCSV.generate_line(row).strip.empty?
if processed_users.include?(row[0])
- result[:invalid_lines] = I18n.t('csv_upload_user_duplicate', {:user_name => row[0]})
+ result[:invalid_lines] = I18n.t('csv_upload_user_duplicate',
+ {:user_name => row[0]})
else
if User.add_user(user_class, row).nil?
result[:invalid_lines] << row.join(",")
View
2  db/populate/02_students.rb
@@ -2,5 +2,5 @@
if File.readable?(STUDENT_CSV)
csv_students = File.new(STUDENT_CSV)
- User.upload_user_list(Student, csv_students.read)
+ User.upload_user_list(Student, csv_students, nil)
end
Please sign in to comment.
Something went wrong with that request. Please try again.