<commit_before>class SchedulesController < ApplicationController
  load_and_authorize_resource
  
  # GET /schedules
  # GET /schedules.xml
  def index
    show_unpublished = (person_signed_in? and can?(:edit, @context))
    if @context
      if show_unpublished
        @schedules = @context.schedules
      else
        @schedules = @context.schedules.find_all_by_published(true)
      end
      @schedule = Schedule.new :event => @context
    else
      if show_unpublished
        @schedules = Schedule.find(:all)
      else
        @schedules = Schedule.find_all_by_published(true)
      end
      @schedule = Schedule.new
    end
    
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @schedules }
    end
  end

  # GET /schedules/1
  # GET /schedules/1.xml
  def show
    @blocks = @schedule.blocks(:for_registration => true).sort_by { |b| b.start }
    @attendances = if current_person
      current_person.attendances
    else
      []
    end
    
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @schedule }
    end
  end

  # GET /schedules/1/health
  # GET /schedules/1/health.xml
  def health
    @blocks = @schedule.blocks(:for_registration => true).sort_by { |b| b.start }
    
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @schedule }
    end
  end

  # GET /schedules/new
  # GET /schedules/new.xml
  def new
    respond_to do |format|
      format.xml  { render :xml => @schedule }
    end
  end

  # GET /schedules/1/edit
  def edit
  end

  # POST /schedules
  # POST /schedules.xml
  def create
    respond_to do |format|
      if @schedule.save
        flash[:notice] = 'Schedule was successfully created.'
        format.html { redirect_to(@schedule) }
        format.xml  { render :xml => @schedule, :status => :created, :location => @schedule }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @schedule.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /schedules/1
  # PUT /schedules/1.xml
  def update
    if params[:event]
      params[:event].each_pair do |event_id, args|
        event = Event.find(event_id)
        event.update_attributes(args)
        event.save
      end
    end
    
    if params[:remove_event_from_track]
      params[:remove_event_from_track].each_pair do |track_id, events|
        track = Track.find(track_id)
        events.each do |event_id|
          event = Event.find(event_id)
          track.events.delete(event)
        end
      end
    end
    
    if params[:add_event_to_track]
      params[:add_event_to_track].each_pair do |track_id, event_id|
        if event_id and event_id != ''
          track = Track.find(track_id)
          track.events.push(Event.find(event_id))
        end
      end
    end
    
    if params[:create_event_in_track]
      params[:create_event_in_track].each_pair do |track_id, args|
        if args[:fullname] and args[:fullname] != ''
          track = Track.find(track_id)
          event = track.events.create(args.update({:parent => @schedule.event}))
          event.set_default_registration_policy
        end
      end
    end<commit_msg>If they're only removing one event don't break<commit_after>class SchedulesController < ApplicationController
  load_and_authorize_resource
  
  # GET /schedules
  # GET /schedules.xml
  def index
    show_unpublished = (person_signed_in? and can?(:edit, @context))
    if @context
      if show_unpublished
        @schedules = @context.schedules
      else
        @schedules = @context.schedules.find_all_by_published(true)
      end
      @schedule = Schedule.new :event => @context
    else
      if show_unpublished
        @schedules = Schedule.find(:all)
      else
        @schedules = Schedule.find_all_by_published(true)
      end
      @schedule = Schedule.new
    end
    
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @schedules }
    end
  end

  # GET /schedules/1
  # GET /schedules/1.xml
  def show
    @blocks = @schedule.blocks(:for_registration => true).sort_by { |b| b.start }
    @attendances = if current_person
      current_person.attendances
    else
      []
    end
    
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @schedule }
    end
  end

  # GET /schedules/1/health
  # GET /schedules/1/health.xml
  def health
    @blocks = @schedule.blocks(:for_registration => true).sort_by { |b| b.start }
    
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @schedule }
    end
  end

  # GET /schedules/new
  # GET /schedules/new.xml
  def new
    respond_to do |format|
      format.xml  { render :xml => @schedule }
    end
  end

  # GET /schedules/1/edit
  def edit
  end

  # POST /schedules
  # POST /schedules.xml
  def create
    respond_to do |format|
      if @schedule.save
        flash[:notice] = 'Schedule was successfully created.'
        format.html { redirect_to(@schedule) }
        format.xml  { render :xml => @schedule, :status => :created, :location => @schedule }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @schedule.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /schedules/1
  # PUT /schedules/1.xml
  def update
    if params[:event]
      params[:event].each_pair do |event_id, args|
        event = Event.find(event_id)
        event.update_attributes(args)
        event.save
      end
    end
    
    if params[:remove_event_from_track]
      params[:remove_event_from_track].each_pair do |track_id, events|
        track = Track.find(track_id)
        events = [events] unless events.respond_to?(:each)
        events.each do |event_id|
          event = Event.find(event_id)
          track.events.delete(event)
        end
      end
    end
    
    if params[:add_event_to_track]
      params[:add_event_to_track].each_pair do |track_id, event_id|
        if event_id and event_id != ''
          track = Track.find(track_id)
          track.events.push(Event.find(event_id))
        end
      end
    end
    
    if params[:create_event_in_track]
      params[:create_event_in_track].each_pair do |track_id, args|
        if args[:fullname] and args[:fullname] != ''
          track = Track.find(track_id)
          event = track.events.create(args.update({:parent => @schedule.event}))
          event.set_default_registration_policy
        end
      end
    end
{'fraction_non_alphanumeric': 0.10329205678042887, 'fraction_numerical': 0.0021141649048625794, 'mean_word_length': 2.314814814814815, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 36}, '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': '2219330', 'n_tokens_mistral': 2131, 'n_tokens_neox': 2104, 'n_words': 474}