gaku 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -3
  3. data/.travis.yml +11 -8
  4. data/README.md +2 -4
  5. data/VERSION +1 -1
  6. data/core/Guardfile +24 -14
  7. data/core/Rakefile +0 -3
  8. data/core/app/controllers/gaku/admin/disposals_controller.rb +18 -45
  9. data/core/app/controllers/gaku/exams_controller.rb +2 -2
  10. data/core/app/controllers/gaku/syllabuses/exams_controller.rb +2 -2
  11. data/core/app/models/gaku/address.rb +1 -1
  12. data/core/app/models/gaku/disposal.rb +45 -0
  13. data/core/app/models/gaku/exam_portion.rb +1 -1
  14. data/core/app/models/gaku/student.rb +2 -2
  15. data/core/app/models/gaku/user.rb +1 -1
  16. data/core/app/models/gaku/versioning/student_version.rb +7 -12
  17. data/core/app/views/gaku/shared/overrides/students/_import_link.html.slim +0 -0
  18. data/core/app/views/gaku/shared/overrides/syllabuses/_import_link.html.slim +0 -0
  19. data/core/app/views/gaku/students/index.html.slim +1 -1
  20. data/core/app/views/gaku/syllabuses/index.html.slim +1 -1
  21. data/core/config/initializers/active_record.rb +1 -1
  22. data/core/config/routes.rb +1 -9
  23. data/core/db/default/gaku/attendance_types.rb +18 -8
  24. data/core/db/default/gaku/commute_method_types.rb +12 -20
  25. data/core/db/default/gaku/enrollment_status.rb +34 -31
  26. data/core/db/default/gaku/scholarship_statuses.rb +11 -8
  27. data/core/db/migrate/20120202111850_translated_tables.rb +52 -0
  28. data/core/db/migrate/{20120202111850_gaku_core.rb → 20131014065028_gaku_core.rb} +0 -86
  29. data/core/gaku_core.gemspec +43 -40
  30. data/core/lib/gaku/core.rb +2 -3
  31. data/core/lib/gaku/core/version.rb +1 -1
  32. data/core/lib/generators/gaku/install/install_generator.rb +1 -10
  33. data/core/spec/models/address_spec.rb +1 -1
  34. data/core/spec/spec_helper.rb +3 -3
  35. data/gaku_dependencies.rb +2 -12
  36. data/sample/db/sample/gaku/changes/student_changes.rb +3 -3
  37. data/sample/gaku_sample.gemspec +0 -1
  38. data/sample/lib/shared_sample_data.rb +2 -2
  39. metadata +12 -35
  40. data/core/app/controllers/gaku/students/importer_controller.rb +0 -75
  41. data/core/app/controllers/gaku/syllabuses/importer_controller.rb +0 -19
  42. data/core/app/models/gaku/import_file.rb +0 -5
  43. data/core/app/views/gaku/students/importer/index.html.slim +0 -26
  44. data/core/app/views/gaku/students/importer/roster_import_preview.html.slim +0 -4
  45. data/core/app/views/gaku/syllabuses/importer/index.html.slim +0 -14
  46. data/core/app/workers/gaku/importers/students/roster_worker.rb +0 -18
  47. data/core/app/workers/gaku/importers/students/school_station_zaikousei_worker.rb +0 -15
  48. data/core/config/initializers/sidekiq.rb +0 -6
  49. data/core/lib/gaku/exporters/roster_exporter.rb +0 -36
  50. data/core/lib/gaku/importers/key_mapper.rb +0 -19
  51. data/core/lib/gaku/importers/logger.rb +0 -10
  52. data/core/lib/gaku/importers/students/guardians.rb +0 -89
  53. data/core/lib/gaku/importers/students/personal_information.rb +0 -65
  54. data/core/lib/gaku/importers/students/roster.rb +0 -50
  55. data/core/lib/gaku/importers/students/roster_to_student.rb +0 -67
  56. data/core/lib/gaku/importers/students/school_station_zaikousei.rb +0 -109
  57. data/core/lib/gaku/importers/students/student_identity.rb +0 -17
  58. data/core/lib/gaku/testing/factories/import_file_factory.rb +0 -8
  59. data/core/lib/generators/gaku/install/templates/Procfile +0 -2
  60. data/core/lib/generators/gaku/install/templates/config/sidekiq.yml +0 -8
  61. data/core/spec/integration/importers/roster_spec.rb +0 -41
  62. data/core/spec/models/import_file_spec.rb +0 -9
  63. data/core/spec/requests/students/import_export.rb +0 -37
  64. data/core/spec/support/sample_roster.xls +0 -0
  65. data/core/spec/workers/roster_spec.rb +0 -13
@@ -1,5 +0,0 @@
1
- module Gaku
2
- class ImportFile < ActiveRecord::Base
3
- has_attached_file :data_file
4
- end
5
- 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,4 +0,0 @@
1
- h3 student import preview
2
- br /
3
- p = "created students:" + @created_students.to_s
4
- p = "row count:" + @rowcount.to_s
@@ -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,10 +0,0 @@
1
- module Gaku::Importers::Logger
2
- @logger
3
- def log(msg)
4
- if !@logger.nil?
5
- @logger.info(msg)
6
- else
7
- puts msg
8
- end
9
- end
10
- 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