Class: Decidim::TermCustomizer::Admin::TranslationsImportForm

Inherits:
Form
  • Object
show all
Defined in:
app/forms/decidim/term_customizer/admin/translations_import_form.rb

Overview

A form object to be used when admin users want to import a collection of proposals from a participatory text.

Constant Summary collapse

ACCEPTED_MIME_TYPES =
Decidim::TermCustomizer::Import::Readers::ACCEPTED_MIME_TYPES
MIME_TYPE_ZIP =
"application/zip"

Instance Method Summary collapse

Instance Method Details

#accepted_mime_typeObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/forms/decidim/term_customizer/admin/translations_import_form.rb', line 31

def accepted_mime_type
  accepted_mime_types = ACCEPTED_MIME_TYPES.values + [MIME_TYPE_ZIP]
  return if accepted_mime_types.include?(mime_type)

  errors.add(
    :file,
    I18n.t(
      "activemodel.errors.models.translations_import.attributes.file.invalid_mime_type",
      valid_mime_types: ACCEPTED_MIME_TYPES.keys.map do |m|
        I18n.t("decidim.term_customizer.admin.translations.new_import.accepted_mime_types.#{m}")
      end.join(", ")
    )
  )
end

#file_pathObject



19
20
21
# File 'app/forms/decidim/term_customizer/admin/translations_import_form.rb', line 19

def file_path
  file&.path
end

#mime_typeObject



23
24
25
# File 'app/forms/decidim/term_customizer/admin/translations_import_form.rb', line 23

def mime_type
  file&.content_type
end

#zip_file?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/forms/decidim/term_customizer/admin/translations_import_form.rb', line 27

def zip_file?
  mime_type == MIME_TYPE_ZIP
end