|
@@ -68,6 +68,27 @@ class Person < ApplicationRecord
|
68
|
68
|
self.participants.includes(:activity).where(is_organizer: true)
|
69
|
69
|
end
|
70
|
70
|
|
|
71
|
+ # Create multiple Persons from data found in a csv file, return those.
|
|
72
|
+ def self.from_csv(content)
|
|
73
|
+ reader = CSV.parse(content, {headers: true, skip_blanks: true})
|
|
74
|
+
|
|
75
|
+ result = []
|
|
76
|
+ reader.each do |row|
|
|
77
|
+ p = Person.find_by(email: row['email'])
|
|
78
|
+ if not p
|
|
79
|
+ p = Person.new
|
|
80
|
+ p.first_name = row['first_name']
|
|
81
|
+ p.infix = row['infix']
|
|
82
|
+ p.last_name = row['last_name']
|
|
83
|
+ p.email = row['email']
|
|
84
|
+ p.birth_date = Date.strptime(row['birth_date'])
|
|
85
|
+ p.save!
|
|
86
|
+ end
|
|
87
|
+ result << p
|
|
88
|
+ end
|
|
89
|
+
|
|
90
|
+ return result
|
|
91
|
+ end
|
71
|
92
|
private
|
72
|
93
|
# Assert that the person's birth date, if any, lies in the past.
|
73
|
94
|
def birth_date_cannot_be_in_future
|