diff options
author | hellekin <hellekin@cepheide.org> | 2020-10-08 22:10:41 +0200 |
---|---|---|
committer | hellekin <hellekin@cepheide.org> | 2020-10-08 22:11:03 +0200 |
commit | 31850c6ca118b7828dbaa3ad1a87dab4287718f5 (patch) | |
tree | 7c0055b939a27eb2f38f42ca17ec671aeac4c221 /doc/import/README.md | |
parent | 0ab4ac71cdfe8b7dcf768ca0b68c8ef53040f1a2 (diff) | |
download | incommon-map-31850c6ca118b7828dbaa3ad1a87dab4287718f5.tar.gz |
Add categories, sections, and import data
Diffstat (limited to 'doc/import/README.md')
-rw-r--r-- | doc/import/README.md | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/doc/import/README.md b/doc/import/README.md index b65225e..f5c4096 100644 --- a/doc/import/README.md +++ b/doc/import/README.md @@ -30,3 +30,33 @@ locs['features'].each do |f| Resource.create(agent_id: agent.id, feature: f) end ``` +### Importing categories + +We have a JSON file in French for categories in `doc/import/categories-fr.json`. + +From the console: + +```ruby +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 +``` + +It's taken into account in `rails db:seed` |