From 31850c6ca118b7828dbaa3ad1a87dab4287718f5 Mon Sep 17 00:00:00 2001 From: hellekin Date: Thu, 8 Oct 2020 22:10:41 +0200 Subject: Add categories, sections, and import data --- db/seeds.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'db/seeds.rb') diff --git a/db/seeds.rb b/db/seeds.rb index 8a4c670..ea9fc25 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -26,3 +26,25 @@ Taxonomy.find_or_create_by( uuid: '2519915f-d19c-4281-b758-f5ddb889d7fa', agent_id: dewey.id ) + +# Create French categories and sections +if Category.count == 0 + dewey_taxo = Taxonomy.first + cats = JSON.parse(IO.read('doc/import/categories-fr.json')) + cats.each do |cat| + c = Category.create(name: cat['name'], dewey_id: cat['id'], taxonomy_id: dewey_taxo.id, color: cat['color']) + cat['sections'].each do |sec| + Section.create(name: sec['name'], category_id: c.id, dewey_id: sec['id'], color: sec['color']) + end + end + # Now that we have all we need, update resources_sections... + Resource.all.each do |res| + sec_ids = res.feature['properties']['categories'] + next if sec_ids.empty? + sec_ids.each do |id| + s = Section.find_by(dewey_id: id) + res.sections << s if s.present? + res.save + end + end +end -- cgit v1.2.3