Skip to content

Commit

Permalink
Update gobierto data seed recipe
Browse files Browse the repository at this point in the history
* Change default datasets categories
* Rename default vocabularies to include dataset name
  • Loading branch information
entantoencuanto committed Feb 12, 2020
1 parent 76adb76 commit 120bbf5
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions db/seeds/modules/gobierto_data/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

module GobiertoSeeds
class Recipe
DEFAULT_CATEGORY_NAMES = [
"Sector público",
"Transporte",
"Medio ambiente",
"Ciencia y tecnología",
"Economía",
"Medio Rural",
"Demografía",
"Hacienda",
"Educación",
"Cultura y ocio",
"Turismo",
"Empleo",
"Sociedad y bienestar",
"Urbanismo e infraestructuras",
"Comercio",
"Legislación y justicia",
"Salud",
"Seguridad",
"Industria",
"Energía",
"Deporte",
"Vivienda"
].freeze

def self.run(site)
description = site.custom_fields.localized_string.where(class_name: "GobiertoData::Dataset").find_or_initialize_by(uid: "description")
if description.new_record?
Expand All @@ -15,7 +40,7 @@ def self.run(site)
if frequency.new_record?
vocabulary = site.vocabularies.find_or_initialize_by(slug: "datasets-frequency")
if vocabulary.new_record?
vocabulary.name_translations = { ca: "Freqüència", en: "Frequency", es: "Frecuencia" }
vocabulary.name_translations = { ca: "Freqüència de conjunt de dades", en: "Dataset frequency", es: "Frecuencia de conjunto de datos" }
vocabulary.save
vocabulary.terms.create(name_translations: { ca: "Anual", en: "Annual", es: "Anual" })
vocabulary.terms.create(name_translations: { ca: "Trimestral", en: "Quarterly", es: "Trimestral" })
Expand All @@ -36,14 +61,18 @@ def self.run(site)

vocabulary = site.vocabularies.find_or_initialize_by(slug: "datasets-category")
if vocabulary.new_record?
vocabulary.name_translations = { ca: "Categoria", en: "Category", es: "Categoría" }
vocabulary.name_translations = { ca: "Categoria de conjunt de dades", en: "Dataset Category", es: "Categoría de conjunto de datos" }
vocabulary.save
vocabulary.terms.create(name_translations: { ca: "General", en: "General", es: "General" })
DEFAULT_CATEGORY_NAMES.each do |category_name|
vocabulary.terms.create(
name_translations: Hash[site.configuration.available_locales.product([category_name])]
)
end
end
category.name_translations = { ca: "Categoria", en: "Category", es: "Categoría" }
category.position = 3
category.options = {
configuration: { vocabulary_type: "single_select" },
configuration: { vocabulary_type: "multiple_select" },
vocabulary_id: vocabulary.id.to_s
}
category.save
Expand Down

0 comments on commit 120bbf5

Please sign in to comment.