<commit_before>class Kuhsaft::LocalizedPage < ActiveRecord::Base
  belongs_to :page
  has_many :page_parts, :class_name => 'Kuhsaft::PagePart::Content', :autosave => true

  scope :current_locale, lambda{ where('locale = ?', Kuhsaft::Page.current_translation_locale) }
  
  scope :published, lambda{ 
    where('published = ? OR published_at < ? AND published = ?', 
      Kuhsaft::PublishState::PUBLISHED, 
      DateTime.now, 
      Kuhsaft::PublishState::PUBLISHED_AT
    )
  }
  
  scope :search, lambda{ |term| current_locale.published.where('fulltext LIKE ?', "%#{term}%") }
  scope :navigation, lambda{ |slug| 
    current_locale.published.where('slug = ?', slug).where('page_type = ?', Kuhsaft::PageType::NAVIGATION)
  }

  before_validation :create_slug, :create_url, :collect_fulltext
  delegate :childs, :to => :page

  validates :title, :presence => true
  validates :locale, :presence => true
  validates :slug, :presence => true, :uniqueness => true, :unless => :navigation?
  validates :url, :uniqueness => true, :unless => :navigation?

  accepts_nested_attributes_for :page_parts, :allow_destroy => true

  def published?
    return true if published == Kuhsaft::PublishState::PUBLISHED
    return false if published == Kuhsaft::PublishState::UNPUBLISHED
    if published == Kuhsaft::PublishState::PUBLISHED_AT
      return false if published_at.blank?
      published_at < DateTime.now
    else
      false
    end
  end

  def locale<commit_msg>dont validate slug<commit_after>class Kuhsaft::LocalizedPage < ActiveRecord::Base
  belongs_to :page
  has_many :page_parts, :class_name => 'Kuhsaft::PagePart::Content', :autosave => true

  scope :current_locale, lambda{ where('locale = ?', Kuhsaft::Page.current_translation_locale) }
  
  scope :published, lambda{ 
    where('published = ? OR published_at < ? AND published = ?', 
      Kuhsaft::PublishState::PUBLISHED, 
      DateTime.now, 
      Kuhsaft::PublishState::PUBLISHED_AT
    )
  }
  
  scope :search, lambda{ |term| current_locale.published.where('fulltext LIKE ?', "%#{term}%") }
  scope :navigation, lambda{ |slug| 
    current_locale.published.where('slug = ?', slug).where('page_type = ?', Kuhsaft::PageType::NAVIGATION)
  }

  before_validation :create_slug, :create_url, :collect_fulltext
  delegate :childs, :to => :page

  validates :title, :presence => true
  validates :locale, :presence => true
  validates :slug, :presence => true
  validates :url, :uniqueness => true, :unless => :navigation?

  accepts_nested_attributes_for :page_parts, :allow_destroy => true

  def published?
    return true if published == Kuhsaft::PublishState::PUBLISHED
    return false if published == Kuhsaft::PublishState::UNPUBLISHED
    if published == Kuhsaft::PublishState::PUBLISHED_AT
      return false if published_at.blank?
      published_at < DateTime.now
    else
      false
    end
  end

  def locale
{'fraction_non_alphanumeric': 0.1260824385174922, 'fraction_numerical': 0.0, 'mean_word_length': 4.480075901328274, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7540277', 'n_tokens_mistral': 958, 'n_tokens_neox': 925, 'n_words': 201}