Commit 571380271dedf25106f78aa4d0198704cbc9e2f9

Authored by Parley
1 parent f4b16954

Implement task to create templates of people

Signed-off-by: Parley Martins <parley@outlook.com>
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Showing 1 changed file with 57 additions and 10 deletions   Show diff stats
lib/tasks/templates.rake
1 namespace :templates do 1 namespace :templates do
2 namespace :create do 2 namespace :create do
3 - 3 +
4 desc "Create new templates of software, intitution, person and community" 4 desc "Create new templates of software, intitution, person and community"
5 task :all => :environment do 5 task :all => :environment do
6 Rake::Task["templates:create:institution"].invoke 6 Rake::Task["templates:create:institution"].invoke
@@ -18,12 +18,53 @@ namespace :templates do @@ -18,12 +18,53 @@ namespace :templates do
18 end 18 end
19 end 19 end
20 20
21 -  
22 desc "Create new templates of people" 21 desc "Create new templates of people"
23 task :people => :environment do 22 task :people => :environment do
24 Environment.all.each do |env| 23 Environment.all.each do |env|
25 if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin") 24 if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin")
  25 + person = Person.where(:identifier => "noosfero_person_template").first
  26 +
  27 + if person.nil?
  28 + password = SecureRandom.hex(6)
  29 + user = User.create!(:name => "People", :login => "people", :email => "person@template.noo", :password => password , :password_confirmation => password, :environment => env)
  30 + person = user.person
  31 + end
  32 +
  33 + person.layout_template = "leftbar"
  34 + person.is_template = true
  35 +
  36 + box1 = person.boxes.where(:position => 1).first
  37 + box1.blocks.destroy_all
  38 + person.save!
26 puts "Person successfully created!" 39 puts "Person successfully created!"
  40 +
  41 + institution_block = InstitutionsBlock.new
  42 + institution_block.position = 4
  43 + institution_block.save!
  44 + box1.blocks << institution_block
  45 + box1.save!
  46 + puts "InstitutionBlock successfully added to person!"
  47 +
  48 + software_block = SoftwaresBlock.new
  49 + software_block.position = 2
  50 + software_block.save!
  51 + box1.blocks << software_block
  52 + box1.save!
  53 + puts "SoftwaresBlock successfully added to person!"
  54 +
  55 + community_block = CommunitiesBlock.new
  56 + community_block.position = 3
  57 + community_block.save!
  58 + box1.blocks << community_block
  59 + box1.save!
  60 + puts "CommunitiesBlock successfully added to person!"
  61 +
  62 + main_block = MainBlock.new
  63 + main_block.position = 1
  64 + main_block.save!
  65 + box1.blocks << main_block
  66 + box1.save!
  67 + puts "MainBlock successfully added to person!"
27 end 68 end
28 end 69 end
29 end 70 end
@@ -42,20 +83,20 @@ namespace :templates do @@ -42,20 +83,20 @@ namespace :templates do
42 task :institution => :environment do 83 task :institution => :environment do
43 Environment.all.each do |env| 84 Environment.all.each do |env|
44 if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin") 85 if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin")
45 - community = Community.create!(:name => "institution", :is_template => true, :moderated_articles => true) 86 + community = Community.create!(:name => "institution", :is_template => true, :moderated_articles => true, :environment => env)
46 community.layout_template = "leftbar" 87 community.layout_template = "leftbar"
47 - 88 +
48 box2 = community.boxes.where(:position => 2).first 89 box2 = community.boxes.where(:position => 2).first
49 box1 = community.boxes.where(:position => 1).first 90 box1 = community.boxes.where(:position => 1).first
50 box3 = community.boxes.where(:position => 3).first 91 box3 = community.boxes.where(:position => 3).first
51 - 92 +
52 box2.blocks.destroy_all 93 box2.blocks.destroy_all
53 box1.blocks.destroy_all 94 box1.blocks.destroy_all
54 box3.blocks.destroy_all 95 box3.blocks.destroy_all
55 96
56 community.save! 97 community.save!
57 puts "Institution succesfully created!" 98 puts "Institution succesfully created!"
58 - 99 +
59 members_block = MembersBlock.new 100 members_block = MembersBlock.new
60 members_block.limit = 16 101 members_block.limit = 16
61 members_block.prioritize_profiles_with_image = true 102 members_block.prioritize_profiles_with_image = true
@@ -67,15 +108,14 @@ namespace :templates do @@ -67,15 +108,14 @@ namespace :templates do
67 members_block.save! 108 members_block.save!
68 box1.blocks << members_block 109 box1.blocks << members_block
69 box1.save! 110 box1.save!
70 - puts "MembersBlock successfully added!"  
71 -  
72 - 111 + puts "MembersBlock successfully added to institution!"
  112 +
73 main_block = MainBlock.new 113 main_block = MainBlock.new
74 main_block.position = 1 114 main_block.position = 1
75 main_block.save! 115 main_block.save!
76 box1.blocks << main_block 116 box1.blocks << main_block
77 box1.save! 117 box1.save!
78 - puts "MainBlock successfully added!" 118 + puts "MainBlock successfully added to institution!"
79 end 119 end
80 end 120 end
81 end 121 end
@@ -88,6 +128,13 @@ namespace :templates do @@ -88,6 +128,13 @@ namespace :templates do
88 if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin") 128 if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("MpogSoftwarePlugin")
89 Community["institution"].destroy 129 Community["institution"].destroy
90 puts "Institution template destoyed with success!" 130 puts "Institution template destoyed with success!"
  131 +
  132 + user = User["people"]
  133 + if !user.nil?
  134 + user.person.destroy
  135 + user.destroy
  136 + puts "Person template destroyed with success!"
  137 + end
91 end 138 end
92 end 139 end
93 end 140 end