<commit_before># encoding: UTF-8
class Candidate < ActiveRecord::Base
  # Associations
  belongs_to :election
  belongs_to :profile
  belongs_to :post

  # Validations
  validates :profile_id, uniqueness: {
    scope: [:post_id, :election_id], message: I18n.t('candidates.similar_candidate')
  }, on: :create
  validates :name, :lastname, :stil_id, :email,
    :phone, :post, :profile, :election, presence: true

  validate :check_edit
  after_create :send_email
  after_update :send_email

  def send_email
    ElectionMailer.candidate_email(self).deliver_now
  end

  def prepare(user)
    if (user.present?) && (user.profile.present?)
      self.profile = user.profile
      self.name = user.profile.name
      self.lastname = user.profile.lastname
      self.email = user.profile.email
      self.phone = user.profile.phone
      self.stil_id = user.profile.stil_id
    end
  end

  def editable?
    v = election.try(:view_status)
    if v == :during
      return true
    elsif ['Studierådet','Styrelsen'].include?(post.elected_by) && v == :after
      return true
    else
      return false
    end
  end

  def check_edit
    if !editable?
      errors.add(:election, I18n.t('candidate.time_error'))
      return false
    end
    true
  end

  def p_url
    Rails.application.routes.url_helpers.candidate_url(id, host: PUBLIC_URL)
  end

  def p_path
    Rails.application.routes.url_helpers.candidate_path(id)
  end

  def owner?(user)
    user.present? && user.profile == profile
  end
end<commit_msg>Hound fixes<commit_after># encoding: UTF-8
class Candidate < ActiveRecord::Base
  # Associations
  belongs_to :election
  belongs_to :profile
  belongs_to :post

  # Validations
  validates :profile_id, uniqueness: {
    scope: [:post_id, :election_id], message: I18n.t('candidates.similar_candidate')
  }, on: :create
  validates :name, :lastname, :stil_id, :email,
            :phone, :post, :profile, :election, presence: true

  validate :check_edit
  after_create :send_email
  after_update :send_email

  def send_email
    ElectionMailer.candidate_email(self).deliver_now
  end

  def prepare(user)
    if (user.present?) && (user.profile.present?)
      self.profile = user.profile
      self.name = user.profile.name
      self.lastname = user.profile.lastname
      self.email = user.profile.email
      self.phone = user.profile.phone
      self.stil_id = user.profile.stil_id
    end
  end

  def editable?
    v = election.try(:view_status)
    if v == :during
      return true
    elsif ['Studierådet', 'Styrelsen'].include?(post.elected_by) && v == :after
      return true
    else
      return false
    end
  end

  def check_edit
    if !editable?
      errors.add(:election, I18n.t('candidate.time_error'))
      return false
    end
    true
  end

  def p_url
    Rails.application.routes.url_helpers.candidate_url(id, host: PUBLIC_URL)
  end

  def p_path
    Rails.application.routes.url_helpers.candidate_path(id)
  end

  def owner?(user)
    user.present? && user.profile == profile
  end
end
{'fraction_non_alphanumeric': 0.10484668644906034, 'fraction_numerical': 0.003297065611605671, 'mean_word_length': 3.1618655692729765, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1322452', 'n_tokens_mistral': 1047, 'n_tokens_neox': 1025, 'n_words': 225}