aboutsummaryrefslogtreecommitdiff
path: root/doc/import/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/import/README.md')
-rw-r--r--doc/import/README.md30
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`