From 21b4f0bcce70ab380f8f4e5f8c38ff137fbb3059 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Tue, 26 Oct 2010 11:41:18 -0300 Subject: [PATCH] Separating the sample data scripts a little more --- app/models/environment.rb | 3 ++- script/sample-data | 113 +---------------------------------------------------------------------------------------------------------------- script/sample-enterprises | 6 ++++++ script/sample-profiles | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 113 deletions(-) create mode 100755 script/sample-profiles diff --git a/app/models/environment.rb b/app/models/environment.rb index 91b31f0..1d870ff 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -135,7 +135,8 @@ class Environment < ActiveRecord::Base env.boxes[1].blocks << RecentDocumentsBlock.new # "right" area - env.boxes[2].blocks << ProfileListBlock.new + env.boxes[2].blocks << CommunitiesBlock.new(:limit => 4) + env.boxes[2].blocks << PeopleBlock.new(:limit => 4) end # One Environment can be reached by many domains diff --git a/script/sample-data b/script/sample-data index cbd06c9..c3ce589 100755 --- a/script/sample-data +++ b/script/sample-data @@ -24,118 +24,7 @@ EOF environment = Environment.create!(:name => 'Noosfero', :is_default => true, :description => DEFAULT_ENVIRONMENT_TEXT) unless (Environment.default) end -places = [ - { :country=>'BR', :city=>'Salvador', - :lat=>-12.94032, :lng=>-38.58398 }, - { :country=>'BR', :city=>'São Paulo', - :lat=>-23.54894, :lng=>-46.63881 }, - { :country=>'BR', :city=>'Rio de Janeiro', - :lat=>-22.90353, :lng=>-43.20958 }, - { :country=>'AR', :city=>'Buenos Aires', - :lat=>-34.61088, :lng=>-58.39782 }, - { :country=>'AR', :city=>'Mar del Plata', - :lat=>-37.98317, :lng=>-57.59513 }, - { :country=>'MX', :city=>'Acapulco', - :lat=>16.86369, :lng=>-99.88151 }, - { :country=>'US', :city=>'Los Angeles', - :lat=>34.02307, :lng=>-118.24310 }, - { :country=>'IT', :city=>'Roma', - :lat=>41.89512, :lng=>12.48184 }, - { :country=>'IN', :city=>'Mumbai', - :lat=>19.01798, :lng=>72.85583 }, - { :country=>'CN', :city=>'Shanghai', - :lat=>31.23041, :lng=>121.47308 }, - { :country=>'JP', :city=>'Tokyo', - :lat=>35.68964, :lng=>139.69116 }, - { :country=>'FR', :city=>'Paris', - :lat=>48.85658, :lng=>2.351074 }, - { :country=>'BW', :city=>'Sowa', - :lat=>-20.56891, :lng=>26.22367 } -] - -people = [] - -NAMES = %w[ José João Antonio Paulo Maria Joana Paula Angela ] -SURNAMES = %w[ Silva Santos Abreu Oliveira Machado Bonfim ] -print "Creating users: " -for name in NAMES - for surname in SURNAMES - full_name = [name, surname].join(' ') - user = User.create!({ - :login => full_name.to_slug, - :email => full_name.to_slug + '@localhost.localdomain', - :password => 'test', - :password_confirmation => 'test', - :environment => environment, - }) - user.person.name = full_name - place = places[rand(places.length)] - user.person.data[:country] = place[:country] - user.person.city = place[:city] - user.person.lat = place[:lat] + (rand/100)-0.005 - user.person.lng = place[:lng] + (rand/100)-0.005 - user.person.save! - people << user.person - - print '.' - end -end -puts ' done!' - -print "Creating some friendships: " -rand(people.size * 3).times do - from = people.rand - to = people.rand - if from != to && !from.friends.include?(to) - AddFriend.create!(:requestor => to, :target => from).finish - end - print '.' -end -puts ' done!' - - -communities = [] -VERBS = ['Save', 'I like', 'Use'] -STUFF = ['Free Software', 'Organic food', 'the wales', 'the environment'] -print "Creating communities: " -for verb in VERBS - for stuff in STUFF - name = [verb, stuff].join(' ') - community = Community.create!(:name => name, :environment => environment) - communities << community - rand(10).times do - community.add_member(people.rand) - end - print '.' - end -end -puts ' done!' - -EVENTS = ['International Conference on %s', '%s day', '%s World Congress', '%s World Forum', '%s Summit', '%s Week'] -THEMES = ['Sustainability', 'Free Software', 'Climate Change', 'Environment', 'Agile Development', 'Solidarity Economy'] -print "Creating some events: " -for event in EVENTS - for theme in THEMES - Event.create!(:name => event % theme, :profile => communities.rand, :start_date => Date.today + (-30 + rand(60)).days) - print '.' - end -end -puts ' done!' - -ze = User.create!({ - :login => "ze", - :email => 'root@localhost.localdomain', - :password => 'test', - :password_confirmation => 'test', - :environment => environment, -}).person -environment.add_admin(ze) - +system('./script/sample-profiles') system('./script/sample-categories') system('./script/sample-enterprises') system('./script/sample-products') - -# give admin rights for 'ze' in some enterprises -Enterprise.all.rand.add_admin(ze) -Enterprise.all.rand.add_admin(ze) -Enterprise.all.rand.add_admin(ze) diff --git a/script/sample-enterprises b/script/sample-enterprises index d8d7e4b..0d384c8 100755 --- a/script/sample-enterprises +++ b/script/sample-enterprises @@ -42,3 +42,9 @@ EnterpriseActivation.find(:all, :conditions => ['created_at > ?', start_time]).e enterprise = activation.enterprise puts [activation.code, enterprise.name, enterprise.foundation_year].join(';') end + +ze = Person['ze'] +# give admin rights for 'ze' in some enterprises +Enterprise.all.rand.add_admin(ze) +Enterprise.all.rand.add_admin(ze) +Enterprise.all.rand.add_admin(ze) diff --git a/script/sample-profiles b/script/sample-profiles new file mode 100755 index 0000000..5f652e8 --- /dev/null +++ b/script/sample-profiles @@ -0,0 +1,111 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/environment' + +environment = Environment.default + +places = [ + { :country=>'BR', :city=>'Salvador', + :lat=>-12.94032, :lng=>-38.58398 }, + { :country=>'BR', :city=>'São Paulo', + :lat=>-23.54894, :lng=>-46.63881 }, + { :country=>'BR', :city=>'Rio de Janeiro', + :lat=>-22.90353, :lng=>-43.20958 }, + { :country=>'AR', :city=>'Buenos Aires', + :lat=>-34.61088, :lng=>-58.39782 }, + { :country=>'AR', :city=>'Mar del Plata', + :lat=>-37.98317, :lng=>-57.59513 }, + { :country=>'MX', :city=>'Acapulco', + :lat=>16.86369, :lng=>-99.88151 }, + { :country=>'US', :city=>'Los Angeles', + :lat=>34.02307, :lng=>-118.24310 }, + { :country=>'IT', :city=>'Roma', + :lat=>41.89512, :lng=>12.48184 }, + { :country=>'IN', :city=>'Mumbai', + :lat=>19.01798, :lng=>72.85583 }, + { :country=>'CN', :city=>'Shanghai', + :lat=>31.23041, :lng=>121.47308 }, + { :country=>'JP', :city=>'Tokyo', + :lat=>35.68964, :lng=>139.69116 }, + { :country=>'FR', :city=>'Paris', + :lat=>48.85658, :lng=>2.351074 }, + { :country=>'BW', :city=>'Sowa', + :lat=>-20.56891, :lng=>26.22367 } +] + +people = [] +NAMES = %w[ José João Antonio Paulo Maria Joana Paula Angela ] +SURNAMES = %w[ Silva Santos Abreu Oliveira Machado Bonfim ] +print "Creating users: " +for name in NAMES + for surname in SURNAMES + full_name = [name, surname].join(' ') + user = User.create!({ + :login => full_name.to_slug, + :email => full_name.to_slug + '@localhost.localdomain', + :password => 'test', + :password_confirmation => 'test', + :environment => environment, + }) + user.person.name = full_name + place = places[rand(places.length)] + user.person.data[:country] = place[:country] + user.person.city = place[:city] + user.person.lat = place[:lat] + (rand/100)-0.005 + user.person.lng = place[:lng] + (rand/100)-0.005 + user.person.save! + people << user.person + + print '.' + end +end +puts ' done!' + +print "Creating some friendships: " +rand(people.size * 3).times do + from = people.rand + to = people.rand + if from != to && !from.friends.include?(to) + AddFriend.create!(:requestor => to, :target => from).finish + end + print '.' +end +puts ' done!' + + +communities = [] +VERBS = ['Save', 'I like', 'Use'] +STUFF = ['Free Software', 'Organic food', 'the wales', 'the environment'] +print "Creating communities: " +for verb in VERBS + for stuff in STUFF + name = [verb, stuff].join(' ') + community = Community.create!(:name => name, :environment => environment) + communities << community + rand(10).times do + community.add_member(people.rand) + end + print '.' + end +end +puts ' done!' + +EVENTS = ['International Conference on %s', '%s day', '%s World Congress', '%s World Forum', '%s Summit', '%s Week'] +THEMES = ['Sustainability', 'Free Software', 'Climate Change', 'Environment', 'Agile Development', 'Solidarity Economy'] +print "Creating some events: " +for event in EVENTS + for theme in THEMES + Event.create!(:name => event % theme, :profile => communities.rand, :start_date => Date.today + (-30 + rand(60)).days) + print '.' + end +end +puts ' done!' + +ze = User.create!({ + :login => "ze", + :email => 'root@localhost.localdomain', + :password => 'test', + :password_confirmation => 'test', + :environment => environment, +}).person +environment.add_admin(ze) + -- libgit2 0.21.2