establecer relaciones de pertenencia

This commit is contained in:
f 2020-07-02 11:25:04 -03:00
parent 9de23a1506
commit 036387dbe0
4 changed files with 42 additions and 11 deletions

View file

@ -0,0 +1,33 @@
# frozen_string_literal: true
# Almacena el UUID de otro Post
class MetadataBelongsTo < MetadataRelatedPosts
# TODO: Convertir algunos tipos de valores en módulos para poder
# implementar varios tipos de campo sin repetir código
#
# @include MetadataString
#
# Una string vacía
def default_value
''
end
# @see MetadataTemplate
def to_param
name
end
def validate
super
errors << I18n.t('metadata.belongs_to.missing_post') unless !value.blank? && posts.find(sanitize(value), uuid: true)
errors.empty?
end
private
def sanitize(uuid)
uuid.gsub(/[^a-f0-9\-]/, '')
end
end

View file

@ -39,7 +39,7 @@ MetadataTemplate = Struct.new(:site, :document, :name, :label, :type,
def validate def validate
self.errors = [] self.errors = []
errors << I18n.t("metadata.#{type}.cant_be_empty") unless can_be_empty? errors << I18n.t("metadata.cant_be_empty") unless can_be_empty?
errors.empty? errors.empty?
end end

View file

@ -31,18 +31,18 @@ en:
destroyed: 'Removed "%{title}"' destroyed: 'Removed "%{title}"'
reorder: 'Reorder' reorder: 'Reorder'
metadata: metadata:
array: cant_be_empty: 'This field cannot be empty'
cant_be_empty: 'This field cannot be empty'
string:
cant_be_empty: 'This field cannot be empty'
image: image:
cant_be_empty: 'This field cannot be empty' not_an_image: 'Not an image'
path_required: 'Missing file for upload'
event: event:
zone_missing: 'Timezone is incorrect' zone_missing: 'Timezone is incorrect'
date_missing: 'Event date is required' date_missing: 'Event date is required'
date_non_parseable: 'Time is not in the correct format' date_non_parseable: 'Time is not in the correct format'
time_non_parseable: 'Date is not in the correct format' time_non_parseable: 'Date is not in the correct format'
end_in_the_past: "Event end can't happen before the start" end_in_the_past: "Event end can't happen before the start"
belongs_to:
missing_post: "Couldn't find the related post"
exceptions: exceptions:
post: post:
site_missing: 'Needs an instance of Site' site_missing: 'Needs an instance of Site'

View file

@ -31,12 +31,8 @@ es:
destroyed: 'Eliminado "%{title}"' destroyed: 'Eliminado "%{title}"'
reorder: 'Reordenados' reorder: 'Reordenados'
metadata: metadata:
array: cant_be_empty: 'El campo no puede estar vacío'
cant_be_empty: 'El campo no puede estar vacío'
string:
cant_be_empty: 'El campo no puede estar vacío'
image: image:
cant_be_empty: 'El campo no puede estar vacío'
not_an_image: 'No es una imagen' not_an_image: 'No es una imagen'
path_required: 'Se necesita un archivo de imagen' path_required: 'Se necesita un archivo de imagen'
event: event:
@ -45,6 +41,8 @@ es:
date_non_parseable: 'La fecha no está en el formato correcto' date_non_parseable: 'La fecha no está en el formato correcto'
time_non_parseable: 'La hora no está en el formato correcto' time_non_parseable: 'La hora no está en el formato correcto'
end_in_the_past: 'El fin del evento no puede ser anterior al comienzo' end_in_the_past: 'El fin del evento no puede ser anterior al comienzo'
belongs_to:
missing_post: 'No se pudo encontrar el artículo relacionado'
exceptions: exceptions:
post: post:
site_missing: 'Necesita una instancia de Site' site_missing: 'Necesita una instancia de Site'