Created
February 19, 2016 13:32
-
-
Save stefanoverna/a765e310d96beea5d502 to your computer and use it in GitHub Desktop.
Batch create AIFI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| paragraph = titolo, body, immagine, attachment | |
| attachment = titolo, body, file | |
| gruppo = titolo, descrizione, attachments | |
| articoli = titolo, body, published_at, immagine, attachment | |
| DOMAIN = "magazine-admin.bookrepublic.it" | |
| ActiveRecord::Base.transaction do | |
| existing_space = Space.by_domain(DOMAIN) | |
| existing_space && existing_space.destroy! | |
| space = Space.create!( | |
| domain: DOMAIN, | |
| name: "BookRepublic Magazine", | |
| readonly_token: "27d9cebb840044984741ae4ed64db7e9f7ec536349b066fd30", | |
| locales: ["it"] | |
| ) | |
| def create_content_type(has_paragraphs, has_attachments, has_groups, has_articles) | |
| xxx = ContentType.create!( | |
| space: space, | |
| name: "Interventi convegni AIFI", | |
| api_key: "interventi_convegni_aifi" | |
| ) | |
| Field.create!( | |
| content_type: xxx, | |
| label: "Titolo", | |
| api_key: "title", | |
| field_type: "title", | |
| localized: true, | |
| validators: { required: {} }, | |
| position: 0 | |
| ) | |
| Field.create!( | |
| content_type: xxx, | |
| label: "Abstract", | |
| api_key: "abstract", | |
| field_type: "text", | |
| localized: true, | |
| validators: { required: {} }, | |
| position: 0 | |
| ) | |
| Field.create!( | |
| content_type: xxx, | |
| label: "Body", | |
| api_key: "body", | |
| field_type: "html", | |
| localized: true, | |
| validators: { required: {} }, | |
| position: 0 | |
| ) | |
| Field.create!( | |
| content_type: xxx, | |
| label: "Impostazioni SEO", | |
| api_key: "seo", | |
| field_type: "seo", | |
| localized: true, | |
| validators: {}, | |
| position: 1 | |
| ) | |
| if has_paragraphs | |
| Field.create!( | |
| content_type: xxx, | |
| label: "Allegati", | |
| api_key: "attachments", | |
| field_type: "embeds_many", | |
| localized: false, | |
| validators: { | |
| records_content_type: { content_type: ATTACHMENT.api_key } | |
| }, | |
| position: 2 | |
| ) | |
| end | |
| if has_groups | |
| Field.create!( | |
| content_type: xxx, | |
| label: "Gruppi", | |
| api_key: "attachments", | |
| field_type: "embeds_many", | |
| localized: false, | |
| validators: { | |
| records_content_type: { content_type: .api_key } | |
| }, | |
| position: 2 | |
| ) | |
| end | |
| if has_attachments | |
| Field.create!( | |
| content_type: xxx, | |
| label: "Allegati", | |
| api_key: "attachments", | |
| field_type: "embeds_many", | |
| localized: false, | |
| validators: { | |
| records_content_type: { content_type: attachment.api_key } | |
| }, | |
| position: 2 | |
| ) | |
| end | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment