From cd1d4356fb9d45a0d44c2f5ec4a169892d76b59e Mon Sep 17 00:00:00 2001 From: saurabhbhatia Date: Mon, 16 Sep 2013 17:12:22 +0800 Subject: [PATCH] Updated import data to get complete teacher and announcement data --- .../admin/import_data_controller.rb | 73 +++++++++++++------ .../get_announcement_data.html.erb | 1 + .../admin/users_new_interface/index.html.erb | 1 + 3 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 app/views/admin/import_data/get_announcement_data.html.erb diff --git a/app/controllers/admin/import_data_controller.rb b/app/controllers/admin/import_data_controller.rb index 0718df9bf..c4f25da1f 100644 --- a/app/controllers/admin/import_data_controller.rb +++ b/app/controllers/admin/import_data_controller.rb @@ -8,7 +8,7 @@ class Admin::ImportDataController < OrbitBackendController include Admin::FrontendWidgetInterface def get_teacher_data - uri = URI("https://tp.rulingcom.com:33333/teachers.xml") + uri = URI("https://localhost:8000/teachers.xml") #params = {"UnitName" => "管理學院".encode('big5-uao'), "account" => "manage"} #uri.query = URI.encode_www_form(params) @@ -18,7 +18,8 @@ class Admin::ImportDataController < OrbitBackendController @teachers = @teacher_data["objects"] @i = 5000 @teachers.each do |hash| - @roles = Role.all + # @roles = Role.skip(1).first + @roles = Role.all @teacher = User.new I18n.locale = :zh_tw if hash['teacher_zh_tw'].blank? && hash['teacher_en'].blank? @@ -33,13 +34,13 @@ class Admin::ImportDataController < OrbitBackendController @teacher.first_name = "Please Fill the Name" elsif hash['teacher_en'].blank? && !hash['teacher_zh_tw'].blank? @teacher.first_name = hash['teacher_zh_tw'] - else + elsif !hash['teacher_en'].blank? && hash['teacher_zh_tw'].blank? @teacher.first_name = hash['teacher_en'] end #@teacher.first_name = hash['teacher_en'] @teacher.ntu_seq = hash['ntu_seq'] - @teacher.role_ids = ["#{@roles.first.id}"] + @teacher.role_ids = ["#{@roles.skip(1).first.id}"] @teacher.password = "testpass" @i += 10 if hash['email'].blank? @@ -48,12 +49,12 @@ class Admin::ImportDataController < OrbitBackendController @teacher.email = hash['email'] end - if hash['teacher_zh_tw'].blank? - @teacher.user_id = hash['teacher_en'] + if hash['teacher_zh_tw'].blank? && hash['teacher_en'].blank? + @teacher.user_id = "defaultuser" elsif hash['teacher_en'].blank? @teacher.user_id = hash['teacher_zh_tw'] - else - @teacher.user_id = "Please Enter a User Name" + elsif hash['teacher_zh_tw'] + @teacher.user_id = hash['teacher_en'] end @teacher.save! end @@ -85,13 +86,20 @@ class Admin::ImportDataController < OrbitBackendController if @books.present? @books.each do |b| @book = WritingBook.new + I18n.locale = :zh_tw @book.authors = b[:author] @book.paper_title = b[:title] @book.book_title = b[:book_title] - @book.year = b[:year] @book.note = b[:remarks] - @book.publisher = b[:publisher] - @book.create_user_id = hash.id + @book.publisher = b[:publisher] + I18n.locale = :en + @book.authors = b[:author] + @book.paper_title = b[:title] + @book.book_title = b[:book_title] + @book.note = b[:remarks] + @book.publisher = b[:publisher] + @book.year = b[:year] + @book.create_user_id = hash.id @book.save end else @@ -129,14 +137,23 @@ class Admin::ImportDataController < OrbitBackendController if @conference_papers.present? @conference_papers.each do |b| @conference_paper = WritingConference.new + I18n.locale = :zh_tw @conference_paper.authors = b[:author] if b[:title].blank? @conference_paper.paper_title = "No Title Present" else @conference_paper.paper_title = b[:title] end - @conference_paper.year = b[:year] @conference_paper.note = b[:remarks] + I18n.locale = :en + @conference_paper.authors = b[:author] + if b[:title].blank? + @conference_paper.paper_title = "No Title Present" + else + @conference_paper.paper_title = b[:title] + end + @conference_paper.note = b[:remarks] + @conference_paper.year = b[:year] @conference_paper.create_user_id = hash.id @conference_paper.save! end @@ -180,15 +197,23 @@ class Admin::ImportDataController < OrbitBackendController if @journal_papers.present? @journal_papers.each do |b| @journal_paper = WritingJournal.new + I18n.locale = :zh_tw @journal_paper.authors = b[:author] if b[:title].blank? @journal_paper.paper_title = "No Title Present" else - title = b[:title].gsub! /"/ - @journal_paper.paper_title = title + @journal_paper.paper_title = b[:title].first end - @journal_paper.year = b[:year] @journal_paper.note = b[:remarks] + I18n.locale = :en + @journal_paper.authors = b[:author] + if b[:title].blank? + @journal_paper.paper_title = "No Title Present" + else + @journal_paper.paper_title = b[:title].first + end + @journal_paper.note = b[:remarks] + @journal_paper.year = b[:year] @journal_paper.vol_no = b[:volumeno] @journal_paper.form_to_start = b[:beginpage] @journal_paper.form_to_end = b[:endpage] @@ -203,7 +228,7 @@ class Admin::ImportDataController < OrbitBackendController end def get_announcement_data - uri = URI("https://tp.rulingcom.com:33333/announcements.xml") + uri = URI("https://localhost:8000/announcements.xml") #params = {"UnitName" => "管理學院".encode('big5-uao'), "account" => "manage"} #uri.query = URI.encode_www_form(params) @@ -227,16 +252,20 @@ class Admin::ImportDataController < OrbitBackendController end I18n.locale = :en - if hash['announcement_title_en'].blank? + if hash['announcement_title_zh_tw'].blank? && hash['announcement_title_en'].blank? + @bulletin.title = "Please Fill the Name" + @bulletin.text = hash['announcement_content_en'] + + elsif hash['announcement_title_en'].blank? @bulletin.title = hash['announcement_zh_tw'] @bulletin.text = hash['announcement_content_en'] - elsif hash['announcement_title_zh_tw'].blank? && hash['announcement_title_en'].blank? - @bulletin.first_name = "Please Fill the Name" - @bulletin.text = hash['announcement_content_en'] - else - @bulletin.first_name = hash['announcement_title_en'] + + elsif hash['announcement_title_zh_tw'].blank? + @bulletin.title = hash['announcement_title_en'] @bulletin.text = hash['announcement_content_en'] end + @bulletin.category_id = "51d2a16438178423c2000001" + @bulletin.is_pending = true @bulletin.save! end diff --git a/app/views/admin/import_data/get_announcement_data.html.erb b/app/views/admin/import_data/get_announcement_data.html.erb new file mode 100644 index 000000000..9751735f2 --- /dev/null +++ b/app/views/admin/import_data/get_announcement_data.html.erb @@ -0,0 +1 @@ +

Successfully Imported Announcement Data!

\ No newline at end of file diff --git a/app/views/admin/users_new_interface/index.html.erb b/app/views/admin/users_new_interface/index.html.erb index d639725ed..a87648fab 100644 --- a/app/views/admin/users_new_interface/index.html.erb +++ b/app/views/admin/users_new_interface/index.html.erb @@ -20,6 +20,7 @@ +