Handle execptions for import and fix plugin templates

This commit is contained in:
manson 2014-07-15 19:10:51 +08:00
parent 2e447476b3
commit 6cccdbc9ab
9 changed files with 90 additions and 38 deletions

View File

@ -725,10 +725,14 @@ class Admin::ImportController < OrbitAdminController
if old_book.nil?
new_book = Book.new(:book_title_translations => {"en" => book["book_title"]["en"], "zh_tw" => book["book_title"]["zh-tw"]}, :extracted_chapters_translations => {"en" => book["extracted_chapters"]["en"], "zh_tw" => book["extracted_chapters"]["zh-tw"]}, :publisher_translations => {"en" => book["publishers"]["en"], "zh_tw" => book["publishers"]["zh-tw"]}, :editor_translations => {"en" => book["editor"]["en"], "zh_tw" => book["editor"]["zh-tw"]}, :year => book["year"], :language => book["language"].sub("-","_"), :pages => book["number_of_pages"], :isbn => book["issn"], :publication_date => book["publication_date"], :url => book["reference_url"], :note => book["note"], :rss2_id => book["rss2_id"])
new_book.member_profile = member
if !book["file"].blank?
book_file = new_book.book_files.new
book_file.remote_member_book_file_url = book["file"]["file"]
book_file.title_translations = {"en" => book["file"]["name"], "zh_tw" => book["file"]["name"]}
book_file.save
end
author_types.each do |author|
bat = BookAuthorType.where(:title => author).first
if bat.nil?
@ -766,16 +770,41 @@ class Admin::ImportController < OrbitAdminController
projects.each do |project|
old_project = Project.where(:rss2_id => project["rss2_id"]).first
if old_project.nil?
new_project = Project.new(:project_title_translations => {"en" => project["project_title"]["en"], "zh_tw" => project["project_title"]["zh-tw"]},:job_title_translations => {"en" => project["job_title"]["en"],"zh_tw" => project["job_title"]["zh-tw"]}, :participator_translations => {"en" => project["participant"]["en"],"zh_tw" => project["participant"]["zh-tw"]}, :unit_translations => {"en" => project["unit"]["en"],"zh_tw" => project["unit"]["zh-tw"]},:year => project["year"], :language => project["language"].sub("-","_"), :period_start_date => Date.strptime(project["start_date"], '%Y-%m'), :period_end_date => Date.strptime(project["end_date"], '%Y-%m'), :url => project["reference_url"], :note_translations => {"en" => project["note"]["en"],"zh_tw" => project["note"]["zh-tw"]}, :rss2_id => project["rss2_id"])
new_project = Project.new(
:project_title_translations => {
"en" => project["project_title"]["en"],
"zh_tw" => project["project_title"]["zh-tw"]},
:job_title_translations => {
"en" => project["job_title"]["en"],
"zh_tw" => project["job_title"]["zh-tw"]},
:participator_translations => {
"en" => project["participant"]["en"],
"zh_tw" => project["participant"]["zh-tw"]},
:unit_translations => {
"en" => project["unit"]["en"],
"zh_tw" => project["unit"]["zh-tw"]},
:year => project["year"],
:language => project["language"].sub("-","_"),
:period_start_date => Date.strptime(project["start_date"].gsub('00','01'), '%Y-%m'),
:period_end_date => Date.strptime(project["end_date"].gsub('00','01'), '%Y-%m'),
:url => project["reference_url"],
:note_translations => {
"en" => project["note"]["en"],
"zh_tw" => project["note"]["zh-tw"]},
:rss2_id => project["rss2_id"])
pc = ProjectType.where(:title => project["project_categories"]["zh-tw"]).first
if pc.nil?
pc = ProjectType.new(:title_translations => {"en" => project["project_categories"]["en"], "zh_tw" => project["project_categories"]["zh-tw"]})
pc.save
end
if !project["file"].blank?
project_file = new_project.project_files.new
project_file.remote_file_url = project["file"]["file"]
project_file.title_translations = {"en" => project["file"]["name"], "zh_tw" => project["file"]["name"]}
project_file.save
end
new_project.project_type = pc
new_project.member_profile = member
new_project.save
@ -833,10 +862,14 @@ class Admin::ImportController < OrbitAdminController
old_research = Research.where(:rss2_id => research["rss2_id"]).first
if old_research.nil?
new_research = Research.new(:research_title_translations => {"en" => research["title"]["en"],"zh_tw" => research["title"]["zh-tw"]},:language => research["language"], :publish_date => research["date_of_publication"], :rss2_id => research["rss2_id"])
if research["file"]
research_file = new_research.research_files.new
research_file.remote_file_url = research["file"]["file"]
research_file.title_translations = {"en" => research["file"]["name"], "zh_tw" => research["file"]["name"]}
research_file.save
end
new_research.member_profile = member
new_research.save
end
@ -883,7 +916,21 @@ class Admin::ImportController < OrbitAdminController
experiences.each do |experience|
old_experience = Experience.where(:rss2_id => experience["rss2_id"]).first
if old_experience.nil?
new_experience = Experience.new(:organizationt_title_translations => {"en" => experience["organization_title"]["en"], "zh_tw" => experience["organization_title"]["zh-tw"]}, :department_translations => {"en" => experience["department"]["en"], "zh_tw" => experience["department"]["zh-tw"]}, :job_title_translations => {"en" => experience["job_title"]["en"], "zh_tw" => experience["job_title"]["zh-tw"]}, :language => experience["language"], :start_date => Date.strptime(experience["start_date"], '%Y-%m'), :end_date => Date.strptime(experience["end_date"], '%Y-%m'), :rss2_id => experience["rss2_id"])
new_experience = Experience.new(
:organizationt_title_translations => {
"en" => experience["organization_title"]["en"],
"zh_tw" => experience["organization_title"]["zh-tw"]},
:department_translations => {
"en" => experience["department"]["en"],
"zh_tw" => experience["department"]["zh-tw"]},
:job_title_translations => {
"en" => experience["job_title"]["en"],
"zh_tw" => experience["job_title"]["zh-tw"]},
:language => experience["language"],
:start_date => Date.strptime(experience["start_date"].gsub('00','01'), '%Y-%m'),
:end_date => Date.strptime(experience["end_date"].gsub('00','01'), '%Y-%m'),
:rss2_id => experience["rss2_id"])
new_experience.member_profile = member
new_experience.save
end
@ -982,10 +1029,13 @@ class Admin::ImportController < OrbitAdminController
end
journal.journal_paper_files.destroy_all
if !rss2_journal["file"].blank?
paper_file = journal.journal_paper_files.new
paper_file.remote_journal_file_url = rss2_journal["file"]["file"]
paper_file.title_translations = {"en" => rss2_journal["file"]["name"], "zh_tw" => rss2_journal["file"]["name"]}
paper_file.save rescue nil
end
journal.member_profile = member
journal.save
@ -1076,10 +1126,12 @@ class Admin::ImportController < OrbitAdminController
end
conference.writing_conference_files.destroy_all
if !rss2_conference["file"].blank?
paper_file = conference.writing_conference_files.new
paper_file.remote_file_url = rss2_conference["file"]["file"]
paper_file.title_translations = {"en" => rss2_conference["file"]["name"], "zh_tw" => rss2_conference["file"]["name"]}
paper_file.save rescue nil
end
conference.member_profile = member
conference.save

