Import teacher data

This commit is contained in:
Manson Wang 2013-12-29 15:10:49 +08:00 committed by Manson Wang
parent 198c302891
commit ed8b42e948
2 changed files with 59 additions and 1 deletions

View File

@ -0,0 +1,58 @@
#encoding: utf-8
namespace :teacher do
task :import, [:department,:category] => :environment do |t, args|
department = "#{args.department}"
teacher_role = Role.where(:key=>"teacher").first
role_fulltime = RoleStatus.where(:key=>"1.fulltime").first
role_adjunct = RoleStatus.where(:key=>"2.adjunct").first
role_category = RoleCategory.where(:key=>"#{args.category}").first
@teacher = []
CSV.foreach("#{Rails.root}/#{department}.csv") do |row|
@teacher.push(row)
end
@teacher.each do |teacher|
sex = "unknown"
if teacher[2]==""
sex = "male"
elsif teacher[2]==""
sex = "female"
end
role_status = ""
if teacher[3].include? "兼任"
role_status = role_adjunct
else
role_status = role_fulltime
end
if teacher[1].blank?
teacher[1] = " "
end
user_data = {
:user_id => teacher[5].split("@")[0],
:password => "password",
:first_name_translations =>{"zh_tw"=>teacher[0].split(teacher[0][0])[1],"en"=>teacher[1].split(" ")[1]},
:last_name_translations => {"zh_tw"=>teacher[0][0],"en"=>teacher[1].split(" ")[0]},
:roles => [teacher_role],
:role_statuses => [role_status],
:role_categorys => [role_category],
:office_tel => teacher[4],
:email => teacher[5],
:confirmation_token => nil,
:confirmed_at => Time.now,
:approved => true,
:sex => sex
}
if User.where(:email=>teacher[5]).count == 0
user = User.new(user_data)
user.save
else
user = User.where(:email=>teacher[5]).first
user.update_attributes(user_data)
end
end
end
end

View File

@ -80,7 +80,7 @@
<div class="o-members-pic"><%= show_avatar(member) %></div>
<ul class="o-members-info">
<li><b class="o-members-label"><%= t("users.name")%></b><%= link_to member.name, panel_member_front_end_member_list_path(member.id), {:class => "o-members-link"} %></li>
<% @job_title = @member_lists.get_member_list_attribute_value(member.id,@job_title_field.id).get_value_by_locale(I18n.locale)
<% @job_title = @member_lists.get_member_list_attribute_value(member.id,@job_title_field.id).get_value_by_locale(I18n.locale) rescue ""
if @job_title != 'NoData' and !@job_title.blank?
%>
<li><b class="o-members-label"><%= @job_title_field.title %></b><%= @job_title %></li>