Commit 152a99656ef0039daf9c471b203e925168506a58
Exists in
master
and in
29 other branches
Merge branch 'script-sample-data' of https://gitlab.com/juniorsilva1001/noosfero
Conflicts: script/sample-articles script/sample-enterprises script/sample-products script/sample-profiles
Showing
5 changed files
with
38 additions
and
25 deletions
Show diff stats
lib/noosfero/sample_data_helper.rb
@@ -11,13 +11,13 @@ module Noosfero::SampleDataHelper | @@ -11,13 +11,13 @@ module Noosfero::SampleDataHelper | ||
11 | 11 | ||
12 | def save(obj, &block) | 12 | def save(obj, &block) |
13 | begin | 13 | begin |
14 | - if obj.save | ||
15 | - print '.' | ||
16 | - instance_eval &block if block | ||
17 | - return obj | ||
18 | - else | ||
19 | - print 'F' | ||
20 | - end | 14 | + if obj.save |
15 | + print '.' | ||
16 | + instance_eval &block if block | ||
17 | + return obj | ||
18 | + else | ||
19 | + print 'F' | ||
20 | + end | ||
21 | rescue | 21 | rescue |
22 | print 'E' | 22 | print 'E' |
23 | end | 23 | end |
script/sample-articles
@@ -13,14 +13,16 @@ print "Creating some TinyMce articles: " | @@ -13,14 +13,16 @@ print "Creating some TinyMce articles: " | ||
13 | for subject in SUBJECTS | 13 | for subject in SUBJECTS |
14 | rand(20).times do |i| | 14 | rand(20).times do |i| |
15 | profile = profiles.sample | 15 | profile = profiles.sample |
16 | + name = "%s #{subject}" % profile.name | ||
17 | + next if profile.articles.where(:slug => name.to_slug).first | ||
16 | article = TinyMceArticle.new( | 18 | article = TinyMceArticle.new( |
17 | - :name => "%s #{subject}" % profile.name, | ||
18 | - :body => "%s #{subject}" % profile.name, | ||
19 | - :tag_list => [TAGS.sample, TAGS.sample], | 19 | + :name => name, |
20 | + :body => name, | ||
21 | + :tag_list => [TAGS.rand, TAGS.rand], | ||
20 | :profile => profile | 22 | :profile => profile |
21 | ) | 23 | ) |
22 | save article do | 24 | save article do |
23 | - categories.sample.articles << article | 25 | + article.add_category categories.rand |
24 | end | 26 | end |
25 | end | 27 | end |
26 | end | 28 | end |
@@ -30,10 +32,12 @@ print "Creating some galleries: " | @@ -30,10 +32,12 @@ print "Creating some galleries: " | ||
30 | for subject in SUBJECTS | 32 | for subject in SUBJECTS |
31 | rand(20).times do |i| | 33 | rand(20).times do |i| |
32 | profile = profiles.sample | 34 | profile = profiles.sample |
35 | + name = "Gallery %s #{subject}" % profile.name | ||
36 | + next if profile.articles.where(:slug => name.to_slug).first | ||
33 | save Gallery.new( | 37 | save Gallery.new( |
34 | - :name => "Gallery %s #{subject}" % profile.name, | ||
35 | - :body => "Gallery %s #{subject}" % profile.name, | ||
36 | - :tag_list => [TAGS.sample, TAGS.sample], | 38 | + :name => name, |
39 | + :body => name, | ||
40 | + :tag_list => [TAGS.rand, TAGS.rand], | ||
37 | :profile => profile | 41 | :profile => profile |
38 | ) | 42 | ) |
39 | end | 43 | end |
@@ -43,16 +47,20 @@ done | @@ -43,16 +47,20 @@ done | ||
43 | print "Creating some events: " | 47 | print "Creating some events: " |
44 | for subject in EVENT_SUBJECTS | 48 | for subject in EVENT_SUBJECTS |
45 | for theme in THEMES | 49 | for theme in THEMES |
50 | + profile = profiles.sample | ||
51 | + name = subject % theme | ||
52 | + next if profile.articles.where(:slug => name.to_slug).first | ||
46 | event = Event.new( | 53 | event = Event.new( |
47 | - :name => subject % theme, | ||
48 | - :profile => profiles.sample, | 54 | + :name => name, |
55 | + :profile => profile, | ||
49 | :start_date => Date.today + (-30 + rand(60)).days, | 56 | :start_date => Date.today + (-30 + rand(60)).days, |
50 | :tag_list => [TAGS.sample, TAGS.sample] | 57 | :tag_list => [TAGS.sample, TAGS.sample] |
51 | ) | 58 | ) |
52 | save event do | 59 | save event do |
53 | - categories.sample.events << event | ||
54 | - categories.sample.events << event | ||
55 | - categories.sample.events << event | 60 | + 3.times do |
61 | + category = categories.sample | ||
62 | + event.add_category category | ||
63 | + end | ||
56 | end | 64 | end |
57 | end | 65 | end |
58 | end | 66 | end |
script/sample-enterprises
@@ -32,9 +32,12 @@ groups.each do |group| | @@ -32,9 +32,12 @@ groups.each do |group| | ||
32 | :lat => rand_position(:lat), | 32 | :lat => rand_position(:lat), |
33 | :lng => rand_position(:lng) | 33 | :lng => rand_position(:lng) |
34 | ) | 34 | ) |
35 | + next if Profile[enterprise.identifier] | ||
35 | save enterprise do | 36 | save enterprise do |
36 | - categories.sample.enterprises << enterprise | ||
37 | - categories.sample.enterprises << enterprise | 37 | + 2.times do |
38 | + category = categories.sample | ||
39 | + enterprise.add_category category | ||
40 | + end | ||
38 | end | 41 | end |
39 | end | 42 | end |
40 | end | 43 | end |
@@ -43,7 +46,6 @@ done | @@ -43,7 +46,6 @@ done | ||
43 | 46 | ||
44 | EnterpriseActivation.find(:all, :conditions => ['created_at > ?', start_time]).each do |activation| | 47 | EnterpriseActivation.find(:all, :conditions => ['created_at > ?', start_time]).each do |activation| |
45 | enterprise = activation.enterprise | 48 | enterprise = activation.enterprise |
46 | - puts [activation.code, enterprise.name, enterprise.foundation_year].join(';') | ||
47 | end | 49 | end |
48 | 50 | ||
49 | ze = Person['ze'] | 51 | ze = Person['ze'] |
script/sample-products
@@ -12,9 +12,12 @@ for thing in THINGS | @@ -12,9 +12,12 @@ for thing in THINGS | ||
12 | for color in COLORS | 12 | for color in COLORS |
13 | name = [color, thing].join(' ') | 13 | name = [color, thing].join(' ') |
14 | rand(10).times do |i| | 14 | rand(10).times do |i| |
15 | + profile = enterprises.rand | ||
16 | + next if profile.products.where(:name => name).first | ||
15 | save Product.new( | 17 | save Product.new( |
16 | :name => name, | 18 | :name => name, |
17 | - :profile => enterprises.sample, :price => (i * 13.7), | 19 | + :profile_id => profile.id, :price => (i * 13.7), |
20 | + :product_category_id => categories.sample.id | ||
18 | ) | 21 | ) |
19 | end | 22 | end |
20 | end | 23 | end |
script/sample-profiles
@@ -64,7 +64,7 @@ for name in NAMES | @@ -64,7 +64,7 @@ for name in NAMES | ||
64 | if categories.present? | 64 | if categories.present? |
65 | 2.times do | 65 | 2.times do |
66 | category = categories.sample | 66 | category = categories.sample |
67 | - category.people << user.person unless category.people.include?(user.person) | 67 | + user.person.add_category category unless category.people.include?(user.person) |
68 | end | 68 | end |
69 | end | 69 | end |
70 | end | 70 | end |
@@ -149,7 +149,7 @@ for verb in VERBS | @@ -149,7 +149,7 @@ for verb in VERBS | ||
149 | if categories.present? | 149 | if categories.present? |
150 | 2.times do | 150 | 2.times do |
151 | category = categories.sample | 151 | category = categories.sample |
152 | - category.communities << community unless category.communities.include?(community) | 152 | + community.add_category category unless category.communities.include?(community) |
153 | end | 153 | end |
154 | end | 154 | end |
155 | end | 155 | end |