first version of mid_site_sync for new i18n var

This commit is contained in:
Matthew K. Fu JuYuan 2012-07-26 14:57:22 +08:00 committed by Christophe Vilayphiou
parent a8cc581279
commit f76b1c02b5
1 changed files with 9 additions and 11 deletions

View File

@ -18,12 +18,10 @@ namespace :mid_site do
sub_role = role.sub_roles.get_sub_role_from_key(key) sub_role = role.sub_roles.get_sub_role_from_key(key)
if sub_role.nil? if sub_role.nil?
ut_data = ut_query.find{|ut_data| ut_data["ut_cod"] == key } ut_data = ut_query.find{|ut_data| ut_data["ut_cod"] == key }
# debugger
i18n_for_new_sub_role = I18nVariable.create!( :document_class => 'SubRole', :key => key, :en => (ut_data["ut_eng_m"] rescue ''), :zh_tw => (ut_data["ut_chi_m"] rescue ''), :parent_id => role.i18n_variable.id )
sub_role = role.sub_roles.create!(:key => key) sub_role = role.sub_roles.create!(:key => key)
sub_role.i18n_variable = i18n_for_new_sub_role sub_role.title_translations ={"en" => (ut_data["ut_eng_m"] rescue ''), "zh_tw" => (ut_data["ut_chi_m"] rescue '')}
sub_role.save! sub_role.save!
p "Created SubRole(key: #{key}): EN: #{sub_role.i18n_variable.en}, CH: #{sub_role.i18n_variable.zh_tw} ParentRole(#{role.i18n_variable.key}): #{role.i18n_variable.en}" p "Created SubRole(key: #{key}): EN: #{sub_role.title_translations['en']}, CH: #{sub_role.title_translations['zh_tw']} ParentRole(#{role.key}): #{role.title_translations['en']}"
end end
sub_role sub_role
end end
@ -65,9 +63,9 @@ namespace :mid_site do
user_model_mapper[:admin] = false user_model_mapper[:admin] = false
local_user.update_attributes(user_model_mapper) local_user.update_attributes(user_model_mapper)
i18n_department_admin = I18nVariable.find_or_create_by( :document_class => 'Role', :key => 'department_admin', :en => 'Department Admin', :zh_tw => '系所使用者' )
local_user.role = Role.find_or_create_by( :key => "department_admin",:build_in => true) local_user.role = Role.find_or_create_by( :key => "department_admin",:build_in => true)
local_user.role.i18n_variable = i18n_department_admin local_user.role.title_translations = {"en" => 'Department Admin', "zh_tw" => '系所使用者' }
unless local_user.ut_cod == local_user.up_ut_cod #if the ut_cod has additions info for up ut unless local_user.ut_cod == local_user.up_ut_cod #if the ut_cod has additions info for up ut
@ -128,15 +126,15 @@ namespace :mid_site do
task :before_instll_admin => :environment do task :before_instll_admin => :environment do
var_1 = I18nVariable.find_or_create_by( :document_class => 'Role', :key => 'administrator', :en => 'Administrator', :zh_tw => '管理員' ) var_1 = {"en" => 'Administrator', "zh_tw" => '管理員' }
var_1_1 = I18nVariable.find_or_create_by( :document_class => 'SubRole', :key => 'computer_center', :en => 'Computer Center', :zh_tw => '計算機中心', :parent_id => var_1.id ) var_1_1 = {"en" => 'Computer Center', "zh_tw" => '計算機中心'}
admin_role = Role.find_or_create_by( :key => 'administrator',:built_in => true) admin_role = Role.find_or_create_by( :key => 'administrator',:built_in => true)
admin_role.i18n_variable =var_1 admin_role.title_translations =var_1
admin_role.save! admin_role.save!
sub_role = admin_role.sub_roles.find_or_create_by(:key => 'computer_center', :built_in => true) sub_role = admin_role.sub_roles.find_or_create_by(:key => 'computer_center', :built_in => true)
sub_role.i18n_variable =var_1_1 sub_role.title_translations =var_1_1
sub_role.save! sub_role.save!
#var_1_1_1 = I18nVariable.create!( :document_class => 'Attribute', :key => 'field', :en => 'Field', :zh_tw => '領域', :parent_id => var_1_1.id ) #var_1_1_1 = I18nVariable.create!( :document_class => 'Attribute', :key => 'field', :en => 'Field', :zh_tw => '領域', :parent_id => var_1_1.id )