View File

@ -7,8 +7,8 @@
<th class="col-md-2">{{th_author}}</th>
</tr>
</thead>
<tbody>
<tr data-level="0" data-list="writing_conferences">
<tbody data-level="0" data-list="writing_conferences">
<tr>
<td>{{year}}</td>
<td><a href="{{link_to_show}}">{{paper_title}}</a></td>
<td>{{author}}</td>

View File

@ -9,8 +9,8 @@
<th class="col-md-2"></th>
</tr>
</thead>
<tbody>
<tr data-level="0" data-list="diplomas">
<tbody data-level="0" data-list="diplomas">
<tr>
<td>{{member}}</td>
<td>{{school_name}}</td>
<td>{{degree}}</td>

View File

@ -9,8 +9,8 @@
<th class="col-md-2"></th>
</tr>
</thead>
<tbody>
<tr data-level="0" data-list="experiences">
<tbody data-level="0" data-list="experiences">
<tr>
<td>{{member}}</td>
<td>{{organizationt_title}}</td>
<td>{{department}}</td>

View File

@ -9,8 +9,8 @@
<th class="col-md-2"></th>
</tr>
</thead>
<tbody>
<tr data-level="0" data-list="honors">
<tbody data-level="0" data-list="honors">
<tr>
<td>{{year}}</td>
<td>{{award_name}}</td>
<td>{{awarding_unit}}</td>

View File

@ -9,8 +9,8 @@
<th class="col-md-2"></th>
</tr>
</thead>
<tbody>
<tr data-level="0" data-list="labs">
<tbody data-level="0" data-list="labs">
<tr>
<td>{{year}}</td>
<td>{{lab_title}}</td>
<td>{{location}}</td>

View File

@ -9,8 +9,8 @@
<th class="col-md-2">{{th_authors}}</th>
</tr>
</thead>
<tbody>
<tr data-level="0" data-list="patents">
<tbody data-level="0" data-list="patents">
<tr>
<td>{{publication_date}}</td>
<td><a href="{{link_to_show}}">{{patent_title}}</a></td>
<td>{{patent_no}}</td>

View File

@ -9,8 +9,8 @@
<th class="col-md-3">{{th_authors}}</th>
</tr>
</thead>
<tbody>
<tr data-level="0" data-list="projects">
<tbody data-level="0" data-list="projects">
<tr>
<td>{{duration}}</td>
<td><a href="{{link_to_show}}">{{project_title}}</a></td>
<td>{{job_title}}</td>

View File

@ -9,8 +9,8 @@
<th class="col-md-2"></th>
</tr>
</thead>
<tbody>
<tr data-level="0" data-list="researchs">
<tbody data-level="0" data-list="researchs">
<tr>
<td>{{year}}</td>
<td>{{publication_date}}</td>
<td>{{research_title}}</td>