<commit_before>require 'friendly_id'
require 'sanitize'

module Coursewareable
  # [Classroom] lecture
  class Lecture < ActiveRecord::Base
    extend FriendlyId
    include PublicActivity::Model

    attr_accessible :content, :requisite, :title, :parent_lecture_id, :position

    # Relationships
    belongs_to :parent_lecture, :class_name => Lecture
    belongs_to :user
    belongs_to :classroom
    has_many :images, :as => :assetable, :class_name => Image
    has_many :uploads, :as => :assetable, :class_name => Upload
    has_many :assignments, :dependent => :destroy
    has_many :responses, :through => :assignments
    has_many :grades, :through => :assignments
    has_many(:child_lectures, :class_name => Lecture,
             :foreign_key => :parent_lecture_id)

    # Validations
    validates_presence_of :title, :slug, :content

    # Generate title slug
    friendly_id :title, :use => :slugged

    # Track activities
    tracked(:owner => :user, :recipient => :classroom, :params => {
      :user_name => proc {|c, m| m.user.name}
    }, :only => [:create])

    # Callbacks
    # Cleanup title and description before saving it
    before_validation do
      self.title = Sanitize.clean(self.title)
      self.content = Sanitize.clean(self.content, Sanitize::Config::RELAXED)
      self.requisite = Sanitize.clean(
        self.requisite, Sanitize::Config::RESTRICTED)
    end
  end
end
<commit_msg>Child lecture lectures should also be ordered. @wip<commit_after>require 'friendly_id'
require 'sanitize'

module Coursewareable
  # [Classroom] lecture
  class Lecture < ActiveRecord::Base
    extend FriendlyId
    include PublicActivity::Model

    attr_accessible :content, :requisite, :title, :parent_lecture_id, :position

    # Relationships
    belongs_to :parent_lecture, :class_name => Lecture
    belongs_to :user
    belongs_to :classroom
    has_many :images, :as => :assetable, :class_name => Image
    has_many :uploads, :as => :assetable, :class_name => Upload
    has_many :assignments, :dependent => :destroy
    has_many :responses, :through => :assignments
    has_many :grades, :through => :assignments
    has_many(:child_lectures, :class_name => Lecture,
             :foreign_key => :parent_lecture_id, :order => 'position DESC')

    # Validations
    validates_presence_of :title, :slug, :content

    # Generate title slug
    friendly_id :title, :use => :slugged

    # Track activities
    tracked(:owner => :user, :recipient => :classroom, :params => {
      :user_name => proc {|c, m| m.user.name}
    }, :only => [:create])

    # Callbacks
    # Cleanup title and description before saving it
    before_validation do
      self.title = Sanitize.clean(self.title)
      self.content = Sanitize.clean(self.content, Sanitize::Config::RELAXED)
      self.requisite = Sanitize.clean(
        self.requisite, Sanitize::Config::RESTRICTED)
    end
  end
end

{'fraction_non_alphanumeric': 0.11298656562177058, 'fraction_numerical': 0.0, 'mean_word_length': 3.7219512195121953, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, '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': '5508312', 'n_tokens_mistral': 934, 'n_tokens_neox': 910, 'n_words': 224}