From 4575f399c7ebb79abcd33d3b0405b6fad4318bad Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Tue, 17 May 2022 17:22:41 +0200 Subject: [PATCH] Fix posts --- app/controllers/admin/education/programs_controller.rb | 1 + app/models/communication/website/post.rb | 7 ++++++- app/models/education/program.rb | 5 +++++ app/services/filters/admin/education/programs.rb | 6 ++++++ .../communication/blocks/templates/posts/_static.html.erb | 1 + 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/education/programs_controller.rb b/app/controllers/admin/education/programs_controller.rb index d934aee75..af4c1e463 100644 --- a/app/controllers/admin/education/programs_controller.rb +++ b/app/controllers/admin/education/programs_controller.rb @@ -7,6 +7,7 @@ class Admin::Education::ProgramsController < Admin::Education::ApplicationContro has_scope :for_search_term has_scope :for_diploma + has_scope :for_school def index @programs = apply_scopes(@programs).ordered_by_name.page(params[:page]) diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 5f9cae573..53e396726 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -84,13 +84,18 @@ class Communication::Website::Post < ApplicationRecord ", term: "%#{sanitize_sql_like(term)}%") } + # Is it used? def path # used in menu_item#static_target "/#{published_at.strftime "%Y/%m/%d"}/#{slug}" end def git_path(website) - "content/posts/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if published && published_at + "content/posts/#{hugo_path}.html" if published && published_at + end + + def hugo_path + "#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}" end def template_static diff --git a/app/models/education/program.rb b/app/models/education/program.rb index ec001f173..a64575637 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -184,6 +184,11 @@ class Education::Program < ApplicationRecord ", term: "%#{sanitize_sql_like(term)}%") } scope :for_diploma, -> (diploma_id) { where(diploma_id: diploma_id) } + scope :for_school, -> (school_id) { + joins(:schools) + .where(education_schools: { id: school_id }) + .distinct + } def to_s "#{name}" diff --git a/app/services/filters/admin/education/programs.rb b/app/services/filters/admin/education/programs.rb index e6eb599cb..fc15d2de1 100644 --- a/app/services/filters/admin/education/programs.rb +++ b/app/services/filters/admin/education/programs.rb @@ -9,6 +9,12 @@ module Filters 'filters.attributes.element', element: Education::Diploma.model_name.human.downcase ) + add :for_school, + user.university.education_schools, + I18n.t( + 'filters.attributes.element', + element: Education::School.model_name.human.downcase + ) end end end diff --git a/app/views/admin/communication/blocks/templates/posts/_static.html.erb b/app/views/admin/communication/blocks/templates/posts/_static.html.erb index 938875fd7..2a06e6526 100644 --- a/app/views/admin/communication/blocks/templates/posts/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/posts/_static.html.erb @@ -6,4 +6,5 @@ - slug: <%= post.slug %> path: <%= post.path %> url: <%= post.url %> + file: <%= post.hugo_path %> <% end %> -- GitLab