Updated import data to get complete teacher and announcement data

This commit is contained in:
saurabhbhatia 2013-09-16 17:12:22 +08:00
parent d5357ea63c
commit cd1d4356fb
3 changed files with 53 additions and 22 deletions

View File

@ -8,7 +8,7 @@ class Admin::ImportDataController < OrbitBackendController
include Admin::FrontendWidgetInterface include Admin::FrontendWidgetInterface
def get_teacher_data 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"} #params = {"UnitName" => "管理學院".encode('big5-uao'), "account" => "manage"}
#uri.query = URI.encode_www_form(params) #uri.query = URI.encode_www_form(params)
@ -18,7 +18,8 @@ class Admin::ImportDataController < OrbitBackendController
@teachers = @teacher_data["objects"] @teachers = @teacher_data["objects"]
@i = 5000 @i = 5000
@teachers.each do |hash| @teachers.each do |hash|
@roles = Role.all # @roles = Role.skip(1).first
@roles = Role.all
@teacher = User.new @teacher = User.new
I18n.locale = :zh_tw I18n.locale = :zh_tw
if hash['teacher_zh_tw'].blank? && hash['teacher_en'].blank? 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" @teacher.first_name = "Please Fill the Name"
elsif hash['teacher_en'].blank? && !hash['teacher_zh_tw'].blank? elsif hash['teacher_en'].blank? && !hash['teacher_zh_tw'].blank?
@teacher.first_name = hash['teacher_zh_tw'] @teacher.first_name = hash['teacher_zh_tw']
else elsif !hash['teacher_en'].blank? && hash['teacher_zh_tw'].blank?
@teacher.first_name = hash['teacher_en'] @teacher.first_name = hash['teacher_en']
end end
#@teacher.first_name = hash['teacher_en'] #@teacher.first_name = hash['teacher_en']
@teacher.ntu_seq = hash['ntu_seq'] @teacher.ntu_seq = hash['ntu_seq']
@teacher.role_ids = ["#{@roles.first.id}"] @teacher.role_ids = ["#{@roles.skip(1).first.id}"]
@teacher.password = "testpass" @teacher.password = "testpass"
@i += 10 @i += 10
if hash['email'].blank? if hash['email'].blank?
@ -48,12 +49,12 @@ class Admin::ImportDataController < OrbitBackendController
@teacher.email = hash['email'] @teacher.email = hash['email']
end end
if hash['teacher_zh_tw'].blank? if hash['teacher_zh_tw'].blank? && hash['teacher_en'].blank?
@teacher.user_id = hash['teacher_en'] @teacher.user_id = "defaultuser"
elsif hash['teacher_en'].blank? elsif hash['teacher_en'].blank?
@teacher.user_id = hash['teacher_zh_tw'] @teacher.user_id = hash['teacher_zh_tw']
else elsif hash['teacher_zh_tw']
@teacher.user_id = "Please Enter a User Name" @teacher.user_id = hash['teacher_en']
end end
@teacher.save! @teacher.save!
end end
@ -85,13 +86,20 @@ class Admin::ImportDataController < OrbitBackendController
if @books.present? if @books.present?
@books.each do |b| @books.each do |b|
@book = WritingBook.new @book = WritingBook.new
I18n.locale = :zh_tw
@book.authors = b[:author] @book.authors = b[:author]
@book.paper_title = b[:title] @book.paper_title = b[:title]
@book.book_title = b[:book_title] @book.book_title = b[:book_title]
@book.year = b[:year]
@book.note = b[:remarks] @book.note = b[:remarks]
@book.publisher = b[:publisher] @book.publisher = b[:publisher]
@book.create_user_id = hash.id 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 @book.save
end end
else else
@ -129,14 +137,23 @@ class Admin::ImportDataController < OrbitBackendController
if @conference_papers.present? if @conference_papers.present?
@conference_papers.each do |b| @conference_papers.each do |b|
@conference_paper = WritingConference.new @conference_paper = WritingConference.new
I18n.locale = :zh_tw
@conference_paper.authors = b[:author] @conference_paper.authors = b[:author]
if b[:title].blank? if b[:title].blank?
@conference_paper.paper_title = "No Title Present" @conference_paper.paper_title = "No Title Present"
else else
@conference_paper.paper_title = b[:title] @conference_paper.paper_title = b[:title]
end end
@conference_paper.year = b[:year]
@conference_paper.note = b[:remarks] @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.create_user_id = hash.id
@conference_paper.save! @conference_paper.save!
end end
@ -180,15 +197,23 @@ class Admin::ImportDataController < OrbitBackendController
if @journal_papers.present? if @journal_papers.present?
@journal_papers.each do |b| @journal_papers.each do |b|
@journal_paper = WritingJournal.new @journal_paper = WritingJournal.new
I18n.locale = :zh_tw
@journal_paper.authors = b[:author] @journal_paper.authors = b[:author]
if b[:title].blank? if b[:title].blank?
@journal_paper.paper_title = "No Title Present" @journal_paper.paper_title = "No Title Present"
else else
title = b[:title].gsub! /"/ @journal_paper.paper_title = b[:title].first
@journal_paper.paper_title = title
end end
@journal_paper.year = b[:year]
@journal_paper.note = b[:remarks] @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.vol_no = b[:volumeno]
@journal_paper.form_to_start = b[:beginpage] @journal_paper.form_to_start = b[:beginpage]
@journal_paper.form_to_end = b[:endpage] @journal_paper.form_to_end = b[:endpage]
@ -203,7 +228,7 @@ class Admin::ImportDataController < OrbitBackendController
end end
def get_announcement_data 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"} #params = {"UnitName" => "管理學院".encode('big5-uao'), "account" => "manage"}
#uri.query = URI.encode_www_form(params) #uri.query = URI.encode_www_form(params)
@ -227,16 +252,20 @@ class Admin::ImportDataController < OrbitBackendController
end end
I18n.locale = :en 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.title = hash['announcement_zh_tw']
@bulletin.text = hash['announcement_content_en'] @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" elsif hash['announcement_title_zh_tw'].blank?
@bulletin.text = hash['announcement_content_en'] @bulletin.title = hash['announcement_title_en']
else
@bulletin.first_name = hash['announcement_title_en']
@bulletin.text = hash['announcement_content_en'] @bulletin.text = hash['announcement_content_en']
end end
@bulletin.category_id = "51d2a16438178423c2000001"
@bulletin.is_pending = true
@bulletin.save! @bulletin.save!
end end

View File

@ -0,0 +1 @@
<p>Successfully Imported Announcement Data!</p>

View File

@ -20,6 +20,7 @@
</form> </form>
</div> </div>
<ul class="nav nav-pills filter-nav pull-right"> <ul class="nav nav-pills filter-nav pull-right">
<li class="accordion-group"> <li class="accordion-group">
<div class="accordion-heading"> <div class="accordion-heading">