gaku_core 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/gaku/admin/departments_controller.rb +55 -0
- data/app/controllers/gaku/admin/disposals_controller.rb +18 -45
- data/app/controllers/gaku/exams_controller.rb +2 -2
- data/app/controllers/gaku/syllabuses/exams_controller.rb +2 -2
- data/app/helpers/gaku/gaku_helper.rb +7 -0
- data/app/helpers/gaku/translations_helper.rb +4 -0
- data/app/models/gaku/address.rb +1 -1
- data/app/models/gaku/department.rb +13 -0
- data/app/models/gaku/disposal.rb +45 -0
- data/app/models/gaku/exam_portion.rb +1 -1
- data/app/models/gaku/student.rb +2 -2
- data/app/models/gaku/user.rb +1 -1
- data/app/models/gaku/versioning/student_version.rb +7 -12
- data/app/views/gaku/admin/departments/_department.html.slim +2 -0
- data/app/views/gaku/admin/departments/_form.html.slim +3 -0
- data/app/views/gaku/admin/departments/_form_fields.html.slim +1 -0
- data/app/views/gaku/admin/departments/_modal.html.slim +6 -0
- data/app/views/gaku/admin/departments/_table_fields.html.slim +5 -0
- data/app/views/gaku/admin/departments/create.js.erb +7 -0
- data/app/views/gaku/admin/departments/destroy.js.erb +2 -0
- data/app/views/gaku/admin/departments/edit.js.erb +3 -0
- data/app/views/gaku/admin/departments/index.html.slim +20 -0
- data/app/views/gaku/admin/departments/new.js.erb +3 -0
- data/app/views/gaku/admin/departments/update.js.erb +4 -0
- data/app/views/gaku/shared/menu/_admin.html.erb +1 -0
- data/{lib/generators/gaku/install/templates/log/sidekiq.log → app/views/gaku/shared/overrides/students/_import_link.html.slim} +0 -0
- data/app/views/gaku/shared/overrides/syllabuses/_import_link.html.slim +0 -0
- data/app/views/gaku/students/index.html.slim +1 -1
- data/app/views/gaku/syllabuses/index.html.slim +1 -1
- data/config/initializers/active_record.rb +1 -1
- data/config/locales/en.yml +8 -0
- data/config/routes.rb +2 -9
- data/db/default/gaku/attendance_types.rb +18 -8
- data/db/default/gaku/commute_method_types.rb +12 -20
- data/db/default/gaku/departments.rb +14 -0
- data/db/default/gaku/enrollment_status.rb +34 -31
- data/db/default/gaku/scholarship_statuses.rb +11 -8
- data/db/migrate/20120202111850_translated_tables.rb +62 -0
- data/db/migrate/{20120202111850_gaku_core.rb → 20131014065028_gaku_core.rb} +0 -86
- data/lib/gaku/core/version.rb +1 -1
- data/lib/gaku/core.rb +2 -3
- data/lib/gaku/testing/factories/department_factory.rb +11 -0
- data/lib/generators/gaku/install/install_generator.rb +1 -10
- metadata +218 -151
- data/app/controllers/gaku/students/importer_controller.rb +0 -75
- data/app/controllers/gaku/syllabuses/importer_controller.rb +0 -19
- data/app/models/gaku/import_file.rb +0 -5
- data/app/views/gaku/students/importer/index.html.slim +0 -26
- data/app/views/gaku/students/importer/roster_import_preview.html.slim +0 -4
- data/app/views/gaku/syllabuses/importer/index.html.slim +0 -14
- data/app/workers/gaku/importers/students/roster_worker.rb +0 -18
- data/app/workers/gaku/importers/students/school_station_zaikousei_worker.rb +0 -15
- data/config/initializers/sidekiq.rb +0 -6
- data/lib/gaku/exporters/roster_exporter.rb +0 -36
- data/lib/gaku/importers/key_mapper.rb +0 -19
- data/lib/gaku/importers/logger.rb +0 -10
- data/lib/gaku/importers/students/guardians.rb +0 -89
- data/lib/gaku/importers/students/personal_information.rb +0 -65
- data/lib/gaku/importers/students/roster.rb +0 -50
- data/lib/gaku/importers/students/roster_to_student.rb +0 -67
- data/lib/gaku/importers/students/school_station_zaikousei.rb +0 -109
- data/lib/gaku/importers/students/student_identity.rb +0 -17
- data/lib/gaku/testing/factories/import_file_factory.rb +0 -8
- data/lib/generators/gaku/install/templates/Procfile +0 -2
- data/lib/generators/gaku/install/templates/config/sidekiq.yml +0 -8
@@ -1,75 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require 'GenSheet'
|
3
|
-
module Gaku
|
4
|
-
class Students::ImporterController < GakuController
|
5
|
-
|
6
|
-
skip_authorization_check
|
7
|
-
before_action :load_templates, only: :index
|
8
|
-
|
9
|
-
def index
|
10
|
-
@importer_types = {I18n.t('student.roster_sheet') => :import_roster, 'School Station' => :import_school_station_zaikousei}
|
11
|
-
# render 'gaku/students/importer/index'
|
12
|
-
end
|
13
|
-
|
14
|
-
def get_roster
|
15
|
-
template = Template.find(params[:template][:id])
|
16
|
-
#read file from paperclip obejct
|
17
|
-
source_file = File.new(template.file.path)
|
18
|
-
#process with GenSheet
|
19
|
-
sheet = GenSheet.new(source_file).to_xls
|
20
|
-
|
21
|
-
send_file sheet
|
22
|
-
end
|
23
|
-
|
24
|
-
def get_registration_roster
|
25
|
-
exporter = Gaku::Exporters::RosterExporter.new
|
26
|
-
file = exporter.export({})
|
27
|
-
end
|
28
|
-
|
29
|
-
def create
|
30
|
-
redirect_to importer_index_path, alert: I18n.t('errors.messages.file_unreadable') && return if params[:importer][:data_file].nil?
|
31
|
-
file = ImportFile.new(import_params)
|
32
|
-
file.context = 'students'
|
33
|
-
raise 'COULD NOT SAVE FILE' unless file.save
|
34
|
-
|
35
|
-
case params[:importer][:importer_type]
|
36
|
-
when 'import_roster'
|
37
|
-
import_roster(file)
|
38
|
-
when 'import_school_station_zaikousei'
|
39
|
-
import_school_station_zaikousei(file)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def import_params
|
46
|
-
params.require(:importer).permit(:data_file, :importer_type)
|
47
|
-
end
|
48
|
-
|
49
|
-
def load_templates
|
50
|
-
@templates ||= Template.all
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
def import_roster(file)
|
55
|
-
if file.data_file.content_type == 'application/vnd.ms-excel' ||
|
56
|
-
file.data_file.content_type == 'application/vnd.oasis.opendocument.spreadsheet' ||
|
57
|
-
file.data_file.content_type == 'application/xls'
|
58
|
-
Gaku::Importers::Students::RosterWorker.perform_async(file.id)
|
59
|
-
render text: 'Importing Roster'
|
60
|
-
else
|
61
|
-
redirect_to importer_index_path, alert: '[' + file.data_file.content_type + '] ' + I18n.t('errors.messages.file_type_unsupported')
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def import_school_station_zaikousei(file)
|
66
|
-
if file.data_file.content_type == 'application/vnd.ms-excel'
|
67
|
-
Gaku::Importers::Students::SchoolStationZaikouseiWorker.perform_async(file.id)
|
68
|
-
render text: '在校生をSchoolStationからインポート中。'
|
69
|
-
else
|
70
|
-
redirect_to importer_index_path, alert: I18n.t('errors.messages.file_type_unsupported')
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
module Gaku
|
3
|
-
class Syllabuses::ImporterController < GakuController
|
4
|
-
|
5
|
-
skip_authorization_check
|
6
|
-
|
7
|
-
def index
|
8
|
-
#@importer_types = ["GAKU Engine"]
|
9
|
-
render 'gaku/syllabuses/importer/index'
|
10
|
-
end
|
11
|
-
|
12
|
-
def get_template
|
13
|
-
end
|
14
|
-
|
15
|
-
def import_from_template
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
.row-fluid
|
2
|
-
.span12.well
|
3
|
-
.row-fluid
|
4
|
-
.span12
|
5
|
-
= form_tag get_roster_importer_index_path, method: :get do
|
6
|
-
.control-group
|
7
|
-
.controls
|
8
|
-
= label 'template', 'id', t(:'template.plural')
|
9
|
-
= select_tag 'template[id]', options_from_collection_for_select(@templates, :id, :name), {prompt: t(:'template.choose')}
|
10
|
-
.control-group
|
11
|
-
.controls
|
12
|
-
= submit_tag t(:'student.download_roster'), class: 'span3 btn btn-primary'
|
13
|
-
= hr
|
14
|
-
.row-fluid
|
15
|
-
.span12
|
16
|
-
= link_to_file t(:'student.download_registration_roster'), action: :get_registration_roster
|
17
|
-
hr /
|
18
|
-
= form_for :importer, html: { multipart: true } do |f|
|
19
|
-
h3 = t('student.import')
|
20
|
-
= t('file')
|
21
|
-
= f.file_field :data_file
|
22
|
-
br /
|
23
|
-
= t(:'import_format')
|
24
|
-
= select("importer", "importer_type", @importer_types, {include_blank: false})
|
25
|
-
br /
|
26
|
-
= submit_tag t'import'
|
@@ -1,14 +0,0 @@
|
|
1
|
-
.row-fluid
|
2
|
-
.span12.well
|
3
|
-
.row-fluid
|
4
|
-
.span12
|
5
|
-
= link_to_file t(:'syllabus.registration.csv'), action: :get_template id: "get_template"
|
6
|
-
hr /
|
7
|
-
= form_for :importer, url: { action: "import_from_template" }, html: { multipart: true } do |f|
|
8
|
-
label for="importer"
|
9
|
-
= f.file_field :data_file
|
10
|
-
br /
|
11
|
-
= t(:'import_format')
|
12
|
-
= select("importer", "data_type", @importer_types, {include_blank: false})
|
13
|
-
br /
|
14
|
-
= submit_tag 'Submit'
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'roo'
|
2
|
-
require 'GenSheet'
|
3
|
-
|
4
|
-
module Gaku::Importers::Students
|
5
|
-
class RosterWorker
|
6
|
-
include Sidekiq::Worker
|
7
|
-
sidekiq_options retry: false
|
8
|
-
|
9
|
-
def perform(file_id)
|
10
|
-
file = Gaku::ImportFile.find file_id
|
11
|
-
if file
|
12
|
-
Gaku::Importers::Students::Roster.new(file, logger)
|
13
|
-
else
|
14
|
-
raise 'NO FILE'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Gaku::Importers::Students
|
2
|
-
class SchoolStationZaikouseiWorker
|
3
|
-
include Sidekiq::Worker
|
4
|
-
sidekiq_options retry: false
|
5
|
-
|
6
|
-
def perform(file_id)
|
7
|
-
file = Gaku::ImportFile.find file_id
|
8
|
-
if file
|
9
|
-
Gaku::Importers::Students::SchoolStationZaikousei.new(file, logger)
|
10
|
-
else
|
11
|
-
raise 'NO FILE'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,6 +0,0 @@
|
|
1
|
-
require 'sidekiq'
|
2
|
-
#Sidekiq.configure_server do |config|
|
3
|
-
# config.redis = { url: 'redis://redistogo:23997367276d9d8e473756154c3da248@spadefish.redistogo.com:9679/'}
|
4
|
-
#end
|
5
|
-
|
6
|
-
ENV['REDISTOGO_URL'] = 'redis://redistogo:23997367276d9d8e473756154c3da248@spadefish.redistogo.com:9679/'
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require 'roo'
|
3
|
-
require 'GenSheet'
|
4
|
-
|
5
|
-
module Gaku
|
6
|
-
module Exporters
|
7
|
-
class RosterExporter
|
8
|
-
@format
|
9
|
-
@template
|
10
|
-
@workbook
|
11
|
-
|
12
|
-
def initialize(options = {})
|
13
|
-
@format = options[:format] || '.xls'
|
14
|
-
#TODO fix with paperclip
|
15
|
-
@template = options[:template] || 'assets/templates/roster.xls'
|
16
|
-
load_template(@template)
|
17
|
-
end
|
18
|
-
|
19
|
-
def load_template(template)
|
20
|
-
begin
|
21
|
-
@workbook = Roo::Spreadsheet.open(@template)
|
22
|
-
rescue
|
23
|
-
@workbook = Roo::Spreadsheet.new
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def export_all
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def export(records = {})
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Gaku::Importers::KeyMapper
|
2
|
-
def get_keymap(key_syms)
|
3
|
-
keymap = {}
|
4
|
-
key_syms.each do |key|
|
5
|
-
keymap[key] = '^' + I18n.t(key) + '$'#.gsub(' ', ' ')
|
6
|
-
end
|
7
|
-
keymap
|
8
|
-
end
|
9
|
-
|
10
|
-
def filter_keymap(keymap,book)
|
11
|
-
filtered_keymap = {}
|
12
|
-
keymap.each do |key, value|
|
13
|
-
book.each do |row|
|
14
|
-
filtered_keymap[key] = value if row.grep(/#{value}/i).any?
|
15
|
-
end
|
16
|
-
end
|
17
|
-
filtered_keymap
|
18
|
-
end
|
19
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'GenSheet'
|
2
|
-
|
3
|
-
module Gaku::Importers::Students
|
4
|
-
class Guardians
|
5
|
-
include Gaku::Importers::Logger
|
6
|
-
include Gaku::Importers::KeyMapper
|
7
|
-
include Gaku::Importers::Students::StudentIdentity
|
8
|
-
include Gaku::Importers::Students::PersonalInformation
|
9
|
-
|
10
|
-
GUARDIAN_KEY_SYMS = [:'student.id_number', :'student.foreign_id_number',
|
11
|
-
:student_name, :'guardian.relationship', :full_name, :'guardian.surname',
|
12
|
-
:'surname_reading', :'guardian.name', :name_reading, :birth_date,
|
13
|
-
:sex, :email, :phone,
|
14
|
-
:'address.zipcode', :'address.country', :'address.state',
|
15
|
-
:'address.city', :'address.address2', :'address.address1']
|
16
|
-
|
17
|
-
def initialize(file, logger = nil)
|
18
|
-
@logger = logger
|
19
|
-
@book = GenSheet.open(File.open(file.data_file.path)) if file
|
20
|
-
@info = @book.sheet('info').parse(
|
21
|
-
header_search: @book.row(@book.first_row)).last
|
22
|
-
set_locale
|
23
|
-
process_guardians
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def set_locale
|
29
|
-
I18n.locale = @info['locale'].to_sym.presence || I18n.default_locale
|
30
|
-
end
|
31
|
-
|
32
|
-
def process_guardians
|
33
|
-
@book.sheet(I18n.t('guardian.plural'))
|
34
|
-
|
35
|
-
keymap = get_keymap GUARDIAN_KEY_SYMS
|
36
|
-
filtered_keymap = filter_keymap(keymap, @book)
|
37
|
-
|
38
|
-
@book.each_with_index(filtered_keymap) do |row, i|
|
39
|
-
process_row(row) unless i == 0
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def process_row(row)
|
44
|
-
student = find_student_by_student_ids(row[:student_id_number], row[:student_foreign_id_number])
|
45
|
-
add_guardian(row, student) unless student.nil?
|
46
|
-
end
|
47
|
-
|
48
|
-
def add_guardian(row, student)
|
49
|
-
if row[:'guardian.name'] != nil && row[:'guardian.name'] != '' # name filled
|
50
|
-
guardian_name = row[:'guardian.name']
|
51
|
-
log 'Guardian with name: ' + guardian_name
|
52
|
-
if row[:'guardian.surname'] == nil || row[:'guardian.suranme'] == ''
|
53
|
-
guardian_surname = student.surname
|
54
|
-
else
|
55
|
-
guardian_surname = row[:'guardian.surname']
|
56
|
-
end
|
57
|
-
elsif !row[:full_name] == nil && row[:full_name] != '' # use full name
|
58
|
-
guardian_name_parts = row[:full_name].sub(' ', ' ').split(' ')
|
59
|
-
guardian_surname = guardian_name_parts.first
|
60
|
-
guardian_name = guardian_name_parts.last
|
61
|
-
else # no name, so can't register guardian
|
62
|
-
return
|
63
|
-
end
|
64
|
-
|
65
|
-
#TODO find existing guardian
|
66
|
-
log "Registering new Guardian '#{guardian_surname} #{guardian_name}' " +
|
67
|
-
"to Student [#{student.student_id_number}] #{student.formatted_name}."
|
68
|
-
guardian = student.guardians.new #guardian.new
|
69
|
-
guardian.name = guardian_name
|
70
|
-
guardian.surname = guardian_surname
|
71
|
-
|
72
|
-
guardian.save
|
73
|
-
|
74
|
-
guardian.name_reading = row[:name_reading]
|
75
|
-
guardian.surname_reading = row[:surname_reading]
|
76
|
-
guardian.relationship = row[:'guardian.relationship']
|
77
|
-
|
78
|
-
add_address(row, guardian)
|
79
|
-
add_contacts(row, guardian)
|
80
|
-
reg_sex(row, guardian)
|
81
|
-
reg_birthdate(row, guardian)
|
82
|
-
|
83
|
-
guardian.save
|
84
|
-
|
85
|
-
student.guardians << guardian
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module Gaku::Importers::Students::PersonalInformation
|
2
|
-
def add_contacts(row, person)
|
3
|
-
phone = row[:phone]
|
4
|
-
unless person.contacts.where(contact_type_id: Gaku::ContactType.where(
|
5
|
-
name: 'Phone').first.id, data: phone).exists?
|
6
|
-
person.contacts.create!(contact_type_id:
|
7
|
-
Gaku::ContactType.wherprimary: true,
|
8
|
-
emergency: true, data: phone) unless (phone.nil? || phone == '')
|
9
|
-
end
|
10
|
-
|
11
|
-
email = row[:email]
|
12
|
-
unless person.contacts.where(contact_type_id: Gaku::ContactType.where(
|
13
|
-
name: 'Email').first.id, data: email).exists?
|
14
|
-
person.contacts.create!(contact_type_id: Gaku::ContactType.where(name: 'Email').first.id, primary: true,
|
15
|
-
emergency: true, data: email) unless (email.nil? || email == '')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def add_address(row, person)
|
20
|
-
if row[:'address.address1']
|
21
|
-
state = nil
|
22
|
-
unless (row[:'address.state'].nil? || row[:'address.state'] == '')
|
23
|
-
state = Gaku::State.where(name: row[:'address.state']).first
|
24
|
-
if state == nil
|
25
|
-
log 'State: "' + row[:'address.state'] + '" not found. Please register and retry import.'
|
26
|
-
return
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
country = Gaku::Country.where(name: '日本').first
|
31
|
-
unless Gaku::Country.where(name: row[:'address.country']).first.nil?
|
32
|
-
country = Gaku::Country.where(name: row[:'address.country']).first
|
33
|
-
end
|
34
|
-
|
35
|
-
unless person.addresses.where(zipcode: row[:'address.zipcode'].to_s,
|
36
|
-
country_id: country.id, state_id: state.id, city: row[:'city'],
|
37
|
-
address1: row[:'address.address1'], address2: row[:'address.address2']).exists?
|
38
|
-
|
39
|
-
person_address = person.addresses.create!(zipcode: row[:'address.zipcode'],
|
40
|
-
country_id: country.id, state: state, city: row[:'city'],
|
41
|
-
address1: row[:'address.address1'], address2: row[:'address.address2'])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def reg_sex(row, person)
|
47
|
-
gender = nil
|
48
|
-
if row[:sex] == I18n.t('gender.female')
|
49
|
-
gender = 0
|
50
|
-
elsif row[:sex] == I18n.t('gender.male')
|
51
|
-
gender = 1
|
52
|
-
end
|
53
|
-
person.gender = gender
|
54
|
-
end
|
55
|
-
|
56
|
-
def reg_birthdate(row, person)
|
57
|
-
#birth_date = Date.strptime(row['birth_date']).to_s
|
58
|
-
#begin
|
59
|
-
# birth_date = Date.strptime(row['birth_date'].to_s, "%Y/%m/%d")
|
60
|
-
#rescue
|
61
|
-
# birth_date = Date.civil(1899, 12, 31) + row['birth_date'].to_i.days - 1.day
|
62
|
-
#end
|
63
|
-
person.birth_date = row[:birth_date]
|
64
|
-
end
|
65
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'GenSheet'
|
2
|
-
|
3
|
-
module Gaku::Importers::Students
|
4
|
-
class Roster
|
5
|
-
include Gaku::Importers::Logger
|
6
|
-
include Gaku::Importers::KeyMapper
|
7
|
-
|
8
|
-
ROSTER_KEY_SYMS = [:'student.id_number', :'student.foreign_id_number',
|
9
|
-
:full_name, :full_name_reading, :name, :name_reading,
|
10
|
-
:middle_name, :middle_name_reading, :surname, :surname_reading,
|
11
|
-
:sex, :birth_date, :admitted, :phone, :email,
|
12
|
-
:'address.zipcode', :'address.country', :'address.state',
|
13
|
-
:'address.city', :'address.address2', :'address.address1']
|
14
|
-
|
15
|
-
def initialize(file, logger = nil)
|
16
|
-
@logger = logger
|
17
|
-
@book = GenSheet.open(File.open(file.data_file.path)) if file
|
18
|
-
@info = @book.sheet('info').parse(
|
19
|
-
header_search: @book.row(@book.first_row)).last
|
20
|
-
set_locale
|
21
|
-
process_roster
|
22
|
-
|
23
|
-
Gaku::Importers::Students::Guardians.new(file, logger)
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def set_locale
|
29
|
-
I18n.locale = @info['locale'].to_sym.presence || I18n.default_locale
|
30
|
-
end
|
31
|
-
|
32
|
-
def process_roster
|
33
|
-
@book.sheet(I18n.t('student.roster'))
|
34
|
-
|
35
|
-
keymap = get_keymap ROSTER_KEY_SYMS
|
36
|
-
filtered_keymap = filter_keymap(keymap, @book)
|
37
|
-
|
38
|
-
@book.each_with_index(filtered_keymap) do |row, i|
|
39
|
-
process_row(row) unless i == 0
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def process_row(row)
|
44
|
-
ActiveRecord::Base.transaction do
|
45
|
-
Gaku::Importers::Students::RosterToStudent.new(
|
46
|
-
row, @info, @logger)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'GenSheet'
|
2
|
-
|
3
|
-
module Gaku::Importers::Students
|
4
|
-
class RosterToStudent
|
5
|
-
include Gaku::Importers::Logger
|
6
|
-
include Gaku::Importers::Students::StudentIdentity
|
7
|
-
include Gaku::Importers::Students::PersonalInformation
|
8
|
-
|
9
|
-
def initialize(row, info, logger = nil)
|
10
|
-
@logger = logger
|
11
|
-
I18n.locale = info['locale'].to_sym.presence || I18n.default_locale
|
12
|
-
|
13
|
-
student = find_or_create_student(row)
|
14
|
-
reg_id(row, student)
|
15
|
-
reg_name(row, student)
|
16
|
-
reg_sex(row, student)
|
17
|
-
reg_birthdate(row, student)
|
18
|
-
student.save
|
19
|
-
|
20
|
-
add_contacts(row, student)
|
21
|
-
add_address(row, student)
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def find_or_create_student(row)
|
27
|
-
student = find_student_by_student_ids(row[:student_id_number], row[:student_foreign_id_number])
|
28
|
-
|
29
|
-
unless student.nil?
|
30
|
-
log "Updating student record with Student ID[#{
|
31
|
-
student.student_id_number}]."
|
32
|
-
return student
|
33
|
-
end
|
34
|
-
|
35
|
-
log 'Registering new student from importer.'
|
36
|
-
student = Gaku::Student.new
|
37
|
-
student.enrollment_status = Gaku::EnrollmentStatus.find_by_code('enrolled')
|
38
|
-
student
|
39
|
-
end
|
40
|
-
|
41
|
-
def reg_id(row, student)
|
42
|
-
student.student_id_number = normalize_id_num(row[:student_id_number])
|
43
|
-
student.student_foreign_id_number = normalize_id_num(row[:student_foreign_id_number])
|
44
|
-
end
|
45
|
-
|
46
|
-
def reg_name(row, student)
|
47
|
-
if (!row[:surname].nil? && row[:surname] != '')
|
48
|
-
student.surname = row[:surname]
|
49
|
-
student.middle_name = row[:middle_name]
|
50
|
-
student.name = row[:name]
|
51
|
-
student.surname_reading = row[:surname_reading]
|
52
|
-
student.middle_name_reading = row[:middle_name_reading]
|
53
|
-
student.name_reading = row[:name_reading]
|
54
|
-
elsif (!row[:full_name].nil? && row[:full_name] != '')
|
55
|
-
name_parts = row[:full_name].sub(' ', ' ').split(' ')
|
56
|
-
student.surname = name_parts.first
|
57
|
-
student.name = name_parts.last
|
58
|
-
|
59
|
-
name_reading_parts = row[:full_name_reading].sub(' ', ' ').split(' ')
|
60
|
-
student.surname_reading = name_reading_parts.first
|
61
|
-
student.name_reading = name_reading_parts.last
|
62
|
-
else
|
63
|
-
log 'Could not read student name for: ' + row
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
require 'roo'
|
2
|
-
require 'GenSheet'
|
3
|
-
|
4
|
-
module Gaku::Importers::Students
|
5
|
-
class SchoolStationZaikousei
|
6
|
-
include Gaku::Importers::Logger
|
7
|
-
include Gaku::Importers::Students::RosterKeys
|
8
|
-
|
9
|
-
def initialize(file, logger)
|
10
|
-
@logger = logger
|
11
|
-
file_handle = File.open file.data_file.path
|
12
|
-
book = Roo::Spreadsheet.open file_handle
|
13
|
-
open_zaikousei(book)
|
14
|
-
fix_index(book)
|
15
|
-
keymap = get_keymap
|
16
|
-
# fix_names(book, keymap)
|
17
|
-
# fix_genders(book, keymap)
|
18
|
-
# start(book, keymap)
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
def open_zaikousei(book)
|
23
|
-
I18n.locale = :ja
|
24
|
-
book.sheet(0)
|
25
|
-
end
|
26
|
-
|
27
|
-
def fix_index(book)
|
28
|
-
last_column = 0
|
29
|
-
book.row(1).each_with_index do |cell, i|
|
30
|
-
case cell
|
31
|
-
when 'STUDENTCD'
|
32
|
-
book.set 1, i, I18n.t(:student_id_number)
|
33
|
-
when 'ZAINAM_C'
|
34
|
-
book.set 1, i, I18n.t(:name)
|
35
|
-
when 'ZAINAM_K'
|
36
|
-
book.set 1, i, I18n.t(:name_reading)
|
37
|
-
when 'ZAISEXKN'
|
38
|
-
book.set 1, i, I18n.t(:sex)
|
39
|
-
end
|
40
|
-
|
41
|
-
last_column = i
|
42
|
-
end
|
43
|
-
|
44
|
-
book.set 1, (last_column += 1), I18n.t(:surname)
|
45
|
-
book.set 1, (last_column += 1), I18n.t(:surname_reading)
|
46
|
-
|
47
|
-
book.row(1).each do |cell|
|
48
|
-
log 'cell: ' + cell.to_s
|
49
|
-
end
|
50
|
-
#book.row(1..book.last_row).each do |row|
|
51
|
-
# log row
|
52
|
-
#end
|
53
|
-
end
|
54
|
-
|
55
|
-
def _fix_name(row)
|
56
|
-
name_parts = row[:name].sub(' ', ' ').split(' ')
|
57
|
-
surname = name_parts.first
|
58
|
-
name = name_parts.last
|
59
|
-
row[:surname] = surname
|
60
|
-
row[:name] = name
|
61
|
-
|
62
|
-
name_reading_parts = row[:name_reading].sub(' ', ' ').split(' ')
|
63
|
-
surname_reading = name_reading_parts.first
|
64
|
-
name_reading = name_reading_parts.last
|
65
|
-
row[:surname_reading] = surname_reading
|
66
|
-
row[:name_reading] = name_reading
|
67
|
-
end
|
68
|
-
|
69
|
-
def fix_names(book, keymap)
|
70
|
-
book.each_with_index(keymap) do |row, i|
|
71
|
-
_fix_name(row) unless i == 0
|
72
|
-
end
|
73
|
-
book.each(keymap) do |row|
|
74
|
-
log '名前変換 姓[' + row[:surname] + '] 名[' + row[:name] + ']'
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def fix_genders(book, keymap)
|
79
|
-
end
|
80
|
-
|
81
|
-
def start(book, keymap)
|
82
|
-
book.each_with_index(keymap) do |row, i|
|
83
|
-
process_row(row) unless i == 0
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def student_exists?(row)
|
88
|
-
Gaku::Student.exists?(
|
89
|
-
student_foreign_id_number: row[:foreign_id].to_i.to_s)
|
90
|
-
end
|
91
|
-
|
92
|
-
def update_student(row)
|
93
|
-
end
|
94
|
-
|
95
|
-
def register_student(row)
|
96
|
-
ActiveRecord::Base.transaction do
|
97
|
-
Gaku::Importers::Students::RosterToStudent.new(row)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def process_row(row)
|
102
|
-
if student_exists?(row)
|
103
|
-
update_student(row)
|
104
|
-
else
|
105
|
-
register_student(row)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Gaku::Importers::Students::StudentIdentity
|
2
|
-
def normalize_id_num(id_number)
|
3
|
-
if id_number.to_i == 0 # ID is alphanumeric
|
4
|
-
return id_number.to_s
|
5
|
-
else # ID number is a number, defaulted to float from sheet data
|
6
|
-
return id_number.to_i.to_s
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def find_student_by_student_ids(student_id_number, student_foreign_id_number = nil)
|
11
|
-
student = Gaku::Student.where(
|
12
|
-
student_id_number: normalize_id_num(student_id_number)).first
|
13
|
-
return student unless student.nil?
|
14
|
-
Gaku::Student.where(
|
15
|
-
student_foreign_id_number: normalize_id_num(student_foreign_id_number)).first
|
16
|
-
end
|
17
|
-
end
|